diff --git a/Plugins/Mineplex.ClansQueue.Common/pom.xml b/Plugins/Mineplex.ClansQueue.Common/pom.xml index d468c56ca..10f7c455c 100644 --- a/Plugins/Mineplex.ClansQueue.Common/pom.xml +++ b/Plugins/Mineplex.ClansQueue.Common/pom.xml @@ -7,7 +7,7 @@ com.mineplex mineplex-parent dev-SNAPSHOT - ../plugin.xml + ../pom.xml ClansQueue-Common diff --git a/Plugins/Mineplex.ClansQueue.Common/src/com/mineplex/clansqueue/common/SortableLinkedList.java b/Plugins/Mineplex.ClansQueue.Common/src/com/mineplex/clansqueue/common/SortableLinkedList.java index 1cffc506a..63d4d1579 100644 --- a/Plugins/Mineplex.ClansQueue.Common/src/com/mineplex/clansqueue/common/SortableLinkedList.java +++ b/Plugins/Mineplex.ClansQueue.Common/src/com/mineplex/clansqueue/common/SortableLinkedList.java @@ -1,5 +1,6 @@ package com.mineplex.clansqueue.common; +import java.util.Comparator; import java.util.LinkedList; public class SortableLinkedList> extends LinkedList @@ -8,6 +9,6 @@ public class SortableLinkedList> extends LinkedList public void sort() { - sort((t1, t2) -> t1.compareTo(t2)); + sort(Comparator.naturalOrder()); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/shape/Shape.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/shape/Shape.java index 0446261db..9eb27bc71 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/shape/Shape.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/shape/Shape.java @@ -8,69 +8,62 @@ import java.util.Set; import org.bukkit.util.Vector; +import mineplex.core.common.util.UtilAlg; + /** - * A simple 3D vector stored shape + * A simple 3D vector stored shape */ public class Shape { - + protected final static double DEFAULT_DENSITY = 1; - + protected HashSet _points = new HashSet<>(); public Shape(){} - + public Shape(Collection points){ this._points.addAll(points); } - + /** * Rotate this shape along the X-axis * @param radians Radians to rotate the shape */ public void rotateOnXAxis(double radians) { - for(Vector v : _points) + for(Vector v : _points) { - double y = v.getY(); - double z = v.getZ(); - v.setY(y * Math.cos(radians) - z * Math.sin(radians)); - v.setZ(y * Math.sin(radians) + z * Math.cos(radians)); + UtilAlg.rotateAroundXAxis(v, radians); } } - + /** * Rotate this shape along the Y-axis * @param radians Radians to rotate the shape */ public void rotateOnYAxis(double radians) { - for(Vector v : _points) + for(Vector v : _points) { - double x = v.getX(); - double z = v.getZ(); - v.setX(x * Math.cos(radians) - z * Math.sin(radians)); - v.setZ(x * Math.sin(radians) + z * Math.cos(radians)); + UtilAlg.rotateAroundYAxis(v, radians); } } - + /** * Rotate this shape along the Z-axis * @param radians Radians to rotate the shape */ public void rotateOnZAxis(double radians) { - for(Vector v : _points) + for(Vector v : _points) { - double x = v.getX(); - double y = v.getY(); - v.setX(x * Math.cos(radians) - y * Math.sin(radians)); - v.setY(x * Math.sin(radians) + y * Math.cos(radians)); - } - + UtilAlg.rotateAroundZAxis(v, radians); + } + } - + /** * Offsets all the points based on the given vector * @param v @@ -79,26 +72,26 @@ public class Shape { for(Vector p : _points) p.add(v); } - + public void addPoint(Vector v) { _points.add(v); } - + public boolean removePoint(Vector v) { return _points.remove(v); } - + public Set getPoints() { return new HashSet<>(_points); } - + /** - * Multiply all the points by m. - * If m > 1 then the shape will become larger. - * If m < 1 then the shape will become smaller. + * Multiply all the points by m. + * If m > 1 then the shape will become larger. + * If m < 1 then the shape will become smaller. * If m = 1 then the shape will stay the same. * If m < 0 then the shape will become inverted. * @param m @@ -107,7 +100,7 @@ public class Shape { for(Vector v : _points) v.multiply(m); } - + public Shape clone() { List list = new ArrayList<>(); for(Vector p : _points) @@ -116,12 +109,12 @@ public class Shape } return new Shape(list); } - + public Vector getMidPoint() { return getMaxAABBCorner().subtract(getMinAABBCorner()).multiply(0.5); } - + public Vector getMaxAABBCorner() { Vector max = null; @@ -138,7 +131,7 @@ public class Shape } return max; } - + public Vector getMinAABBCorner() { Vector min = null; @@ -155,7 +148,7 @@ public class Shape } return min; } - + /** * Get the closest length which will be a factor of the provided length, but not longer then max * E.g. You want to split a length of 9 into even peaces, but the peaces should not be longer than the max 5, then this will @@ -164,12 +157,12 @@ public class Shape * @param max The max distance of the returned length * @return The closest to length to be a factor of the provided length which is <= max */ - + public static double getRoundFactor(double length, double max) { return length/Math.ceil(length/max); } - + /** * Get the closest RoundFactor length applied to a vector, using the vector as the max length. The returned vector is a cloned * parallel vector to the provided length @@ -177,13 +170,13 @@ public class Shape * @param maxLength The max length of the new returned vector * @return Returns a parallel vector to the given length vector which is also a factor of the provided vector, but not longer * then maxLength - * + * * @see #getRoundFactor(double, double) */ public static Vector getVectorFactor(Vector length, double maxLength) { return length.clone().multiply(getRoundFactor(length.length(), maxLength)); } - + } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/skin/SkinData.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/skin/SkinData.java index cd7a46158..0b301c04b 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/skin/SkinData.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/skin/SkinData.java @@ -175,14 +175,13 @@ public class SkinData return "_" + _nameCount; } - - /* + /** * Creates a {@link SkinData} from a given {@link GameProfile}. * Will return null if the GameProfile does not have any texture data * * @param input The GameProfile to get textures from * @param requireSecure Whether the SkinData should be signed - * @param useDefaultSkins Whether to subsitute an Alex or Steve skin if no textures are present + * @param useDefaultSkins Whether to substitute an Alex or Steve skin if no textures are present * * @return The SkinData, or null if no textures are present */ diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java index 09d849d91..6ddca054a 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java @@ -1,8 +1,16 @@ package mineplex.core.common.util; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.TreeSet; import net.minecraft.server.v1_8_R3.AxisAlignedBB; + import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R3.TrigMath; @@ -14,6 +22,7 @@ import org.bukkit.util.Vector; public class UtilAlg { + public static TreeSet sortKey(Set toSort) { return sortSet(toSort, null); @@ -21,28 +30,27 @@ public class UtilAlg public static TreeSet sortSet(Collection toSort, Comparator comparator) { - TreeSet sortedSet = new TreeSet(comparator); - for (T cur : toSort) - sortedSet.add(cur); + TreeSet sortedSet = new TreeSet<>(comparator); + sortedSet.addAll(toSort); return sortedSet; } - + public static Location getMidpoint(Location a, Location b) { return a.clone().add(b.clone().subtract(a.clone()).multiply(0.5)); } - + public static Vector getTrajectory(Entity from, Entity to) { return getTrajectory(from.getLocation().toVector(), to.getLocation().toVector()); } - + public static Vector getTrajectory(Location from, Location to) { return getTrajectory(from.toVector(), to.toVector()); } - + public static Vector getTrajectory(Vector from, Vector to) { return to.clone().subtract(from).normalize(); @@ -56,34 +64,34 @@ public class UtilAlg double len = Math.sqrt(dx * dx + dy * dy + dz * dz); - return new double[] { dx / len, dy / len, dz / len}; + return new double[]{dx / len, dy / len, dz / len}; } - + public static Vector getTrajectory2d(Entity from, Entity to) { return getTrajectory2d(from.getLocation().toVector(), to.getLocation().toVector()); } - + public static Vector getTrajectory2d(Location from, Location to) { return getTrajectory2d(from.toVector(), to.toVector()); } - + public static Vector getTrajectory2d(Vector from, Vector to) { return to.clone().subtract(from).setY(0).normalize(); } - public static boolean HasSight(Location from, Player to) + public static boolean HasSight(Location from, Player to) { return HasSight(from, to.getLocation()) || HasSight(from, to.getEyeLocation()); } - public static boolean HasSight(Location from, Location to) + public static boolean HasSight(Location from, Location to) { //Clone Location - Location cur = new Location(from.getWorld(), from.getX(), from.getY(), from.getZ()); - + Location cur = new Location(from.getWorld(), from.getX(), from.getY(), from.getZ()); + double rate = 0.1; Vector vec = getTrajectory(from, to).multiply(0.1); @@ -97,7 +105,7 @@ public class UtilAlg return true; } - + public static float GetPitch(Vector vec) { return GetPitch(vec.getX(), vec.getY(), vec.getZ()); @@ -110,11 +118,11 @@ public class UtilAlg public static float GetPitch(double x, double y, double z) { - double xz = Math.sqrt((x*x) + (z*z)); + double xz = Math.sqrt((x * x) + (z * z)); - double pitch = Math.toDegrees(TrigMath.atan(xz/y)); - if (y <= 0) pitch += 90; - else pitch -= 90; + double pitch = Math.toDegrees(TrigMath.atan(xz / y)); + if (y <= 0) pitch += 90; + else pitch -= 90; //Fix for two vectors at same Y giving 180 if (pitch == 180) @@ -122,7 +130,7 @@ public class UtilAlg return (float) pitch; } - + public static float GetYaw(Vector vec) { return GetYaw(vec.getX(), vec.getY(), vec.getZ()); @@ -135,40 +143,35 @@ public class UtilAlg public static float GetYaw(double x, double y, double z) { - double yaw = Math.toDegrees(TrigMath.atan((-x)/z)); - if (z < 0) yaw += 180; - + double yaw = Math.toDegrees(TrigMath.atan((-x) / z)); + if (z < 0) yaw += 180; + return (float) yaw; } - + public static Vector Normalize(Vector vec) { if (vec.length() > 0) vec.normalize(); - + return vec; } - - public static Vector Clone(Vector vec) - { - return new Vector(vec.getX(), vec.getY(), vec.getZ()); - } - public static T Random(Set set) + public static T Random(Set set) { List list = new ArrayList(); - + list.addAll(set); - + return Random(list); } - - - public static T Random(List list) + + + public static T Random(List list) { if (list.isEmpty()) return null; - + return list.get(UtilMath.r(list.size())); } @@ -215,69 +218,69 @@ public class UtilAlg return list; } - public static boolean inBoundingBox(Location loc, Location cornerA, Location cornerB) + public static boolean inBoundingBox(Location loc, Location cornerA, Location cornerB) { - if (loc.getX() <= Math.min(cornerA.getX(), cornerB.getX())) return false; - if (loc.getX() >= Math.max(cornerA.getX(), cornerB.getX())) return false; - + if (loc.getX() <= Math.min(cornerA.getX(), cornerB.getX())) return false; + if (loc.getX() >= Math.max(cornerA.getX(), cornerB.getX())) return false; + if (cornerA.getY() != cornerB.getY()) { - if (loc.getY() <= Math.min(cornerA.getY(), cornerB.getY())) return false; - if (loc.getY() >= Math.max(cornerA.getY(), cornerB.getY())) return false; + if (loc.getY() <= Math.min(cornerA.getY(), cornerB.getY())) return false; + if (loc.getY() >= Math.max(cornerA.getY(), cornerB.getY())) return false; } - - if (loc.getZ() <= Math.min(cornerA.getZ(), cornerB.getZ())) return false; - if (loc.getZ() >= Math.max(cornerA.getZ(), cornerB.getZ())) return false; - + + if (loc.getZ() <= Math.min(cornerA.getZ(), cornerB.getZ())) return false; + if (loc.getZ() >= Math.max(cornerA.getZ(), cornerB.getZ())) return false; + return true; } public static boolean inBoundingBox(Location loc, Vector cornerA, Vector cornerB) { - if (loc.getX() <= Math.min(cornerA.getX(), cornerB.getX())) return false; - if (loc.getX() >= Math.max(cornerA.getX(), cornerB.getX())) return false; - + if (loc.getX() <= Math.min(cornerA.getX(), cornerB.getX())) return false; + if (loc.getX() >= Math.max(cornerA.getX(), cornerB.getX())) return false; + if (cornerA.getY() != cornerB.getY()) { - if (loc.getY() <= Math.min(cornerA.getY(), cornerB.getY())) return false; - if (loc.getY() >= Math.max(cornerA.getY(), cornerB.getY())) return false; + if (loc.getY() <= Math.min(cornerA.getY(), cornerB.getY())) return false; + if (loc.getY() >= Math.max(cornerA.getY(), cornerB.getY())) return false; } - - if (loc.getZ() <= Math.min(cornerA.getZ(), cornerB.getZ())) return false; - if (loc.getZ() >= Math.max(cornerA.getZ(), cornerB.getZ())) return false; - + + if (loc.getZ() <= Math.min(cornerA.getZ(), cornerB.getZ())) return false; + if (loc.getZ() >= Math.max(cornerA.getZ(), cornerB.getZ())) return false; + return true; } - + public static Vector cross(Vector a, Vector b) { - double x = a.getY()*b.getZ() - a.getZ()*b.getY(); - double y = a.getZ()*b.getX() - a.getX()*b.getZ(); - double z = a.getX()*b.getY() - a.getY()*b.getX(); - - return new Vector(x,y,z).normalize(); + double x = a.getY() * b.getZ() - a.getZ() * b.getY(); + double y = a.getZ() * b.getX() - a.getX() * b.getZ(); + double z = a.getX() * b.getY() - a.getY() * b.getX(); + + return new Vector(x, y, z).normalize(); } - + public static Vector getRight(Vector vec) { - return cross(vec.clone().normalize(), new Vector(0,1,0)); + return cross(vec.clone().normalize(), new Vector(0, 1, 0)); } - + public static Vector getLeft(Vector vec) { return getRight(vec).multiply(-1); } - + public static Vector getBehind(Vector vec) { return vec.clone().multiply(-1); } - + public static Vector getUp(Vector vec) { return getDown(vec).multiply(-1); } - + public static Vector getDown(Vector vec) { return cross(vec, getRight(vec)); @@ -287,37 +290,37 @@ public class UtilAlg { if (locs.isEmpty()) return null; - - Vector vec = new Vector(0,0,0); + + Vector vec = new Vector(0, 0, 0); double amount = 0; - + for (Location loc : locs) { vec.add(loc.toVector()); amount++; } - - vec.multiply(1d/amount); - + + vec.multiply(1d / amount); + return vec.toLocation(locs.get(0).getWorld()); } - + public static Location getAverageBlockLocation(List locs) { if (locs.isEmpty()) return null; - - Vector vec = new Vector(0,0,0); + + Vector vec = new Vector(0, 0, 0); double amount = 0; - + for (Block loc : locs) { vec.add(loc.getLocation().toVector()); amount++; } - - vec.multiply(1d/amount); - + + vec.multiply(1d / amount); + return vec.toLocation(locs.get(0).getWorld()); } @@ -325,217 +328,217 @@ public class UtilAlg { if (locs.isEmpty()) return null; - - Vector vec = new Vector(0,0,0); + + Vector vec = new Vector(0, 0, 0); double amount = 0; - + for (Location loc : locs) { vec.add(UtilAlg.getTrajectory(loc, source)); amount++; } - - vec.multiply(1d/amount); - + + vec.multiply(1d / amount); + return vec; } - + public static Entity findClosest(Entity mid, ArrayList locs) { Entity bestLoc = null; double bestDist = 0; - + for (Entity loc : locs) { double dist = UtilMath.offset(mid, loc); - + if (bestLoc == null || dist < bestDist) { bestLoc = loc; bestDist = dist; } } - + return bestLoc; } - public static Location findClosest(Location mid, ArrayList locs) + public static Location findClosest(Location mid, List locs) { Location bestLoc = null; double bestDist = 0; - + for (Location loc : locs) { double dist = UtilMath.offset(mid, loc); - + if (bestLoc == null || dist < bestDist) { bestLoc = loc; bestDist = dist; } } - + return bestLoc; } - - public static Location findFurthest(Location mid, ArrayList locs) + + public static Location findFurthest(Location mid, List locs) { Location bestLoc = null; double bestDist = 0; - + for (Location loc : locs) { double dist = UtilMath.offset(mid, loc); - + if (bestLoc == null || dist > bestDist) { bestLoc = loc; bestDist = dist; } } - + return bestLoc; } - + public static boolean isInPyramid(Vector a, Vector b, double angleLimit) { return (Math.abs(GetPitch(a) - GetPitch(b)) < angleLimit) && (Math.abs(GetYaw(a) - GetYaw(b)) < angleLimit); } - - public static boolean isTargetInPlayerPyramid(Player player, Player target, double angleLimit) + + public static boolean isTargetInPlayerPyramid(Player player, Player target, double angleLimit) { return isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getEyeLocation()), angleLimit) || isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getLocation()), angleLimit); } - public static Location getLocationAwayFromPlayers(ArrayList locs, ArrayList players) + public static Location getLocationAwayFromPlayers(ArrayList locs, ArrayList players) { Location bestLoc = null; double bestDist = 0; - + for (Location loc : locs) { double closest = -1; - + for (Player player : players) { //Different Worlds if (!player.getWorld().equals(loc.getWorld())) continue; - + double dist = UtilMath.offsetSquared(player.getLocation(), loc); - + if (closest == -1 || dist < closest) { closest = dist; } } - + if (closest == -1) continue; - + if (bestLoc == null || closest > bestDist) { bestLoc = loc; bestDist = closest; } } - + return bestLoc; } - - public static Location getLocationAwayFromOtherLocations(ArrayList locs, ArrayList players) + + public static Location getLocationAwayFromOtherLocations(ArrayList locs, ArrayList players) { Location bestLoc = null; double bestDist = 0; - + for (Location loc : locs) { double closest = -1; - + for (Location player : players) { //Different Worlds if (!player.getWorld().equals(loc.getWorld())) continue; - + double dist = UtilMath.offsetSquared(player, loc); - + if (closest == -1 || dist < closest) { closest = dist; } } - + if (closest == -1) continue; - + if (bestLoc == null || closest > bestDist) { bestLoc = loc; bestDist = closest; } } - + return bestLoc; } - - public static Location getLocationNearPlayers(ArrayList locs, ArrayList players, ArrayList dontOverlap) + + public static Location getLocationNearPlayers(ArrayList locs, ArrayList players, ArrayList dontOverlap) { Location bestLoc = null; double bestDist = 0; - + for (Location loc : locs) { double closest = -1; - + boolean valid = true; - + //Dont spawn on other players for (Player player : dontOverlap) { if (!player.getWorld().equals(loc.getWorld())) continue; - + double dist = UtilMath.offsetSquared(player.getLocation(), loc); - + if (dist < 0.8) { valid = false; break; } } - + if (!valid) continue; - + //Find closest player for (Player player : players) { if (!player.getWorld().equals(loc.getWorld())) continue; - + double dist = UtilMath.offsetSquared(player.getLocation(), loc); - + if (closest == -1 || dist < closest) { closest = dist; } } - + if (closest == -1) continue; - + if (bestLoc == null || closest < bestDist) { bestLoc = loc; bestDist = closest; } } - + return bestLoc; } - + public static Vector calculateVelocity(Vector from, Vector to, double heightGain, Entity entity) { if (entity instanceof LivingEntity) @@ -584,47 +587,47 @@ public class UtilAlg double vz = vh * dirz; return new Vector(vx, vy, vz); } - + public static Location getNearestCornerLocation(Location near, Block block) { ArrayList corners = new ArrayList(); - + corners.add(block.getLocation().clone()); corners.add(block.getLocation().clone().add(.999, 0, 0)); corners.add(block.getLocation().clone().add(.999, 0, .999)); corners.add(block.getLocation().clone().add(0, 0, .999)); - + corners.add(block.getLocation().clone().add(0, .999, 0)); corners.add(block.getLocation().clone().add(.999, .999, 0)); corners.add(block.getLocation().clone().add(.999, .999, .999)); corners.add(block.getLocation().clone().add(0, .999, .999)); - + return UtilAlg.findClosest(near, corners); } - + public static boolean isSimilar(Location a, Location b) { return a.getWorld() == b.getWorld() && a.getX() == b.getX() && a.getY() == b.getY() && a.getZ() == b.getZ(); } - public static int randomMidpoint(int min, int max) + public static int randomMidpoint(int min, int max) { int variance = max - min; - + int value = UtilMath.r(variance); - + value += min; - + return value; } - + public static EulerAngle vectorToEuler(Vector vector) { //JUST MAKE SURE THE ARMOR STAND ISNT ROTATED. - + return new EulerAngle( - Math.toRadians(UtilAlg.GetPitch(vector)), + Math.toRadians(UtilAlg.GetPitch(vector)), Math.toRadians(UtilAlg.GetYaw(vector)), 0); } @@ -638,12 +641,12 @@ public class UtilAlg { double x = location.getX(); double z = location.getZ(); - + double rad = Math.toRadians(yaw); - + x = reverse ? (x + strength * Math.sin(rad)) : (x - strength * Math.sin(rad)); z = reverse ? (z - strength * Math.cos(rad)) : (z + strength * Math.cos(rad)); - + return new Location(location.getWorld(), x, location.getY(), z, location.getYaw(), location.getPitch()); } @@ -658,7 +661,8 @@ public class UtilAlg /** * Gets a random location, with specific radius - * @param center The center location + * + * @param center The center location * @param radiusX The X radius * @param radiusY The Y radius * @param radiusZ The Z radius @@ -670,12 +674,40 @@ public class UtilAlg double x = minX + (UtilMath.random.nextDouble() * 2 * radiusX); double y = minY + (UtilMath.random.nextDouble() * 2 * radiusY); double z = minZ + (UtilMath.random.nextDouble() * 2 * radiusZ); - Location newLocation = center.clone().add((radiusX == 0) ? 0 : x, (radiusY == 0) ? 0 : y, (radiusZ == 0) ? 0 : z); - return newLocation; + return center.clone().add((radiusX == 0) ? 0 : x, (radiusY == 0) ? 0 : y, (radiusZ == 0) ? 0 : z); } public static Location getRandomLocation(Location center, double radius) { return getRandomLocation(center, radius, radius, radius); } + + public static Vector rotateAroundXAxis(Vector vec, double angle) + { + double y = vec.getY(), z = vec.getZ(), sin = Math.sin(angle), cos = Math.cos(angle); + return vec.setY(y * cos - z * sin).setZ(y * sin + z * cos); + } + + public static Vector rotateAroundYAxis(Vector vec, double angle) + { + double x = vec.getX(), z = vec.getZ(), sin = Math.sin(angle), cos = Math.cos(angle); + return vec.setX(x * cos - z * sin).setZ(x * sin + z * cos); + } + + public static Vector rotateAroundZAxis(Vector vec, double angle) + { + double x = vec.getX(), y = vec.getY(), sin = Math.sin(angle), cos = Math.cos(angle); + return vec.setX(x * cos - y * sin).setZ(x * sin + y * cos); + } + + /** + * Adjusts the yaw of a location to face the nearest location in the lookAt collection. + * + * @param location The location to adjust the yaw of + * @param lookAt The list of locations to look at + */ + public static void lookAtNearest(Location location, List lookAt) + { + location.setYaw(GetYaw(getTrajectory(location, findClosest(location, lookAt)))); + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index 15f1be807..341de3aa3 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -2,6 +2,7 @@ package mineplex.core.common.util; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -98,7 +99,7 @@ public class UtilBlock /** * All horizontal diections [north, east, south, west] */ - public static HashSet horizontals = new HashSet<>(); + public static List horizontals = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST); private static MultiBlockUpdaterAgent _quickChangeRecorder; @@ -325,11 +326,6 @@ public class UtilBlock blockUseSet.add((byte) Material.JUNGLE_DOOR.getId()); blockUseSet.add((byte) Material.ACACIA_DOOR.getId()); blockUseSet.add((byte) Material.DARK_OAK_DOOR.getId()); - - horizontals.add(BlockFace.NORTH); - horizontals.add(BlockFace.EAST); - horizontals.add(BlockFace.SOUTH); - horizontals.add(BlockFace.WEST); } public static boolean solid(Block block) @@ -1740,5 +1736,10 @@ public class UtilBlock return blocks; } + + public static BlockFace getFace(float yaw) + { + return horizontals.get(Math.round(yaw / 90F) & 0x3); + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java index 3dabf341d..0cee7ef36 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java @@ -43,8 +43,6 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Giant; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.inventory.EntityEquipment; -import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; @@ -54,8 +52,8 @@ public class UtilEnt public static final String FLAG_ENTITY_COMPONENT = "component"; //Custom Entity Names - private static HashMap _nameMap = new HashMap(); - private static HashMap creatureMap = new HashMap(); + private static HashMap _nameMap = new HashMap<>(); + private static HashMap creatureMap = new HashMap<>(); private static Field _goalSelector; private static Field _targetSelector; @@ -293,19 +291,7 @@ public class UtilEnt creature.setVegetated(true); } } - catch (IllegalArgumentException e) - { - e.printStackTrace(); - } - catch (IllegalAccessException e) - { - e.printStackTrace(); - } - catch (NoSuchFieldException e) - { - e.printStackTrace(); - } - catch (SecurityException e) + catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { e.printStackTrace(); } @@ -574,7 +560,7 @@ public class UtilEnt public static HashMap getInRadius(Location loc, double dR) { - HashMap ents = new HashMap(); + HashMap ents = new HashMap<>(); for (Entity cur : loc.getWorld().getEntities()) { @@ -588,7 +574,7 @@ public class UtilEnt if (offset < dR) { - ents.put(ent, Double.valueOf(1 - (offset/dR))); + ents.put(ent, 1 - (offset / dR)); continue; } @@ -597,8 +583,7 @@ public class UtilEnt if (offset < dR) { - ents.put(ent, Double.valueOf(1 - (offset/dR))); - continue; + ents.put(ent, 1 - (offset / dR)); } } @@ -619,8 +604,7 @@ public class UtilEnt if (offset < dR) { - ents.put(cur, Double.valueOf(1 - (offset/dR))); - continue; + ents.put(cur, 1 - (offset / dR)); } } @@ -633,10 +617,7 @@ public class UtilEnt { if (disguise == EntityType.SQUID) { - if (UtilMath.offset(loc, ent.getLocation().add(0, 0.4, 0)) < 0.6 * mult) - return true; - - return false; + return UtilMath.offset(loc, ent.getLocation().add(0, 0.4, 0)) < 0.6 * mult; } } @@ -852,7 +833,7 @@ public class UtilEnt ec.fakePitch = pitch; ec.fakeYaw = yaw; - EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ec.getWorld()).tracker.trackedEntities.get(ec.getId()); + EntityTrackerEntry entry = ((WorldServer) ec.getWorld()).tracker.trackedEntities.get(ec.getId()); if (entry != null) { @@ -1000,11 +981,6 @@ public class UtilEnt return .51 * ((double) size); } - public static boolean inWater(LivingEntity ent) - { - return ent.getLocation().getBlock().getTypeId() == 8 || ent.getLocation().getBlock().getTypeId() == 9; - } - public static void setBoundingBox(Entity ent, double width, double height) { ((CraftEntity)ent).getHandle().setSize((float) width, (float)height); @@ -1042,12 +1018,6 @@ public class UtilEnt entity.removeMetadata(key, UtilServer.getPlugin()); } - public static void SetItemInHand(LivingEntity entity, ItemStack item) - { - EntityEquipment equipment = entity.getEquipment(); - equipment.setItemInHand(item); - } - public static byte getEntityEggData(EntityType type) { switch (type) @@ -1084,4 +1054,9 @@ public class UtilEnt } } + public static boolean isInWater(Entity entity) + { + return ((CraftEntity) entity).getHandle().inWater; + } + } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index a3f11841f..6dac16355 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -513,7 +513,11 @@ public class UtilPlayer public static Player getClosest(Location loc, double maxDist, Collection ignore) { - maxDist *= maxDist; + if (maxDist > 0) + { + maxDist *= maxDist; + } + Player best = null; double bestDist = 0; @@ -552,7 +556,10 @@ public class UtilPlayer public static Player getClosest(Location loc, double maxDist, Entity... ignore) { - maxDist *= maxDist; + if (maxDist > 0) + { + maxDist *= maxDist; + } Player best = null; double bestDist = 0; @@ -719,10 +726,7 @@ public class UtilPlayer public static void clearInventory(Player player) { player.getInventory().clear(); - player.getInventory().setHelmet(null); - player.getInventory().setChestplate(null); - player.getInventory().setLeggings(null); - player.getInventory().setBoots(null); + player.getInventory().setArmorContents(null); } public static void clearPotionEffects(Player player) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/weight/WeightSet.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/weight/WeightSet.java index 9744e51b3..267d79508 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/weight/WeightSet.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/weight/WeightSet.java @@ -5,13 +5,15 @@ import java.util.Collections; import java.util.HashSet; import java.util.Random; import java.util.Set; +import java.util.function.Predicate; import java.util.stream.Collectors; public class WeightSet { - private static Random random = new Random(); + + private static Random RANDOM = new Random(); - private Set> _weights = new HashSet<>(); + private final Set> _weights = new HashSet<>(); private volatile transient Set _keyset; @@ -23,10 +25,7 @@ public class WeightSet @SafeVarargs public WeightSet(Weight... weights) { - for (Weight weight : weights) - { - _weights.add(weight); - } + Collections.addAll(_weights, weights); computeKeyset(); } @@ -35,7 +34,7 @@ public class WeightSet { for (T element : elements) { - _weights.add(new Weight(1, element)); // Constant weight of 1 means all elements are equally likely + _weights.add(new Weight<>(1, element)); // Constant weight of 1 means all elements are equally likely } computeKeyset(); } @@ -44,11 +43,17 @@ public class WeightSet { for (T element : elements) { - _weights.add(new Weight(1, element)); // Constant weight of 1 means all elements are equally likely + _weights.add(new Weight<>(1, element)); // Constant weight of 1 means all elements are equally likely } computeKeyset(); } + public WeightSet(WeightSet weightSet) + { + _weights.addAll(weightSet._weights); + computeKeyset(); + } + public Weight add(int weight, T element) { Weight w = new Weight<>(weight, element); @@ -58,9 +63,18 @@ public class WeightSet return w; } - public void remove(Weight weight) + public boolean remove(Weight weight) { - _weights.remove(weight); + boolean remove = _weights.remove(weight); + computeKeyset(); + return remove; + } + + public boolean removeIf(Predicate> filter) + { + boolean remove = _weights.removeIf(filter); + computeKeyset(); + return remove; } private int getTotalWeight() @@ -78,7 +92,7 @@ public class WeightSet public T generateRandom() { int totalWeight = getTotalWeight(); - int roll = random.nextInt(totalWeight); + int roll = RANDOM.nextInt(totalWeight); for (Weight weight : _weights) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/MiniDbClientPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/MiniDbClientPlugin.java index 52805cdc5..da7020024 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/MiniDbClientPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/MiniDbClientPlugin.java @@ -8,11 +8,18 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.account.ILoginProcessor; +import mineplex.core.common.util.UtilServer; public abstract class MiniDbClientPlugin extends MiniClientPlugin implements ILoginProcessor { + protected CoreClientManager ClientManager = null; - + + public MiniDbClientPlugin(String moduleName) + { + this(moduleName, UtilServer.getPlugin(), Managers.require(CoreClientManager.class)); + } + public MiniDbClientPlugin(String moduleName, JavaPlugin plugin, CoreClientManager clientManager) { super(moduleName, plugin); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java index eb76c8be4..50f3b6a11 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import mineplex.core.achievement.leveling.LevelingManager; import mineplex.core.common.util.C; public enum Achievement @@ -71,6 +72,16 @@ public enum Achievement new int[]{300}, AchievementCategory.HOLIDAY), + GLOBAL_PUMPKIN_SMASHER_2017("2017 Pumpkin Smasher", 0, + new String[]{"Global.Halloween Pumpkins 2017"}, + new String[]{"Smash 200 Flaming Pumpkins,", + "during Halloween 2017!"}, + new int[][]{ new int[]{0,0,8000}}, + new int[]{2000}, + "", + new String[0], + AchievementCategory.HOLIDAY), + //Bridges BRIDGES_WINS("Bridge Champion", 600, new String[]{"The Bridges.Wins"}, @@ -1404,7 +1415,7 @@ public enum Achievement private static int[] getExperienceLevels() { - int[] levels = new int[100]; + int[] levels = new int[LevelingManager.getMaxLevel()]; int expReq = 0; @@ -1443,7 +1454,12 @@ public enum Achievement expReq += 5000; levels[i] = expReq; } - + +// for (int i=100 ; i> _log = new NautHashMap>(); - - private boolean _shopEnabled = true; + private final NautHashMap> _log = new NautHashMap<>(); public AchievementManager(StatsManager statsManager, CoreClientManager clientManager, DonationManager donationManager, IncognitoManager incognitoManager, EloManager eloManager) { @@ -55,10 +53,12 @@ public class AchievementManager extends MiniPlugin _eloManager = eloManager; _clientManager = clientManager; _shop = new AchievementShop(this, _statsManager, clientManager, donationManager, "Achievement"); - + + //new LevelingManager(this); + generatePermissions(); } - + private void generatePermissions() { PermissionGroup.MOD.setPermission(Perm.SEE_FULL_STATS, true, true); @@ -108,7 +108,7 @@ public class AchievementManager extends MiniPlugin if (stat.equalsIgnoreCase(event.getStatName())) { if (!_log.containsKey(player.getName())) - _log.put(player.getName(), new NautHashMap()); + _log.put(player.getName(), new NautHashMap<>()); //Record that achievement has leveled up if (type.getLevelData(event.getValueAfter()).getLevel() > type.getLevelData(event.getValueBefore()).getLevel()) @@ -184,62 +184,56 @@ public class AchievementManager extends MiniPlugin return _log.remove(player.getName()); } - public void setGiveInterfaceItem(boolean giveInterfaceItem) - { - _giveInterfaceItem = giveInterfaceItem; - } - - /*@EventHandler - public void openShop(PlayerInteractEvent event) - { - if (!_shopEnabled) - return; - - if (event.hasItem() && event.getItem().getType() == Material.SKULL_ITEM) - { - event.setCancelled(true); - - openShop(event.getPlayer()); - } - }*/ - public boolean hasCategory(Player player, Achievement[] required) { if (required == null || required.length == 0) + { return false; - + } + for (Achievement cur : required) { if (get(player, cur).getLevel() < cur.getMaxLevel()) + { return false; + } } - + return true; } - + public int getMineplexLevelNumber(Player sender) { + return getMineplexLevelNumber(sender, true); + } + + public int getMineplexLevelNumber(Player sender, boolean fakeLevels) + { + CoreClient client = _clientManager.Get(sender); int level = get(sender, Achievement.GLOBAL_MINEPLEX_LEVEL).getLevel(); - if (_clientManager.Get(sender).hasPermission(Perm.FAKE_LEVEL_50)) + if (client.hasPermission(Perm.FAKE_LEVEL_50)) { level = Math.max(level, 50 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel()); - } else if (_clientManager.Get(sender).hasPermission(Perm.FAKE_LEVEL_30)) + } + else if (client.hasPermission(Perm.FAKE_LEVEL_30)) { level = Math.max(level, 30 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel()); - } else if (_clientManager.Get(sender).hasPermission(Perm.FAKE_LEVEL_15)) + } + else if (client.hasPermission(Perm.FAKE_LEVEL_15)) { level = Math.max(level, 15); - } else if (_clientManager.Get(sender).hasPermission(Perm.FAKE_LEVEL_5)) + } + else if (client.hasPermission(Perm.FAKE_LEVEL_5)) { level = Math.max(level, 5); } - + return level; } public String getMineplexLevel(Player sender) - { + { return Achievement.getExperienceString(getMineplexLevelNumber(sender)) + " " + ChatColor.RESET; } @@ -248,11 +242,6 @@ public class AchievementManager extends MiniPlugin return _clientManager; } - public void setShopEnabled(boolean var) - { - _shopEnabled = var; - } - public IncognitoManager getIncognito() { return _incognitoManager; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/LevelingManager.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/LevelingManager.java new file mode 100644 index 000000000..5b48b10eb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/LevelingManager.java @@ -0,0 +1,248 @@ +package mineplex.core.achievement.leveling; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.AbstractMap.SimpleEntry; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.UUID; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.MiniDbClientPlugin; +import mineplex.core.account.permissions.Permission; +import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.achievement.Achievement; +import mineplex.core.achievement.AchievementManager; +import mineplex.core.achievement.leveling.rewards.LevelChestReward; +import mineplex.core.achievement.leveling.rewards.LevelCurrencyReward; +import mineplex.core.achievement.leveling.rewards.LevelReward; +import mineplex.core.achievement.leveling.ui.LevelRewardShop; +import mineplex.core.command.CommandBase; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.C; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.treasure.types.TreasureType; + +public class LevelingManager extends MiniDbClientPlugin> +{ + + public enum Perm implements Permission + { + + VIEW_LEVEL_MENU + + } + + // That is a big old number + private static final int MAX_LEVEL = 100; + public static int getMaxLevel() + { + return MAX_LEVEL; + } + + private final AchievementManager _achievement; + private final LevelingRepository _repository; + private final LevelRewardShop _shop; + + private final List> _rewards; + + public LevelingManager(AchievementManager achievementManager) + { + super("Level Rewards"); + + _achievement = achievementManager; + _repository = new LevelingRepository(); + _shop = new LevelRewardShop(this, ClientManager, require(DonationManager.class)); + + _rewards = new ArrayList<>(120); + + populateRewards(); + generatePermissions(); + + addCommand(new CommandBase(this, Perm.VIEW_LEVEL_MENU,"level") + { + @Override + public void Execute(Player caller, String[] args) + { + _shop.attemptShopOpen(caller); + } + }); + } + + private void generatePermissions() + { + PermissionGroup.PLAYER.setPermission(Perm.VIEW_LEVEL_MENU, true, true); + } + + private void populateRewards() + { + addCurrencyReward(1, GlobalCurrency.GEM, 100); + addCurrencyReward(2, GlobalCurrency.GEM, 200); + addChestReward(3, TreasureType.OLD, 1); + addCurrencyReward(4, GlobalCurrency.GEM, 250); + addCurrencyReward(5, GlobalCurrency.GEM, 250); + addChestReward(6, TreasureType.OLD, 2); + addCurrencyReward(7, GlobalCurrency.GEM, 250); + addCurrencyReward(8, GlobalCurrency.GEM, 250); + addCurrencyReward(9, GlobalCurrency.GEM, 500); + addChestReward(10, TreasureType.OLD, 2); + } + + private void addCurrencyReward(int level, GlobalCurrency type, int amount) + { + _rewards.add(new SimpleEntry<>(level, new LevelCurrencyReward(type, amount))); + } + + private void addChestReward(int level, TreasureType type, int amount) + { + _rewards.add(new SimpleEntry<>(level, new LevelChestReward(type, amount))); + } + + @Override + public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException + { + List levels = new ArrayList<>(50); + + try + { + while (resultSet.next()) + { + levels.add(resultSet.getInt("level")); + } + } + catch (SQLException e) + { + e.printStackTrace(); + } + + Set(uuid, levels); + } + + @Override + protected List addPlayer(UUID uuid) + { + return new ArrayList<>(); + } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT level FROM accountLevelReward WHERE accountId=" + accountId + ";"; + } + + public int getLevel(Player player) + { + return _achievement.getMineplexLevelNumber(player, false); + } + + public int getFirstUnclaimedLevel(Player player) + { + List claimed = Get(player); + + for (Entry entry : _rewards) + { + int level = entry.getKey(); + + if (!claimed.contains(level)) + { + return level; + } + } + + return -1; + } + + public List getLevelRewards(int level) + { + List rewards = new ArrayList<>(); + + for (Entry entry : _rewards) + { + int rewardLevel = entry.getKey(); + + if (level == rewardLevel) + { + rewards.add(entry.getValue()); + } + } + + return rewards; + } + + public List> getLevelRewards() + { + return _rewards; + } + + public ItemStack getLevelItem(Player player, List rewards, int level) + { + boolean claimed = hasClaimed(player, level); + boolean canClaim = canClaim(player, level); + boolean exclusive = level > 100; + + Material material; + byte data = 0; + String title = "Level " + Achievement.getExperienceString(level); + String bottomLine; + ItemBuilder builder = new ItemBuilder(Material.AIR); + + // Already claimed + if (claimed) + { + material = Material.INK_SACK; + data = 8; + title = C.cRed + title; + bottomLine = C.cRed + "You have already claimed this reward."; + } + // Hasn't claimed and could claim + else if (canClaim) + { + material = exclusive ? Material.DIAMOND_BLOCK : Material.EMERALD_BLOCK; + title = C.cGreen + title; + bottomLine = C.cGreen + "Click to claim this reward!"; + builder.setGlow(true); + } + // Hasn't claimed and can't claim + else + { + material = exclusive ? Material.OBSIDIAN : Material.REDSTONE_BLOCK; + title = C.cRed + title; + bottomLine = C.cRed + "You aren't a high enough level to claim this reward."; + } + + builder.setType(material); + builder.setData(data); + builder.setTitle(title); + builder.addLore(""); + + for (LevelReward reward : rewards) + { + builder.addLore(" " + reward.getDescription()); + } + + builder.addLore("", bottomLine); + + return builder.build(); + } + + public void claim(Player player, int level) + { + Get(player).add(level); + _repository.claimReward(ClientManager.Get(player), level); + } + + public boolean hasClaimed(Player player, int level) + { + return Get(player).contains(level); + } + + public boolean canClaim(Player player, int level) + { + return getLevel(player) >= level; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/LevelingRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/LevelingRepository.java new file mode 100644 index 000000000..0662a195d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/LevelingRepository.java @@ -0,0 +1,27 @@ +package mineplex.core.achievement.leveling; + +import mineplex.core.account.CoreClient; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; + +public class LevelingRepository extends RepositoryBase +{ + + private static final String CLAIM_REWARD = "INSERT INTO accountLevelReward VALUES (?,?);"; + + LevelingRepository() + { + super(DBPool.getAccount()); + } + + public void claimReward(CoreClient client, int level) + { + int accountId = client.getAccountId(); + + executeInsert(CLAIM_REWARD, null, + new ColumnInt("accountId", accountId), + new ColumnInt("level", level) + ); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/rewards/LevelChestReward.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/rewards/LevelChestReward.java new file mode 100644 index 000000000..d43e706cb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/rewards/LevelChestReward.java @@ -0,0 +1,31 @@ +package mineplex.core.achievement.leveling.rewards; + +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.treasure.types.TreasureType; + +public class LevelChestReward implements LevelReward +{ + + private final TreasureType _chest; + private final int _amount; + + public LevelChestReward(TreasureType chest, int amount) + { + _chest = chest; + _amount = amount; + } + + @Override + public void claim(Player player) + { + INVENTORY.addItemToInventory(null, player, _chest.getItemName(), _amount); + } + + @Override + public String getDescription() + { + return C.cWhite + "- " + _amount + " " + _chest.getName(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/rewards/LevelCurrencyReward.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/rewards/LevelCurrencyReward.java new file mode 100644 index 000000000..e4db06375 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/rewards/LevelCurrencyReward.java @@ -0,0 +1,31 @@ +package mineplex.core.achievement.leveling.rewards; + +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import org.bukkit.entity.Player; + +public class LevelCurrencyReward implements LevelReward +{ + + private final GlobalCurrency _type; + private final int _amount; + + public LevelCurrencyReward(GlobalCurrency type, int amount) + { + _type = type; + _amount = amount; + } + + @Override + public void claim(Player player) + { + DONATION.rewardCurrencyUntilSuccess(_type, player, "Level Reward", _amount); + } + + @Override + public String getDescription() + { + return C.cWhite + "- " + F.currency(_type, _amount); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/rewards/LevelReward.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/rewards/LevelReward.java new file mode 100644 index 000000000..177a74e7c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/rewards/LevelReward.java @@ -0,0 +1,18 @@ +package mineplex.core.achievement.leveling.rewards; + +import mineplex.core.Managers; +import mineplex.core.donation.DonationManager; +import mineplex.core.inventory.InventoryManager; +import org.bukkit.entity.Player; + +public interface LevelReward +{ + + DonationManager DONATION = Managers.require(DonationManager.class); + InventoryManager INVENTORY = Managers.require(InventoryManager.class); + + void claim(Player player); + + String getDescription(); + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/LevelRewardShop.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/LevelRewardShop.java new file mode 100644 index 000000000..dbf2757f8 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/LevelRewardShop.java @@ -0,0 +1,24 @@ +package mineplex.core.achievement.leveling.ui; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.achievement.leveling.LevelingManager; +import mineplex.core.achievement.leveling.ui.page.LevelRewardMainPage; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import org.bukkit.entity.Player; + +public class LevelRewardShop extends ShopBase +{ + + public LevelRewardShop(LevelingManager plugin, CoreClientManager clientManager, DonationManager donationManager) + { + super(plugin, clientManager, donationManager, "Level Reward"); + } + + @Override + protected ShopPageBase> buildPagesFor(Player player) + { + return new LevelRewardMainPage(getPlugin(), this, getClientManager(), getDonationManager(), player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/button/LevelRewardButton.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/button/LevelRewardButton.java new file mode 100644 index 000000000..a5d2bb5dd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/button/LevelRewardButton.java @@ -0,0 +1,53 @@ +package mineplex.core.achievement.leveling.ui.button; + +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import mineplex.core.achievement.leveling.LevelingManager; +import mineplex.core.achievement.leveling.rewards.LevelReward; +import mineplex.core.achievement.leveling.ui.LevelRewardShop; +import mineplex.core.common.util.F; +import mineplex.core.recharge.Recharge; +import mineplex.core.shop.item.IButton; +import mineplex.core.shop.page.ShopPageBase; + +public class LevelRewardButton implements IButton +{ + + private LevelingManager _plugin; + private ShopPageBase _menu; + private final List _rewards; + private final int _level; + + public LevelRewardButton(ShopPageBase menu, List rewards, int level) + { + _plugin = menu.getPlugin(); + _menu = menu; + _rewards = rewards; + _level = level; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + if (_plugin.hasClaimed(player, _level) || !_plugin.canClaim(player, _level) || !Recharge.Instance.use(player, "Claim Level Reward", 250, true, false)) + { + _menu.playDenySound(player); + return; + } + + // Give the player the reward + _rewards.forEach(reward -> reward.claim(player)); + _plugin.claim(player, _level); + + // Give some feedback + _menu.playAcceptSound(player); + player.sendMessage(F.main(_plugin.getName(), "You claimed rewards for level " + F.elem(_level) + ":")); + _rewards.forEach(reward -> player.sendMessage(F.main(_plugin.getName(), reward.getDescription()))); + + // Rebuild the menu + _menu.refresh(); + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/page/LevelRewardMainPage.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/page/LevelRewardMainPage.java new file mode 100644 index 000000000..e6a04d53a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/page/LevelRewardMainPage.java @@ -0,0 +1,157 @@ +package mineplex.core.achievement.leveling.ui.page; + +import java.util.List; +import java.util.Map.Entry; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.account.repository.token.Rank; +import mineplex.core.achievement.leveling.LevelingManager; +import mineplex.core.achievement.leveling.rewards.LevelReward; +import mineplex.core.achievement.leveling.ui.LevelRewardShop; +import mineplex.core.achievement.leveling.ui.button.LevelRewardButton; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilMath; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.item.IButton; +import mineplex.core.shop.page.ShopPageBase; + +public class LevelRewardMainPage extends ShopPageBase +{ + + private static final int VIEW_ALL_INDEX = 22; + private static final ItemStack VIEW_ALL = new ItemBuilder(Material.BOOK) + .setTitle(C.cGreen + "View All Rewards") + .addLore("Click to view all rewards.") + .build(); + private static final ItemStack MAX_LEVEL = new ItemBuilder(Material.FIREWORK) + .setTitle(C.cPurpleB + "Congratulations!") + .addLore( + "You have achieved the maximum level", + "possible on Mineplex! From all of us", + "here at Mineplex, we thank you for", + "dedicating so much time to the server.", + "", + "Unless you're an " + PermissionGroup.ADMIN.getDisplay(true, true, true, false) + C.mBody + " in which case", + "you cheated " + C.cPurple + "<3" + C.cGray + "." + ) + .build(); + + public LevelRewardMainPage(LevelingManager plugin, LevelRewardShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player) + { + super(plugin, shop, clientManager, donationManager, "Level Rewards", player, 3 * 9); + + buildPage(); + } + + @Override + protected void buildPage() + { + int current = _plugin.getFirstUnclaimedLevel(_player); + int previousA = getPreviousLevel(current); + int previousB = getPreviousLevel(previousA); + int nextA = getNextLevel(current); + int nextB = getNextLevel(nextA); + + List previousARewards = _plugin.getLevelRewards(previousA); + List previousBRewards = _plugin.getLevelRewards(previousB); + List currentRewards = _plugin.getLevelRewards(current); + List nextARewards = _plugin.getLevelRewards(nextA); + List nextBRewards = _plugin.getLevelRewards(nextB); + + // Order of display + // previousB -> previousA -> current -> nextA -> nextB + + addButton(11, previousB, previousBRewards); + addButton(12, previousA, previousARewards); + addButton(13, current, currentRewards); + addButton(14, nextA, nextARewards); + addButton(15, nextB, nextBRewards); + + addButton(VIEW_ALL_INDEX, VIEW_ALL, new ViewAllRewardsButton()); + + // Claimed all the rewards + if (current == -1) + { + addButtonNoAction(13, MAX_LEVEL); + + for (int i = 0; i < getSize(); i++) + { + if (i == 13 || i == VIEW_ALL_INDEX) + { + continue; + } + + addButtonNoAction(i, new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) UtilMath.r(15)) + .setTitle(C.cBlack) + .build()); + } + } + } + + private void addButton(int slot, int level, List rewards) + { + if (level < 0 || rewards.isEmpty()) + { + return; + } + + addButton(slot, _plugin.getLevelItem(_player, rewards, level), new LevelRewardButton(this, rewards, level)); + } + + private int getPreviousLevel(int level) + { + int previous = 0; + + for (Entry entry : _plugin.getLevelRewards()) + { + int currentLevel = entry.getKey(); + + if (currentLevel == level) + { + return previous; + } + + previous = currentLevel; + } + + return -1; + } + + private int getNextLevel(int level) + { + boolean foundSearch = false; + + for (Entry entry : _plugin.getLevelRewards()) + { + int currentLevel = entry.getKey(); + + if (currentLevel == level) + { + foundSearch = true; + } + else if (foundSearch) + { + return currentLevel; + } + } + + return -1; + } + + private class ViewAllRewardsButton implements IButton + { + + @Override + public void onClick(Player player, ClickType clickType) + { + _shop.openPageForPlayer(player, new LevelRewardViewAllPage(getPlugin(), getShop(), LevelRewardMainPage.this, getClientManager(), getDonationManager(), player, 1)); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/page/LevelRewardViewAllPage.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/page/LevelRewardViewAllPage.java new file mode 100644 index 000000000..44d6b52dd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/leveling/ui/page/LevelRewardViewAllPage.java @@ -0,0 +1,135 @@ +package mineplex.core.achievement.leveling.ui.page; + +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.achievement.leveling.LevelingManager; +import mineplex.core.achievement.leveling.rewards.LevelReward; +import mineplex.core.achievement.leveling.ui.LevelRewardShop; +import mineplex.core.achievement.leveling.ui.button.LevelRewardButton; +import mineplex.core.common.util.C; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.item.IButton; +import mineplex.core.shop.page.ShopPageBase; + +public class LevelRewardViewAllPage extends ShopPageBase +{ + + private static final int DISPLAY_SIZE = 45; + private static final ItemStack UNKNOWN_REWARD = new ItemBuilder(Material.OBSIDIAN) + .setTitle(C.cRed + "???") + .addLore("", C.cRed + "You aren't a high enough level to claim this reward.") + .build(); + private static final ItemStack GO_BACK = new ItemBuilder(Material.BED) + .setTitle(C.cGreen + "Click to go back.") + .build(); + + private final ShopPageBase _menu; + private int _startingLevel; + + LevelRewardViewAllPage(LevelingManager plugin, LevelRewardShop shop, ShopPageBase menu, CoreClientManager clientManager, DonationManager donationManager, Player player, int startingLevel) + { + super(plugin, shop, clientManager, donationManager, "All Level Rewards", player); + + _menu = menu; + _startingLevel = startingLevel; + + buildPage(); + } + + @Override + protected void buildPage() + { + int level = _startingLevel; + int playerLevel = _plugin.getLevel(_player); + boolean lastPage = false; + + // No i++ ?! look down + for (int i = 0; i < DISPLAY_SIZE; ) + { + if (level >= LevelingManager.getMaxLevel()) + { + lastPage = true; + break; + } + + List rewards = _plugin.getLevelRewards(level); + + // No reward for that level + if (rewards.isEmpty()) + { + level++; + continue; + } + + ItemStack itemStack; + + if (level > 100 && playerLevel < level) + { + itemStack = UNKNOWN_REWARD; + } + else + { + itemStack = _plugin.getLevelItem(_player, rewards, level); + } + + addButton(i++, itemStack, new LevelRewardButton(this, rewards, level)); + level++; + } + + // Not the first page + if (_startingLevel > 1) + { + addButton(46, getChangePageItem(true), new LevelRewardChangePageButton(_startingLevel - DISPLAY_SIZE)); + } + // Not the last page + else if (!lastPage) + { + addButton(53, getChangePageItem(false), new LevelRewardChangePageButton(_startingLevel + DISPLAY_SIZE)); + } + + addButton(49, GO_BACK, new GoBackButton()); + } + + private ItemStack getChangePageItem(boolean previous) + { + return new ItemBuilder(Material.ARROW) + .setTitle(previous ? "Previous Page" : "Next Page") + .build(); + } + + private class LevelRewardChangePageButton implements IButton + { + + private int _newStartingIndex; + + LevelRewardChangePageButton(int newStartingIndex) + { + _newStartingIndex = newStartingIndex; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + // Update the starting index and rebuild the page + _startingLevel = _newStartingIndex; + refresh(); + } + } + + private class GoBackButton implements IButton + { + + @Override + public void onClick(Player player, ClickType clickType) + { + _shop.openPageForPlayer(player, _menu); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/ui/page/AchievementPage.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/ui/page/AchievementPage.java index e5d931a7c..27106c9b4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/ui/page/AchievementPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/ui/page/AchievementPage.java @@ -236,7 +236,7 @@ public class AchievementPage extends ShopPageBase lore = new ArrayList(); lore.add(" "); - _category.addStats(getClientManager(), _statsManager, lore, getPlayer(), _targetName, _targetStats); + //_category.addStats(getClientManager(), _statsManager, lore, getPlayer(), _targetName, _targetStats); ItemStack item = new ItemStack(material); ItemMeta meta = item.getItemMeta(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/arena/Region.java b/Plugins/Mineplex.Core/src/mineplex/core/arena/Region.java deleted file mode 100644 index 0ac43c6cc..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/arena/Region.java +++ /dev/null @@ -1,163 +0,0 @@ -package mineplex.core.arena; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.util.Vector; - -public class Region -{ - private String _name; - private transient Vector _pointOne; - private transient Vector _pointTwo; - - private List _owners; - - private Boolean _blockPassage = false; - private Boolean _blockChange = true; - - private int _priority; - - private int _minX; - private int _minY; - private int _minZ; - - private int _maxX; - private int _maxY; - private int _maxZ; - - public Region(String name, Vector pointOne, Vector pointTwo) - { - _name = name; - _pointOne = pointOne; - _pointTwo = pointTwo; - _priority = 0; - _owners = new ArrayList(); - - UpdateMinMax(); - } - - public Vector GetMaximumPoint() - { - return new Vector(_maxX, _maxY, _maxZ); - } - - public void AdjustRegion(Vector vector) - { - _minX += vector.getBlockX(); - _minY += vector.getBlockY(); - _minZ += vector.getBlockZ(); - - _maxX += vector.getBlockX(); - _maxY += vector.getBlockY(); - _maxZ += vector.getBlockZ(); - } - - public Vector GetMinimumPoint() - { - return new Vector(_minX, _minY, _minZ); - } - - public Vector GetMidPoint() - { - return new Vector((_maxX - _minX)/2 + _minX, (_maxY - _minY)/2 + _minY, (_maxZ - _minZ)/2 + _minZ); - } - - public void SetPriority(int priority) - { - _priority = priority; - } - - public int GetPriority() - { - return _priority; - } - - public Boolean Contains(Vector v) - { - return v.getBlockX() >= _minX && v.getBlockX() <= _maxX - && v.getBlockY() >= _minY && v.getBlockY() <= _maxY - && v.getBlockZ() >= _minZ && v.getBlockZ() <= _maxZ; - } - - public void AddOwner(String name) - { - if (!_owners.contains(name.toLowerCase())) - { - _owners.add(name.toLowerCase()); - } - } - - public void RemoveOwner(String name) - { - _owners.remove(name.toLowerCase()); - } - - public void SetOwners(List owners) - { - _owners = owners; - - for (String ownerName : _owners) - { - ownerName = ownerName.toLowerCase(); - } - } - - public void SetEnter(Boolean canEnter) - { - _blockPassage = !canEnter; - } - - public void SetChangeBlocks(Boolean canChangeBlocks) - { - _blockChange = !canChangeBlocks; - } - - public Boolean CanEnter(String playerName) - { - if (_blockPassage) - { - if (!_owners.contains(playerName.toLowerCase())) - { - return false; - } - } - - return true; - } - - public Boolean CanChangeBlocks(String playerName) - { - if (_blockChange) - { - if (!_owners.contains(playerName.toLowerCase())) - { - return false; - } - } - - return true; - } - - public String GetName() - { - return _name; - } - - private void UpdateMinMax() - { - _minX = Math.min(_pointOne.getBlockX(), _pointTwo.getBlockX()); - _minY = Math.min(_pointOne.getBlockY(), _pointTwo.getBlockY()); - _minZ = Math.min(_pointOne.getBlockZ(), _pointTwo.getBlockZ()); - - _maxX = Math.max(_pointOne.getBlockX(), _pointTwo.getBlockX()); - _maxY = Math.max(_pointOne.getBlockY(), _pointTwo.getBlockY()); - _maxZ = Math.max(_pointOne.getBlockZ(), _pointTwo.getBlockZ()); - } - - @Override - public String toString() - { - return "Maximum point: " + GetMaximumPoint() + " Minimum point: " + GetMinimumPoint(); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index ad21ed84d..ef49e2761 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -57,9 +57,6 @@ import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilParticle.ParticleType; -import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; @@ -76,10 +73,10 @@ import mineplex.core.playwire.PlayWireManager; import mineplex.core.poll.PollManager; import mineplex.core.powerplayclub.PowerPlayClubRepository; import mineplex.core.recharge.Recharge; -import mineplex.core.reward.RewardManager; import mineplex.core.stats.StatsManager; import mineplex.core.thank.ThankManager; -import mineplex.core.treasure.TreasureType; +import mineplex.core.treasure.reward.TreasureRewardManager; +import mineplex.core.treasure.types.TreasureType; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.youtube.YoutubeManager; @@ -91,7 +88,7 @@ import mineplex.serverdata.database.DBPool; public class BonusManager extends MiniClientPlugin implements ILoginProcessor { public static final TimeZone TIMEZONE = TimeZone.getTimeZone("UTC"); - + private static long timeOffSet = 0; public enum Perm implements Permission @@ -108,7 +105,7 @@ public class BonusManager extends MiniClientPlugin implements I POWER_PLAY_COMMAND, TICKET_COMMAND, } - + private ArrayList _pendingExplosions = new ArrayList<>(); private ArrayList _pendingExplosionsPlayers = new ArrayList<>(); private final Map> _homeServerMap = new ConcurrentHashMap<>(); @@ -116,29 +113,29 @@ public class BonusManager extends MiniClientPlugin implements I private long _explode; private boolean _canVote; private boolean _animationRunning; - + public final boolean ClansBonus; public static long getSqlTime() { return getSqlTime(System.currentTimeMillis()); } - + public static long getSqlTime(long currentTime) { return currentTime + timeOffSet; } - + public static long getLocalTime() { return System.currentTimeMillis(); } - + public static long getLocalTime(long sqlTime) { return sqlTime - timeOffSet; } - + public void updateOffSet() { _repository.getTimeOffset(data -> timeOffSet = data); @@ -151,7 +148,7 @@ public class BonusManager extends MiniClientPlugin implements I private PollManager _pollManager; private NpcManager _npcManager; private HologramManager _hologramManager; - private RewardManager _rewardManager; + private TreasureRewardManager _rewardManager; private StatsManager _statsManager; private FacebookManager _facebookManager; private YoutubeManager _youtubeManager; @@ -163,11 +160,11 @@ public class BonusManager extends MiniClientPlugin implements I private Location _carlLocation; private AnimationCarl _animation; private int _visualTick; - + private ArrayList _voteList; - + private String _creeperName; - + /** * THIS SHOULD ONLY BE USED FOR VOTIFIER! */ @@ -183,9 +180,9 @@ public class BonusManager extends MiniClientPlugin implements I System.out.print("VOTIFIER: "); System.out.print("DONATION MANAGER - > " + _donationManager.toString()); - + ClansBonus = _plugin.getClass().getSimpleName().equalsIgnoreCase("ClansHub"); - + _voteList = new ArrayList<>(); if (ClansBonus) { @@ -198,11 +195,11 @@ public class BonusManager extends MiniClientPlugin implements I _voteList.add("http://vote1.mineplex.com"); _voteList.add("http://vote2.mineplex.com"); } - + _creeperName = "Carl"; updateOffSet(); - + generatePermissions(); } @@ -223,7 +220,7 @@ public class BonusManager extends MiniClientPlugin implements I System.out.print("GM NULL"); } - _rewardManager = new RewardManager(_clientManager, _donationManager, _inventoryManager, petManager, gadgetManager, statsManager); + _rewardManager = require(TreasureRewardManager.class); _pollManager = pollManager; _statsManager = statsManager; @@ -233,9 +230,9 @@ public class BonusManager extends MiniClientPlugin implements I _playWireManager = playWireManager; _powerPlayClubRepository = new PowerPlayClubRepository(plugin, _clientManager, _donationManager); - + ClansBonus = _plugin.getClass().getSimpleName().equalsIgnoreCase("ClansHub"); - + _voteList = new ArrayList<>(); if (ClansBonus) { @@ -264,8 +261,8 @@ public class BonusManager extends MiniClientPlugin implements I _carlNpc.setLocation(carlLocation); } _enabled = true; - _animation = new AnimationCarl(_carlNpc.getEntity()); - _animation.setRunning(false); +// _animation = new AnimationCarl(_carlNpc.getEntity()); +// _animation.setRunning(false); } } else @@ -274,11 +271,11 @@ public class BonusManager extends MiniClientPlugin implements I } clientManager.addStoredProcedureLoginProcessor(this); - + ServerCommandManager.getInstance().registerCommandType("VotifierCommand", VotifierCommand.class, new VoteHandler(this)); - + updateOffSet(); - + if (ClansBonus) { clientManager.addStoredProcedureLoginProcessor(new ILoginProcessor() @@ -306,10 +303,10 @@ public class BonusManager extends MiniClientPlugin implements I } }); } - + generatePermissions(); } - + private void generatePermissions() { PermissionGroup.ULTRA.setPermission(Perm.MONTHLY_BONUS, true, true); @@ -343,12 +340,12 @@ public class BonusManager extends MiniClientPlugin implements I return; updateOffSet(); } - + public String getCreeperName() { return _creeperName; } - + public Pair getClansHomeServer(Player player) { if (ClansBonus) @@ -360,7 +357,7 @@ public class BonusManager extends MiniClientPlugin implements I return Pair.create("No Server", -1); } } - + public void handleVote(final Player player, final int rewardReceived, final boolean clans) { final int accountId = _clientManager.getAccountId(player); @@ -373,7 +370,7 @@ public class BonusManager extends MiniClientPlugin implements I data.setHologram(oldData.getHologram()); } Set(player, data); - + if (clans) { _statsManager.incrementStat(player, "Global.ClansDailyVote", 1); @@ -390,52 +387,52 @@ public class BonusManager extends MiniClientPlugin implements I } }))); } - + @EventHandler public void fireCreeper(UpdateEvent event) { if(event.getType() != UpdateType.SLOW) return; - + if(_pendingExplosions.isEmpty()) return; if (_animationRunning) return; - + if (!_canVote) return; - + if (!_enabled) return; _animationRunning = true; _explode = System.currentTimeMillis(); - _animation.setTicks(0); + //_animation.setTicks(0); _canVote = false; } - + @EventHandler public void creeperAnimation(UpdateEvent event) { if (event.getType() != UpdateType.TICK) return; - - _animation.itemClean(); - + + //_animation.itemClean(); + if (_canVote) return; - + if (!_enabled) return; if (!_animationRunning) return; - + Entity creeper = _carlNpc.getEntity(); - + double elapsed = (System.currentTimeMillis() - _explode)/1000d; - + //Not Detonated if (elapsed < 1) { @@ -443,21 +440,21 @@ public class BonusManager extends MiniClientPlugin implements I creeper.getWorld().playSound(creeper.getLocation(), Sound.CREEPER_HISS, (float)(0.5 + elapsed), (float)(0.5 + elapsed)); IncreaseSize(creeper); - return; + return; } - if(!_animation.isRunning()) - { - //Effect - UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, creeper.getLocation(), 0, 0, 0, 0, 1, ViewDist.MAX, UtilServer.getPlayers()); - creeper.getWorld().playSound(creeper.getLocation(), Sound.EXPLODE, 2f, 1f); - _animation.setType(_pendingExplosions.get(0)); - _animation.setPlayer(_pendingExplosionsPlayers.get(0)); - _animation.setRunning(true); - } - - if(!_animation.isDone()) - return; +// if(!_animation.isRunning()) +// { +// //Effect +// UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, creeper.getLocation(), 0, 0, 0, 0, 1, ViewDist.MAX, UtilServer.getPlayers()); +// creeper.getWorld().playSound(creeper.getLocation(), Sound.EXPLODE, 2f, 1f); +// _animation.setType(_pendingExplosions.get(0)); +// _animation.setPlayer(_pendingExplosionsPlayers.get(0)); +// _animation.setRunning(true); +// } +// +// if(!_animation.isDone()) +// return; _animationRunning = false; DecreaseSize(creeper); @@ -465,22 +462,22 @@ public class BonusManager extends MiniClientPlugin implements I _pendingExplosionsPlayers.remove(0); _canVote = true; } - - @EventHandler - public void updateAnimation(UpdateEvent event) - { - if(event.getType() != UpdateType.TICK) - return; - if (!_enabled) - return; - - if(!_animation.isRunning()) - return; - - _animation.run(); - } - +// @EventHandler +// public void updateAnimation(UpdateEvent event) +// { +// if(event.getType() != UpdateType.TICK) +// return; +// +// if (!_enabled) +// return; +// +// if(!_animation.isRunning()) +// return; +// +// _animation.run(); +// } + public void DecreaseSize(Entity player) { if (!_enabled) @@ -488,7 +485,7 @@ public class BonusManager extends MiniClientPlugin implements I ((CraftEntity)_carlNpc.getEntity()).getHandle().getDataWatcher().watch(16, (byte) -1, EntityCreeper.META_FUSE_STATE, -1); } - + public void IncreaseSize(Entity player) { if (!_enabled) @@ -539,21 +536,21 @@ public class BonusManager extends MiniClientPlugin implements I public long nextDailyBonus(Player player) { Timestamp timestamp = ClansBonus ? Get(player).getClansDailyTime() : Get(player).getDailyTime(); - + if (timestamp == null) return 0; - + long lastBonus = timestamp.getTime(); - + return getLocalTime(lastBonus + TIME_BETWEEN_BONUSES); } - + // RANK BONUS public void attemptRankBonus(final Player player, final Callback result) { if (timeTillRankBonus(player) > 0) result.run(false); - + getRepository().attemptRankBonus(player, aBoolean -> { if (aBoolean) @@ -594,22 +591,22 @@ public class BonusManager extends MiniClientPlugin implements I } } } - + public long timeTillRankBonus(Player player) { return nextRankBonus(player) - getLocalTime(); } - + // This calculates the the next rank bonus, IT HAS TO MATCH THE MYSQL STORED FUNCTION. public long nextRankBonus(Player player) { Date date = Get(player).getRankTime(); - + if (date == null) return 0; - + long lastBonus = date.getTime(); - + return getNextRankBonusTime(getLocalTime(lastBonus)); } @@ -627,7 +624,7 @@ public class BonusManager extends MiniClientPlugin implements I } } } - + public void updateVoteStreak(BonusRecord client) { if (client.getVoteStreak() > 0 && client.getVotetime() != null) @@ -651,7 +648,7 @@ public class BonusManager extends MiniClientPlugin implements I if (data.getDailyStreak() > data.getMaxDailyStreak()) data.setMaxDailyStreak(data.getDailyStreak()); } - + public void incrementVoteStreak(BonusRecord client) { client.setVoteStreak(client.getVoteStreak() + 1); @@ -673,21 +670,21 @@ public class BonusManager extends MiniClientPlugin implements I long maxTime = localLastBonus + TIME_BETWEEN_BONUSES + extendTime; return maxTime - System.currentTimeMillis(); } - + public static long getNextRankBonusTime(long time) { - Calendar calendar = Calendar.getInstance(); + Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TIMEZONE); calendar.setTimeInMillis(time); - + calendar.add(Calendar.MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); - + calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); - + return calendar.getTimeInMillis(); } @@ -700,7 +697,7 @@ public class BonusManager extends MiniClientPlugin implements I if (streak >= 40) multiplier += (1 * (streak - 40)); return multiplier; } - + public int getVoteMultiplier(int streak) { int multiplier = Math.min(100, 5 * streak); @@ -729,13 +726,13 @@ public class BonusManager extends MiniClientPlugin implements I return amount; } - + public BonusAmount getClansDailyBonusAmount(Player player) { BonusAmount amount = new BonusAmount(); - + int serverId = getClansHomeServer(player).getRight(); - + if (serverId != -1) { amount.setGold(serverId, 500); @@ -743,7 +740,7 @@ public class BonusManager extends MiniClientPlugin implements I return amount; } - + public BonusAmount getVoteBonusAmount(Player player) { return getVoteBonusAmount(Get(player).getVoteStreak()); @@ -757,25 +754,25 @@ public class BonusManager extends MiniClientPlugin implements I amount.setTickets(1); amount.setGems(400); amount.setBonusGems((int) (mult * 400)); - + return amount; } - + public BonusAmount getClansVoteBonusAmount(Player player) { return getClansVoteBonusAmount(getClansHomeServer(player).getRight()); } - + public BonusAmount getClansVoteBonusAmount(int serverId) { BonusAmount amount = new BonusAmount(); - + if (serverId != -1) { amount.setTickets(1); amount.setGold(serverId, 1000); } - + return amount; } @@ -804,8 +801,8 @@ public class BonusManager extends MiniClientPlugin implements I return data; } - - + + //VOTE public long timeTillVoteBonus(Player player) { @@ -921,10 +918,10 @@ public class BonusManager extends MiniClientPlugin implements I UtilPlayer.message(player, F.main(_creeperName, "Rewarded " + F.elem(experience + " Experience"))); } } - + public static long getNextVoteTime(long time) { - Calendar calendar = Calendar.getInstance(); + Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TIMEZONE); calendar.setTimeInMillis(time); @@ -1009,7 +1006,7 @@ public class BonusManager extends MiniClientPlugin implements I BonusClientData client = Get(player); int availableRewards = 0; - + if (canVote(player)) availableRewards++; if (_playWireManager.Get(player) != null && _playWireManager.Get(player).getAccountId() != -1 && _playWireManager.canRedeemTickets(_playWireManager.Get(player))) availableRewards++; if (_youtubeManager.canYoutube(player)) availableRewards++; @@ -1025,10 +1022,10 @@ public class BonusManager extends MiniClientPlugin implements I if (client.getHologram() == null) { double yAdd = 2.3; - if(!UtilPlayer.is1_9(player)) - { - yAdd = 2.45; - } + if(!UtilPlayer.is1_9(player)) + { + yAdd = 2.45; + } hologram = new Hologram(_hologramManager, _carlNpc.getLocation().clone().add(0, yAdd, 0), ""); hologram.setHologramTarget(Hologram.HologramTarget.WHITELIST); hologram.addPlayer(player); @@ -1089,7 +1086,7 @@ public class BonusManager extends MiniClientPlugin implements I _visualTick++; } - + @Override protected BonusClientData addPlayer(UUID uuid) { @@ -1106,11 +1103,6 @@ public class BonusManager extends MiniClientPlugin implements I return _clientManager; } - public RewardManager getRewardManager() - { - return _rewardManager; - } - @Override @EventHandler public void UnloadPlayer(final ClientUnloadEvent event) @@ -1133,7 +1125,7 @@ public class BonusManager extends MiniClientPlugin implements I _pendingExplosions.add(obj); _pendingExplosionsPlayers.add(player); } - + public PollManager getPollManager() { return _pollManager; @@ -1154,7 +1146,7 @@ public class BonusManager extends MiniClientPlugin implements I { runSyncLater(() -> _showCarl.put(event.getPlayer().getName(), true), 200); } - + @EventHandler public void Quit(PlayerQuitEvent event) { @@ -1162,31 +1154,31 @@ public class BonusManager extends MiniClientPlugin implements I // Removes from allow command map UtilPlayer.removeAllowedCommands(event.getPlayer()); } - + @EventHandler public void carlUpdate(UpdateEvent event) { if (event.getType() != UpdateType.SEC) return; - - for (Player player : UtilServer.getPlayers()) - { - if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false)) - { - if (_pollManager.hasPoll(player) || canVote(player) || _youtubeManager.canYoutube(player) || (_playWireManager.Get(player) != null && _playWireManager.Get(player).getAccountId() != -1 && _playWireManager.canRedeemTickets(_playWireManager.Get(player))) || (canRank(player) && _clientManager.Get(player).hasPermission(Perm.MONTHLY_BONUS) && isPastAugust()) || canDaily(player) || PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository)) - { - if (_showCarl.containsKey(player.getName())) - { - if (_plugin.getClass().getSimpleName().equalsIgnoreCase("Hub") || _plugin.getClass().getSimpleName().equalsIgnoreCase("ClansHub")) - { - UtilPlayer.message(player, C.cDGreen + C.Bold + _creeperName + " the Creeper>" + C.cGreen + " Hey " + player.getName().replace("s", "sss") + "! I have sssome amazing rewardsss for you! Come sssee me!"); - } - } - } - } - } + + for (Player player : UtilServer.getPlayers()) + { + if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false)) + { + if (_pollManager.hasPoll(player) || canVote(player) || _youtubeManager.canYoutube(player) || (_playWireManager.Get(player) != null && _playWireManager.Get(player).getAccountId() != -1 && _playWireManager.canRedeemTickets(_playWireManager.Get(player))) || (canRank(player) && _clientManager.Get(player).hasPermission(Perm.MONTHLY_BONUS) && isPastAugust()) || canDaily(player) || PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository)) + { + if (_showCarl.containsKey(player.getName())) + { + if (_plugin.getClass().getSimpleName().equalsIgnoreCase("Hub") || _plugin.getClass().getSimpleName().equalsIgnoreCase("ClansHub")) + { + UtilPlayer.message(player, C.cDGreen + C.Bold + _creeperName + " the Creeper>" + C.cGreen + " Hey " + player.getName().replace("s", "sss") + "! I have sssome amazing rewardsss for you! Come sssee me!"); + } + } + } + } + } } - + public String getVoteLink() { long sqlTime = getSqlTime(); @@ -1259,7 +1251,7 @@ public class BonusManager extends MiniClientPlugin implements I { _carlLocation = carlLocation; } - + public Npc getCarl() { return _carlNpc; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/animations/AnimationCarl.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/animations/AnimationCarl.java index aeecb152f..1a633a495 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/animations/AnimationCarl.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/animations/AnimationCarl.java @@ -10,8 +10,6 @@ import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.treasure.animation.Animation; import org.bukkit.Color; import org.bukkit.FireworkEffect.Type; import org.bukkit.Location; @@ -24,291 +22,291 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -public class AnimationCarl extends Animation +public class AnimationCarl { - private boolean _isDone; - private Block _creeper; - private Object _type; - private Player _player; - - private HashSet _items = new HashSet(); - - public AnimationCarl(Entity creeper) - { - _creeper = creeper.getLocation().getBlock(); - } - - @Override - protected void tick() - { - if(_type instanceof String) - { - if(((String) _type).contentEquals("DAILY") || ((String) _type).contentEquals("POLL")) - { - for (int i = 50; i < 60; i++) - { - Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i)); - Item shard = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.PRISMARINE_SHARD, (byte) 0, 1, " " + i)); - _items.add(gem); - _items.add(shard); - - Vector vel = new Vector(Math.sin(i * 9/5d), 0, Math.cos(i * 9/5d)); - UtilAction.velocity(gem, vel, Math.abs(Math.sin(i * 12/3000d)), false, 0, 0.2 + Math.abs(Math.cos(i * 12/3000d))*0.6, 1, false); - UtilAction.velocity(shard, vel, Math.abs(Math.sin(UtilMath.r(i) * 30/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 30/3000d))*0.6, 1, false); - - } - } - if(((String) _type).contentEquals("RANK")) - { - for (int i = 50; i < 60; i++) - { - Item shard = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.PRISMARINE_SHARD, (byte) 0, 1, " " + i)); - _items.add(shard); - - Vector vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d)); - UtilAction.velocity(shard, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false); - - } - } - if(!((String) _type).contentEquals("DAILY") && !((String) _type).contentEquals("RANK") && !((String) _type).contentEquals("POLL")) - { - - Item paper = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.PAPER, (byte) 0, 1, " " + 64)); - _items.add(paper); - - Vector vel = new Vector(Math.sin(64 * 8/5d), 0, Math.cos(64 * 8/5d)); - UtilAction.velocity(paper, vel, Math.abs(Math.sin(64 * 9/3000d)), false, 0, 0.2 + Math.abs(Math.cos(64 + 9/3000d))*0.6, 1, false); - - for (int i = 50; i < 60; i++) - { - Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i)); - _items.add(gem); - - Vector velo = new Vector(Math.sin(i * 8/5d), 0, Math.cos(i * 8/5d)); - UtilAction.velocity(gem, velo, Math.abs(Math.sin(i * 8/3000d)), false, 0, 0.2 + Math.abs(Math.cos(i + 8/3000d))*0.6, 1, false); - - } - } - finish(); - } - if(_type instanceof Reward) - { - if(getTicks() == 0) - { - RewardData rewardData = ((Reward)_type).getFakeRewardData(_player); - ItemStack itemStack = rewardData.getDisplayItem(); - Item item = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.7, 0.5), itemStack); - _items.add(item); - - Vector vel = new Vector(_player.getLocation().getX() - _creeper.getLocation().getX(), 0, _player.getLocation().getZ() - _creeper.getLocation().getZ()); - - UtilAction.velocity(item, vel, 0.1, false, 0, 0.2 + 1*0.4, 1, false); - } - - if(((Reward)_type).getRarity() == RewardRarity.RARE) - { - RareAnimation(); - } - else if(((Reward)_type).getRarity() == RewardRarity.LEGENDARY) - { - LegendAnimation(); - } - else if(((Reward)_type).getRarity() == RewardRarity.MYTHICAL) - { - MythicalAnimation(); - } - else - { - finish(); - } - } - if (_type instanceof PowerPlayAnimation) - { - for (int i = 50; i < 65; i++) - { - // Gem amplifier - Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i)); - _items.add(gem); - - Vector vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d)); - UtilAction.velocity(gem, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false); - - // Omega chest - Item omega = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), SkinData.OMEGA_CHEST.getSkull()); - _items.add(omega); - - vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d)); - UtilAction.velocity(omega, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false); - - // Monthly items - PowerPlayAnimation powerPlayAnimation = (PowerPlayAnimation) _type; - for (ItemStack itemStack : powerPlayAnimation.getAnimationItems()) - { - Item monthly = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), itemStack); - _items.add(monthly); - - vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d)); - UtilAction.velocity(monthly, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false); - } - } - finish(); - } - } - - @Override - protected void onFinish() { - _isDone = true; - _player = null; - setTicks(0); - } - - public boolean isDone() - { - return _isDone; - } - - public void setDone(boolean b) - { - _isDone = b; - } - - public void setType(Object type) - { - _type = type; - } - - public void setPlayer(Player player) - { - _player = player; - } - - public void LegendAnimation() - { - if (getTicks() < 1) - { - UtilFirework.playFirework(_creeper.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.LIME, true, true); - } - - if (getTicks() == 1) - { - _creeper.getLocation().getWorld().playSound(_creeper.getLocation().add(0.5, 0.5, 0.5), Sound.ENDERDRAGON_DEATH, 10F, 2.0F); - } - else if (getTicks() < 35) - { - double radius = 2 - (getTicks() / 10D * 2); - int particleAmount = 20 - (getTicks() * 2); - Location _centerLocation = _creeper.getLocation().add(0.5, 0.1, 0.5); - for (int i = 0; i < particleAmount; i++) - { - double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; - double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; - for(double e = 0.1 ; e < 3 ; e += 0.6) - { - Location location = _centerLocation.clone().add(xDiff, e, zDiff); - UtilParticle.PlayParticle(UtilParticle.ParticleType.HAPPY_VILLAGER, location, 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); - } - } - } - else - { - finish(); - } - } - - public void MythicalAnimation() - { - if (getTicks() < 30) - { - UtilFirework.playFirework(_creeper.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.RED, true, true); - } - - if (getTicks() == 1) - { - _creeper.getLocation().getWorld().playSound(_creeper.getLocation().add(0.5, 0.5, 0.5), Sound.PORTAL_TRAVEL, 10F, 2.0F); - _creeper.getLocation().getWorld().playSound(_creeper.getLocation().add(0.5, 0.5, 0.5), Sound.ZOMBIE_UNFECT, 10F, 0.1F); - } - else if (getTicks() < 40) - { - UtilFirework.launchFirework(_creeper.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.RED, true, true, - new Vector((Math.random()-0.5)*0.05, 0.1, (Math.random()-0.5)*0.05), 1); - - //Particle Spiral Up - double radius = getTicks() / 20D; - int particleAmount = getTicks() / 2; - for (int i = 0; i < particleAmount; i++) - { - double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; - double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; - - Location location = _creeper.getLocation().add(0.5, 0, 0.5).clone().add(xDiff, -1.3, zDiff); - UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - - Location _centerLocation = _creeper.getLocation().add(0.5, 0.1, 0.5); - for (int i = 0; i < particleAmount; i++) - { - double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; - double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; - for(double e = 0.1 ; e < 3 ; e += 0.5) - { - Location location = _centerLocation.clone().add(xDiff, e, zDiff); - UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); - } - } - } - else - { - finish(); - } - } - - public void RareAnimation() - { - if (getTicks() == 1) - { - for(int i = 0; i < 3; i++) - { - UtilFirework.playFirework(_creeper.getLocation().add(0.5, i, 0.5), Type.BALL, Color.FUCHSIA, false, false); - } - _creeper.getWorld().playSound(_creeper.getLocation(), Sound.WITHER_SPAWN, 10F, 1.2F); - } - else if (getTicks() >= 60) - { - finish(); - } - - else if (getTicks() < 35) - { - double radius = 2 - (getTicks() / 10D * 2); - int particleAmount = 20 - (getTicks() * 2); - Location _centerLocation = _creeper.getLocation().add(0.5, 0.1, 0.5); - for (int i = 0; i < particleAmount; i++) - { - double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; - double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; - for(double e = 0.1 ; e < 3 ; e += 0.6) - { - Location location = _centerLocation.clone().add(xDiff, e, zDiff); - UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); - } - } - } - } - - public void itemClean() - { - Iterator itemIterator = _items.iterator(); - - while (itemIterator.hasNext()) - { - Item item = itemIterator.next(); - - if (item.isOnGround() || !item.isValid() || item.getTicksLived() > 60) - { - item.remove(); - itemIterator.remove(); - } - } - } +// private boolean _isDone; +// private Block _creeper; +// private Object _type; +// private Player _player; +// +// private HashSet _items = new HashSet(); +// +// public AnimationCarl(Entity creeper) +// { +// _creeper = creeper.getLocation().getBlock(); +// } +// +// @Override +// protected void tick() +// { +// if(_type instanceof String) +// { +// if(((String) _type).contentEquals("DAILY") || ((String) _type).contentEquals("POLL")) +// { +// for (int i = 50; i < 60; i++) +// { +// Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i)); +// Item shard = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.PRISMARINE_SHARD, (byte) 0, 1, " " + i)); +// _items.add(gem); +// _items.add(shard); +// +// Vector vel = new Vector(Math.sin(i * 9/5d), 0, Math.cos(i * 9/5d)); +// UtilAction.velocity(gem, vel, Math.abs(Math.sin(i * 12/3000d)), false, 0, 0.2 + Math.abs(Math.cos(i * 12/3000d))*0.6, 1, false); +// UtilAction.velocity(shard, vel, Math.abs(Math.sin(UtilMath.r(i) * 30/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 30/3000d))*0.6, 1, false); +// +// } +// } +// if(((String) _type).contentEquals("RANK")) +// { +// for (int i = 50; i < 60; i++) +// { +// Item shard = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.PRISMARINE_SHARD, (byte) 0, 1, " " + i)); +// _items.add(shard); +// +// Vector vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d)); +// UtilAction.velocity(shard, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false); +// +// } +// } +// if(!((String) _type).contentEquals("DAILY") && !((String) _type).contentEquals("RANK") && !((String) _type).contentEquals("POLL")) +// { +// +// Item paper = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.PAPER, (byte) 0, 1, " " + 64)); +// _items.add(paper); +// +// Vector vel = new Vector(Math.sin(64 * 8/5d), 0, Math.cos(64 * 8/5d)); +// UtilAction.velocity(paper, vel, Math.abs(Math.sin(64 * 9/3000d)), false, 0, 0.2 + Math.abs(Math.cos(64 + 9/3000d))*0.6, 1, false); +// +// for (int i = 50; i < 60; i++) +// { +// Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i)); +// _items.add(gem); +// +// Vector velo = new Vector(Math.sin(i * 8/5d), 0, Math.cos(i * 8/5d)); +// UtilAction.velocity(gem, velo, Math.abs(Math.sin(i * 8/3000d)), false, 0, 0.2 + Math.abs(Math.cos(i + 8/3000d))*0.6, 1, false); +// +// } +// } +// finish(); +// } +// if(_type instanceof Reward) +// { +// if(getTicks() == 0) +// { +// RewardData rewardData = ((Reward)_type).getFakeRewardData(_player); +// ItemStack itemStack = rewardData.getDisplayItem(); +// Item item = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.7, 0.5), itemStack); +// _items.add(item); +// +// Vector vel = new Vector(_player.getLocation().getX() - _creeper.getLocation().getX(), 0, _player.getLocation().getZ() - _creeper.getLocation().getZ()); +// +// UtilAction.velocity(item, vel, 0.1, false, 0, 0.2 + 1*0.4, 1, false); +// } +// +// if(((Reward)_type).getRarity() == RewardRarity.RARE) +// { +// RareAnimation(); +// } +// else if(((Reward)_type).getRarity() == RewardRarity.LEGENDARY) +// { +// LegendAnimation(); +// } +// else if(((Reward)_type).getRarity() == RewardRarity.MYTHICAL) +// { +// MythicalAnimation(); +// } +// else +// { +// finish(); +// } +// } +// if (_type instanceof PowerPlayAnimation) +// { +// for (int i = 50; i < 65; i++) +// { +// // Gem amplifier +// Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i)); +// _items.add(gem); +// +// Vector vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d)); +// UtilAction.velocity(gem, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false); +// +// // Omega chest +// Item omega = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), SkinData.OMEGA_CHEST.getSkull()); +// _items.add(omega); +// +// vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d)); +// UtilAction.velocity(omega, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false); +// +// // Monthly items +// PowerPlayAnimation powerPlayAnimation = (PowerPlayAnimation) _type; +// for (ItemStack itemStack : powerPlayAnimation.getAnimationItems()) +// { +// Item monthly = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), itemStack); +// _items.add(monthly); +// +// vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d)); +// UtilAction.velocity(monthly, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false); +// } +// } +// finish(); +// } +// } +// +// @Override +// protected void onFinish() { +// _isDone = true; +// _player = null; +// setTicks(0); +// } +// +// public boolean isDone() +// { +// return _isDone; +// } +// +// public void setDone(boolean b) +// { +// _isDone = b; +// } +// +// public void setType(Object type) +// { +// _type = type; +// } +// +// public void setPlayer(Player player) +// { +// _player = player; +// } +// +// public void LegendAnimation() +// { +// if (getTicks() < 1) +// { +// UtilFirework.playFirework(_creeper.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.LIME, true, true); +// } +// +// if (getTicks() == 1) +// { +// _creeper.getLocation().getWorld().playSound(_creeper.getLocation().add(0.5, 0.5, 0.5), Sound.ENDERDRAGON_DEATH, 10F, 2.0F); +// } +// else if (getTicks() < 35) +// { +// double radius = 2 - (getTicks() / 10D * 2); +// int particleAmount = 20 - (getTicks() * 2); +// Location _centerLocation = _creeper.getLocation().add(0.5, 0.1, 0.5); +// for (int i = 0; i < particleAmount; i++) +// { +// double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; +// double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; +// for(double e = 0.1 ; e < 3 ; e += 0.6) +// { +// Location location = _centerLocation.clone().add(xDiff, e, zDiff); +// UtilParticle.PlayParticle(UtilParticle.ParticleType.HAPPY_VILLAGER, location, 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); +// } +// } +// } +// else +// { +// finish(); +// } +// } +// +// public void MythicalAnimation() +// { +// if (getTicks() < 30) +// { +// UtilFirework.playFirework(_creeper.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.RED, true, true); +// } +// +// if (getTicks() == 1) +// { +// _creeper.getLocation().getWorld().playSound(_creeper.getLocation().add(0.5, 0.5, 0.5), Sound.PORTAL_TRAVEL, 10F, 2.0F); +// _creeper.getLocation().getWorld().playSound(_creeper.getLocation().add(0.5, 0.5, 0.5), Sound.ZOMBIE_UNFECT, 10F, 0.1F); +// } +// else if (getTicks() < 40) +// { +// UtilFirework.launchFirework(_creeper.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.RED, true, true, +// new Vector((Math.random()-0.5)*0.05, 0.1, (Math.random()-0.5)*0.05), 1); +// +// //Particle Spiral Up +// double radius = getTicks() / 20D; +// int particleAmount = getTicks() / 2; +// for (int i = 0; i < particleAmount; i++) +// { +// double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; +// double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; +// +// Location location = _creeper.getLocation().add(0.5, 0, 0.5).clone().add(xDiff, -1.3, zDiff); +// UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, +// ViewDist.NORMAL, UtilServer.getPlayers()); +// } +// +// Location _centerLocation = _creeper.getLocation().add(0.5, 0.1, 0.5); +// for (int i = 0; i < particleAmount; i++) +// { +// double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; +// double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; +// for(double e = 0.1 ; e < 3 ; e += 0.5) +// { +// Location location = _centerLocation.clone().add(xDiff, e, zDiff); +// UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); +// } +// } +// } +// else +// { +// finish(); +// } +// } +// +// public void RareAnimation() +// { +// if (getTicks() == 1) +// { +// for(int i = 0; i < 3; i++) +// { +// UtilFirework.playFirework(_creeper.getLocation().add(0.5, i, 0.5), Type.BALL, Color.FUCHSIA, false, false); +// } +// _creeper.getWorld().playSound(_creeper.getLocation(), Sound.WITHER_SPAWN, 10F, 1.2F); +// } +// else if (getTicks() >= 60) +// { +// finish(); +// } +// +// else if (getTicks() < 35) +// { +// double radius = 2 - (getTicks() / 10D * 2); +// int particleAmount = 20 - (getTicks() * 2); +// Location _centerLocation = _creeper.getLocation().add(0.5, 0.1, 0.5); +// for (int i = 0; i < particleAmount; i++) +// { +// double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; +// double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; +// for(double e = 0.1 ; e < 3 ; e += 0.6) +// { +// Location location = _centerLocation.clone().add(xDiff, e, zDiff); +// UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); +// } +// } +// } +// } +// +// public void itemClean() +// { +// Iterator itemIterator = _items.iterator(); +// +// while (itemIterator.hasNext()) +// { +// Item item = itemIterator.next(); +// +// if (item.isOnGround() || !item.isValid() || item.getTicksLived() > 60) +// { +// item.remove(); +// itemIterator.remove(); +// } +// } +// } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/AnimationCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/AnimationCommand.java index 96d54ae38..126b49b4d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/AnimationCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/AnimationCommand.java @@ -21,7 +21,7 @@ public class AnimationCommand extends CommandBase{ public void Execute(Player caller, String[] args) { caller = Bukkit.getPlayer(args[0]); - _plugin.addPendingExplosion(caller, _plugin.getRewardManager().nextReward(caller, null, false, RewardType.SPINNER_FILLER, true)); + //plugin.addPendingExplosion(caller, _plugin.getRewardManager().nextReward(caller, null, false, RewardType.SPINNER_FILLER, true)); if (args.length >= 2) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java index bd48a0205..1e9ff0293 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java @@ -2,9 +2,11 @@ package mineplex.core.bonuses.commands; import org.bukkit.entity.Player; +import mineplex.core.Managers; import mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.gui.BonusGui; import mineplex.core.command.CommandBase; +import mineplex.core.treasure.reward.TreasureRewardManager; public class GuiCommand extends CommandBase { @@ -16,6 +18,6 @@ public class GuiCommand extends CommandBase @Override public void Execute(Player caller, String[] args) { - new BonusGui(Plugin.getPlugin(), caller, Plugin, Plugin.getRewardManager(), Plugin.getFacebookManager(), Plugin.getYoutubeManager(), Plugin.getThankManager(), Plugin.getPlayWireManager()).openInventory(); + new BonusGui(Plugin.getPlugin(), caller, Plugin, Managers.require(TreasureRewardManager.class), Plugin.getFacebookManager(), Plugin.getYoutubeManager(), Plugin.getThankManager(), Plugin.getPlayWireManager()).openInventory(); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java index 413816698..eeb975e48 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java @@ -17,8 +17,8 @@ import mineplex.core.bonuses.gui.buttons.VoteButton; import mineplex.core.bonuses.gui.buttons.YoutubeButton; import mineplex.core.facebook.FacebookManager; import mineplex.core.gui.SimpleGui; +import mineplex.core.treasure.reward.TreasureRewardManager; import mineplex.core.playwire.PlayWireManager; -import mineplex.core.reward.RewardManager; import mineplex.core.thank.ThankManager; import mineplex.core.youtube.YoutubeManager; @@ -38,7 +38,7 @@ public class BonusGui extends SimpleGui private static final int INV_SIZE = 54; - public BonusGui(Plugin plugin, Player player, BonusManager manager, RewardManager rewardManager, FacebookManager facebookManager, YoutubeManager youtubeManager, ThankManager thankManager, PlayWireManager playWireManager) + public BonusGui(Plugin plugin, Player player, BonusManager manager, TreasureRewardManager rewardManager, FacebookManager facebookManager, YoutubeManager youtubeManager, ThankManager thankManager, PlayWireManager playWireManager) { super(plugin, player, player.getName() + "'s Bonuses", INV_SIZE); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java index d450c357a..44d6341db 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java @@ -2,25 +2,6 @@ package mineplex.core.bonuses.gui; import java.util.ArrayList; -import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.gui.DisplayItem; -import mineplex.core.gui.SimpleGui; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.reward.Reward; -import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardManager; -import mineplex.core.reward.RewardPool.Type; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; -import mineplex.core.shop.item.ShopItem; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.core.bonuses.BonusManager; -import mineplex.core.bonuses.gui.buttons.RewardButton; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -32,20 +13,37 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.bonuses.gui.buttons.RewardButton; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.gui.DisplayItem; +import mineplex.core.gui.SimpleGui; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardData; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.treasure.reward.RewardRarity; +import mineplex.core.treasure.reward.TreasureRewardManager; +import mineplex.core.treasure.types.CarlTreasure; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + public class SpinGui extends SimpleGui { + private static final int HOPPER_SLOT = 4; private static final int CARL_SLOT = 22; - private static final int[] LINE_NUMS = { /*-27, -18,*/ -9, 9/*, 18*/ }; + private static final int[] LINE_NUMS = { /*-27, -18,*/ -9, 9/*, 18*/}; + private static final CarlTreasure TREASURE = new CarlTreasure(); - private int _tickCount; private RewardData _rewardData; private Reward _reward; private BonusManager _manager; private int _currentRewardIndex; private int _ticksThisSwap; private int _ticksPerSwap; - private int _swapCount; private Reward[] _rewards; private boolean _stopped; private boolean _rewarded; @@ -54,94 +52,85 @@ public class SpinGui extends SimpleGui private float _pitch; private int _stopSpinnerAt; - public SpinGui(Plugin plugin, Player player, RewardManager rewardManager, BonusManager manager) + public SpinGui(Plugin plugin, Player player, TreasureRewardManager rewardManager, BonusManager manager) { super(plugin, player, "Carl's Spinner", 27); - + _manager = manager; - ShopItem carlItem = new ShopItem(Material.SKULL_ITEM, (byte) 4, "Carl's Spinner", new String[] {ChatColor.RESET + "Good Luck!" }, 1, false, false); + ShopItem carlItem = new ShopItem(Material.SKULL_ITEM, (byte) 4, "Carl's Spinner", new String[]{ChatColor.RESET + "Good Luck!"}, 1, false, false); setItem(HOPPER_SLOT, new DisplayItem(new ItemStack(Material.HOPPER))); //setItem(CARL_SLOT, new DisplayItem(carlItem)); - + _ticks = new ArrayList<>(); _frame = 0; _pitch = 1; - - + _ticksPerSwap = 1; - for (int i=0 ; i<40 ; i++) + for (int i = 0; i < 40; i++) _ticks.add(1); - - for (int i=0 ; i<20 ; i++) + + for (int i = 0; i < 20; i++) _ticks.add(2); - for (int i=0 ; i<10 ; i++) + for (int i = 0; i < 10; i++) _ticks.add(4); - for (int i=0 ; i<4 ; i++) + for (int i = 0; i < 4; i++) _ticks.add(6); - - for (int i=0 ; i<3 ; i++) + + for (int i = 0; i < 3; i++) _ticks.add(8); - + if (Math.random() > 0.5) { - _ticks.add(12); + _ticks.add(12); } - + _stopSpinnerAt = _ticks.size(); - + //Create Rewards - _rewards = new Reward[_stopSpinnerAt+10]; //Adding 10, so theres items to the right still. - for (int i = 0; i < _stopSpinnerAt+10 ; i++) + _rewards = new Reward[_stopSpinnerAt + 10]; //Adding 10, so theres items to the right still. + for (int i = 0; i < _stopSpinnerAt + 10; i++) { if (i != _stopSpinnerAt + 4) { - _rewards[i] = rewardManager.nextReward(player, Type.CARL_SPINNER, null, false, RewardType.SPINNER_FILLER, true); + _rewards[i] = TREASURE.nextReward(player, true); } else { - _rewards[i] = rewardManager.nextReward(player, Type.CARL_SPINNER, null, false, RewardType.SPINNER_REAL, true); + _rewards[i] = TREASURE.nextReward(player, false); _reward = _rewards[i]; } } - - _reward.giveReward(RewardType.SPINNER_REAL, getPlayer(), new Callback() - { - @Override - public void run(RewardData data) - { - _rewardData = data; - } - }); + + _reward.giveReward(player, data -> _rewardData = data); } private void tick() { - - if(_stopped) + + if (_stopped) return; - + _ticksThisSwap++; // Swap if (_ticksThisSwap >= _ticksPerSwap) { _ticksThisSwap = 0; - _swapCount++; - if(_pitch == 1) - _pitch = (float) 1.5; - else if(_pitch == 1.5) - _pitch = 2; - else if(_pitch == 2) - _pitch = 1; - + if (_pitch == 1) + _pitch = (float) 1.5; + else if (_pitch == 1.5) + _pitch = 2; + else if (_pitch == 2) + _pitch = 1; + getPlayer().playSound(getPlayer().getEyeLocation(), Sound.NOTE_PLING, 1, _pitch); _currentRewardIndex++; @@ -150,12 +139,10 @@ public class SpinGui extends SimpleGui // Slow _ticksPerSwap = _ticks.get(_currentRewardIndex - 1); - - if(_currentRewardIndex == _stopSpinnerAt) + + if (_currentRewardIndex == _stopSpinnerAt) _stopped = true; } - - _tickCount++; } public void updateGui() @@ -189,18 +176,18 @@ public class SpinGui extends SimpleGui tick(); checkIfDone(); } - + @EventHandler(priority = EventPriority.HIGHEST) public void close(InventoryCloseEvent event) { - if(_rewarded) + if (_rewarded) return; - - if(event.getPlayer() != getPlayer()) + + if (event.getPlayer() != getPlayer()) return; - + _manager.addPendingExplosion(getPlayer(), _reward); - + if (_reward.getRarity() == RewardRarity.RARE) { Bukkit.broadcastMessage(F.main("Treasure", F.name(event.getPlayer().getName()) + " won " + C.cPurple + "Rare " + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); @@ -218,51 +205,51 @@ public class SpinGui extends SimpleGui UtilPlayer.message(getPlayer(), F.main("Carl's Spinner", "You won " + _rewardData.getRarity().getColor() + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); } } - + @EventHandler public void Glass(UpdateEvent event) { if (event.getType() != UpdateType.FAST) return; - if(!_stopped) + if (!_stopped) return; - - if(!_rewarded) + + if (!_rewarded) return; - - if(_frame == 0) + + if (_frame == 0) { setItem(CARL_SLOT, new DisplayItem(_rewardData.getRarity().getItemStack())); setItem(HOPPER_SLOT, new DisplayItem(_rewardData.getRarity().getItemStack())); _frame++; } - else if(_frame < 5) + else if (_frame < 5) { setItem(HOPPER_SLOT + _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); setItem(HOPPER_SLOT - _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); - + setItem(CARL_SLOT + _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); setItem(CARL_SLOT - _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); - + setItem(13 + _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); setItem(13 - _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); _frame++; } - if(_frame == 6) + if (_frame == 6) { - + } } - + public void checkIfDone() { - if(!_stopped) + if (!_stopped) return; - - if(_rewarded) + + if (_rewarded) return; - + _manager.addPendingExplosion(getPlayer(), _reward); if (_reward.getRarity() == RewardRarity.RARE) { @@ -283,7 +270,7 @@ public class SpinGui extends SimpleGui ItemStack item = getInventory().getItem(13); getInventory().setItem(13, ItemStackFactory.Instance.CreateStack(item.getType(), (byte) 0, 1, _rewardData.getFriendlyName())); _rewarded = true; - + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/CarlSpinButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/CarlSpinButton.java index 210f773cd..aae2c322e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/CarlSpinButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/CarlSpinButton.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.Plugin; import mineplex.core.common.util.C; import mineplex.core.gui.GuiItem; -import mineplex.core.reward.RewardManager; +import mineplex.core.treasure.reward.TreasureRewardManager; import mineplex.core.shop.item.ShopItem; import mineplex.core.bonuses.BonusClientData; import mineplex.core.bonuses.BonusManager; @@ -21,9 +21,9 @@ public class CarlSpinButton implements GuiItem private Plugin _plugin; private Player _player; private BonusManager _bonusManager; - private RewardManager _rewardManager; + private TreasureRewardManager _rewardManager; - public CarlSpinButton(Plugin plugin, Player player, BonusManager bonusManager, RewardManager rewardManager) + public CarlSpinButton(Plugin plugin, Player player, BonusManager bonusManager, TreasureRewardManager rewardManager) { _plugin = plugin; _player = player; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java index 0f87c2f6d..adddba814 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java @@ -33,9 +33,9 @@ import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.treasure.TreasureManager; import mineplex.core.pet.PetManager; import mineplex.core.punish.Punish; -import mineplex.core.treasure.TreasureManager; import mineplex.core.twofactor.TwoFactorAuth; public class CosmeticManager extends MiniPlugin diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java index 27995bae6..f79967dce 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java @@ -238,6 +238,11 @@ public class GadgetPage extends ShopPageBase itemLore.add(C.cBlue + "Found in Thankful Treasure"); break; + case CostConstants.FOUND_IN_TRICK_OR_TREAT: + itemLore.add(C.cBlack); + itemLore.add(C.cBlue + "Found in Trick or Treat Treasure"); + break; + // Ranks case CostConstants.UNLOCKED_WITH_ULTRA: itemLore.add(C.cBlack); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/customdata/CorePlayer.java b/Plugins/Mineplex.Core/src/mineplex/core/customdata/CorePlayer.java index 14aaec660..b8ef68149 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/customdata/CorePlayer.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/customdata/CorePlayer.java @@ -2,13 +2,10 @@ package mineplex.core.customdata; import org.bukkit.entity.Player; -/** - * Created by William (WilliamTiger). - * 17/12/15 - */ public class CorePlayer extends MineplexPlayer { - public CorePlayer(Player player, CustomDataManager customDataManager) + + CorePlayer(Player player, CustomDataManager customDataManager) { super(player, customDataManager); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomData.java b/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomData.java index 052965b5c..6a773f9e6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomData.java @@ -1,13 +1,10 @@ package mineplex.core.customdata; -/** - * Created by William (WilliamTiger). - * 16/12/15 - */ public class CustomData { - private int _id; - private String _key; + + private final int _id; + private final String _key; public CustomData(int id, String key) { @@ -24,4 +21,5 @@ public class CustomData { return _key; } + } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomDataManager.java b/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomDataManager.java index 84e958429..353b4f76a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomDataManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomDataManager.java @@ -8,32 +8,33 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniDbClientPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.customdata.repository.CustomDataRepository; -/** - * Created by William (WilliamTiger). - * 16/12/15 - */ +@ReflectivelyCreateMiniPlugin public class CustomDataManager extends MiniDbClientPlugin { - private CustomDataRepository _repository; - public CustomDataManager(JavaPlugin plugin, CoreClientManager clientManager) + private final CustomDataRepository _repository; + + private CustomDataManager() { - super("Custom Data Manager", plugin, clientManager); + super("Custom Data"); - _repository = new CustomDataRepository(plugin, clientManager, this); + _repository = new CustomDataRepository(ClientManager, this); } @Override public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException { PlayerCustomData data = new PlayerCustomData(_repository); + while (resultSet.next()) { data.setData(_repository.getKey(resultSet.getInt("customDataId")), resultSet.getInt("data")); } + Set(uuid, data); } @@ -49,15 +50,16 @@ public class CustomDataManager extends MiniDbClientPlugin return new PlayerCustomData(_repository); } - public void saveAsync(Player player) + void saveAsync(Player player) { final int accountId = getClientManager().getAccountId(player); - final String name = player.getName(); if (accountId == -1) + { return; + } - runAsync(() -> _repository.saveData(name, player.getUniqueId(), accountId)); + runAsync(() -> _repository.saveData(player.getUniqueId(), accountId)); } public CorePlayer getCorePlayer(Player player) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/customdata/MineplexPlayer.java b/Plugins/Mineplex.Core/src/mineplex/core/customdata/MineplexPlayer.java index bf350f843..e8ed94230 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/customdata/MineplexPlayer.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/customdata/MineplexPlayer.java @@ -2,14 +2,11 @@ package mineplex.core.customdata; import org.bukkit.entity.Player; -/** - * Created by William (WilliamTiger). - * 16/12/15 - */ public abstract class MineplexPlayer { - private Player _player; - private CustomDataManager _customDataManager; + + private final Player _player; + private final CustomDataManager _customDataManager; public MineplexPlayer(Player player, CustomDataManager customDataManager) { @@ -31,7 +28,10 @@ public abstract class MineplexPlayer { key = getKeyPrefix() + key; _customDataManager.Get(getPlayer()).setData(key, data); - if (save) _customDataManager.saveAsync(_player); + if (save) + { + _customDataManager.saveAsync(_player); + } } public int get(String key) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/customdata/PlayerCustomData.java b/Plugins/Mineplex.Core/src/mineplex/core/customdata/PlayerCustomData.java index 961d68023..ff9f7c6dc 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/customdata/PlayerCustomData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/customdata/PlayerCustomData.java @@ -1,25 +1,23 @@ package mineplex.core.customdata; import java.util.HashMap; +import java.util.Map; import mineplex.core.customdata.repository.CustomDataRepository; -/** - * Created by William (WilliamTiger). - * 16/12/15 - */ public class PlayerCustomData { - private HashMap _data; - private CustomDataRepository _repository; - public PlayerCustomData(CustomDataRepository repository) + private final Map _data; + private final CustomDataRepository _repository; + + PlayerCustomData(CustomDataRepository repository) { _data = new HashMap<>(); _repository = repository; } - public HashMap getDataMap() + public Map getDataMap() { return _data; } @@ -37,24 +35,20 @@ public class PlayerCustomData return; } - _repository.getClientManager().getScheduler().runTaskAsynchronously( - _repository.getClientManager().getPlugin(), - new Runnable() - { - @Override - public void run() - { - _repository.registerKey(key); // Make sure it's in the DB. + _repository.getCustomDataManager().runAsync(() -> + { + _repository.registerKey(key); // Make sure it's in the DB. - setData(_repository.getKey(key), amount); // Input - } - }); + setData(_repository.getKey(key), amount); // Input + }); } public int getData(String key) { if (_data.containsKey(_repository.getKey(key))) + { return _data.get(_repository.getKey(key)); + } return -1; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/customdata/repository/CustomDataRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/customdata/repository/CustomDataRepository.java index 2a0a1d4be..e586e7d6c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/customdata/repository/CustomDataRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/customdata/repository/CustomDataRepository.java @@ -1,46 +1,40 @@ package mineplex.core.customdata.repository; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.UUID; -import mineplex.core.database.MinecraftRepository; -import org.bukkit.plugin.java.JavaPlugin; - import mineplex.core.account.CoreClientManager; import mineplex.core.customdata.CustomData; import mineplex.core.customdata.CustomDataManager; import mineplex.core.customdata.PlayerCustomData; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.RepositoryBase; -import mineplex.serverdata.database.ResultSetCallable; import mineplex.serverdata.database.column.ColumnInt; import mineplex.serverdata.database.column.ColumnVarChar; -/** - * Created by William (WilliamTiger). - * 16/12/15 - */ public class CustomDataRepository extends RepositoryBase { + private static final String SELECT_KEYS = "SELECT id, name FROM customData;"; private static final String INSERT_KEY = "INSERT INTO customData (name) VALUES (?);"; private static final String UPDATE_DATA = "UPDATE accountCustomData SET data = ? WHERE accountId = ? AND customDataId = ?;"; private static final String INSERT_DATA = "INSERT INTO accountCustomData (accountId, customDataId, data) VALUES (?, ?, ?);"; - private ArrayList _dataKeys; + private final CoreClientManager _clientManager; + private final CustomDataManager _customDataManager; - private CoreClientManager _clientManager; - private CustomDataManager _customDataManager; + private final List _dataKeys; - public CustomDataRepository(JavaPlugin plugin, CoreClientManager clientManager, CustomDataManager customDataManager) + public CustomDataRepository(CoreClientManager clientManager, CustomDataManager customDataManager) { super(DBPool.getAccount()); _clientManager = clientManager; _customDataManager = customDataManager; + + _dataKeys = new ArrayList<>(); } @Override @@ -51,22 +45,18 @@ public class CustomDataRepository extends RepositoryBase private void downloadDataKeys() { - _dataKeys = new ArrayList<>(); - - executeQuery(SELECT_KEYS, new ResultSetCallable() + executeQuery(SELECT_KEYS, resultSet -> { - @Override - public void processResultSet(ResultSet resultSet) throws SQLException + _dataKeys.clear(); + + while (resultSet.next()) { - while (resultSet.next()) - { - _dataKeys.add(new CustomData(resultSet.getInt("id"), resultSet.getString("name"))); - } + _dataKeys.add(new CustomData(resultSet.getInt("id"), resultSet.getString("name"))); } }); } - public void saveData(String name, UUID uuid, int accountId) + public void saveData(UUID uuid, int accountId) { PlayerCustomData data = _customDataManager.Get(uuid); @@ -92,22 +82,23 @@ public class CustomDataRepository extends RepositoryBase public void registerKey(String key) { if (doesKeyExist(key)) + { return; + } executeUpdate(INSERT_KEY, new ColumnVarChar("name", 100, key)); downloadDataKeys(); } - public ArrayList getDataKeys() - { - return _dataKeys; - } - public boolean doesKeyExist(String key) { for (CustomData cur : _dataKeys) + { if (cur.getKey().equals(key)) + { return true; + } + } return false; } @@ -115,8 +106,12 @@ public class CustomDataRepository extends RepositoryBase public CustomData getKey(int id) { for (CustomData cur : _dataKeys) + { if (cur.getId() == id) + { return cur; + } + } return null; } @@ -124,8 +119,12 @@ public class CustomDataRepository extends RepositoryBase public CustomData getKey(String key) { for (CustomData cur : _dataKeys) + { if (cur.getKey().equals(key)) + { return cur; + } + } return null; } @@ -134,4 +133,9 @@ public class CustomDataRepository extends RepositoryBase { return _clientManager; } + + public CustomDataManager getCustomDataManager() + { + return _customDataManager; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java index 754d96365..ecbed339d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java @@ -18,7 +18,6 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.donation.DonationManager; import mineplex.core.facebook.command.FacebookCommand; import mineplex.core.inventory.InventoryManager; -import mineplex.core.treasure.TreasureType; public class FacebookManager extends MiniDbClientPlugin { @@ -85,7 +84,7 @@ public class FacebookManager extends MiniDbClientPlugin boolean completed = _repository.activateCode(code, accountId); if (completed) { - _inventoryManager.addItemToInventory(player, TreasureType.ANCIENT.getItemName(), 10); + //_inventoryManager.addItemToInventory(player, TreasureType.ANCIENT.getItemName(), 10); message(player, "Thanks! You earned " + F.elem("10 Ancient Chests")); player.playSound(player.getLocation(), Sound.NOTE_PIANO, 1f, 1f); //_donationManager.RewardCoinsLater(getName(), player, 20000); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index b5911dd9e..1a5cfaffb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -7,7 +7,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -25,6 +24,7 @@ import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.inventory.ItemStack; import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; @@ -75,6 +75,7 @@ import mineplex.core.gadget.gadgets.death.DeathEmerald; import mineplex.core.gadget.gadgets.death.DeathEnchant; import mineplex.core.gadget.gadgets.death.DeathFreedom; import mineplex.core.gadget.gadgets.death.DeathFrostLord; +import mineplex.core.gadget.gadgets.death.DeathHalloween; import mineplex.core.gadget.gadgets.death.DeathMapleLeaf; import mineplex.core.gadget.gadgets.death.DeathMusic; import mineplex.core.gadget.gadgets.death.DeathPinataBurst; @@ -113,6 +114,7 @@ import mineplex.core.gadget.gadgets.hat.HatItem; import mineplex.core.gadget.gadgets.hat.HatType; import mineplex.core.gadget.gadgets.item.ItemBatGun; import mineplex.core.gadget.gadgets.item.ItemBow; +import mineplex.core.gadget.gadgets.item.ItemCandy; import mineplex.core.gadget.gadgets.item.ItemCoal; import mineplex.core.gadget.gadgets.item.ItemCoinBomb; import mineplex.core.gadget.gadgets.item.ItemDuelingSword; @@ -128,6 +130,7 @@ import mineplex.core.gadget.gadgets.item.ItemPaintbrush; import mineplex.core.gadget.gadgets.item.ItemPartyPopper; import mineplex.core.gadget.gadgets.item.ItemSnowball; import mineplex.core.gadget.gadgets.item.ItemTNT; +import mineplex.core.gadget.gadgets.kitselector.HalloweenKitSelector; import mineplex.core.gadget.gadgets.kitselector.HaloKitSelector; import mineplex.core.gadget.gadgets.kitselector.RainCloudKitSelector; import mineplex.core.gadget.gadgets.kitselector.RainbowDanceKitSelector; @@ -166,7 +169,6 @@ import mineplex.core.gadget.gadgets.morph.MorphVillager; import mineplex.core.gadget.gadgets.morph.MorphWitch; import mineplex.core.gadget.gadgets.morph.MorphWither; import mineplex.core.gadget.gadgets.morph.managers.SoulManager; -import mineplex.core.gadget.gadgets.morph.managers.SwimManager; import mineplex.core.gadget.gadgets.morph.moba.MorphAnath; import mineplex.core.gadget.gadgets.morph.moba.MorphBardolf; import mineplex.core.gadget.gadgets.morph.moba.MorphBiff; @@ -186,6 +188,7 @@ import mineplex.core.gadget.gadgets.mount.types.MountFrost; import mineplex.core.gadget.gadgets.mount.types.MountLoveTrain; import mineplex.core.gadget.gadgets.mount.types.MountMule; import mineplex.core.gadget.gadgets.mount.types.MountNightmareSteed; +import mineplex.core.gadget.gadgets.mount.types.MountPumpkin; import mineplex.core.gadget.gadgets.mount.types.MountSlime; import mineplex.core.gadget.gadgets.mount.types.MountSpider; import mineplex.core.gadget.gadgets.mount.types.MountStPatricksHorse; @@ -225,6 +228,7 @@ import mineplex.core.gadget.gadgets.particle.ParticleHeart; import mineplex.core.gadget.gadgets.particle.ParticleLegend; import mineplex.core.gadget.gadgets.particle.ParticleMusic; import mineplex.core.gadget.gadgets.particle.ParticlePartyTime; +import mineplex.core.gadget.gadgets.particle.ParticleHalloween; import mineplex.core.gadget.gadgets.particle.ParticleRain; import mineplex.core.gadget.gadgets.particle.ParticleTitan; import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel; @@ -244,6 +248,7 @@ import mineplex.core.gadget.gadgets.particle.king.ParticleKing; import mineplex.core.gadget.gadgets.particle.spring.ParticleSpringHalo; import mineplex.core.gadget.gadgets.taunts.BlowAKissTaunt; import mineplex.core.gadget.gadgets.taunts.EternalTaunt; +import mineplex.core.gadget.gadgets.taunts.InfernalTaunt; import mineplex.core.gadget.gadgets.taunts.RainbowTaunt; import mineplex.core.gadget.gadgets.wineffect.WinEffectBabyChicken; import mineplex.core.gadget.gadgets.wineffect.WinEffectFlames; @@ -269,6 +274,7 @@ import mineplex.core.gadget.set.SetCupidsLove; import mineplex.core.gadget.set.SetEmerald; import mineplex.core.gadget.set.SetFreedom; import mineplex.core.gadget.set.SetFrostLord; +import mineplex.core.gadget.set.SetHalloween; import mineplex.core.gadget.set.SetHowlingWinds; import mineplex.core.gadget.set.SetMusic; import mineplex.core.gadget.set.SetParty; @@ -310,8 +316,8 @@ import mineplex.core.pet.PetManager; import mineplex.core.pet.custom.CustomPet; import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; -import mineplex.core.treasure.TreasureManager; +@ReflectivelyCreateMiniPlugin public class GadgetManager extends MiniPlugin { @@ -350,7 +356,6 @@ public class GadgetManager extends MiniPlugin private final OutfitWindUpSuitBoosterManager _boosterManager; private final IncognitoManager _incognitoManager; private final GameCosmeticManager _gameCosmeticManager; - private TreasureManager _treasureManager; private SoulManager _soulManager; private CastleManager _castleManager; @@ -361,7 +366,7 @@ public class GadgetManager extends MiniPlugin private final Map _lastMove = new HashMap<>(); private final Map> _playerActiveGadgetMap = new HashMap<>(); - private final HashSet _sets = new HashSet<>(); + private final Set _sets = new HashSet<>(); private UserGadgetPersistence _userGadgetPersistence; @@ -369,32 +374,30 @@ public class GadgetManager extends MiniPlugin private int _activeItemSlot = 3; private boolean _gadgetsEnabled = true; - private Set _gadgetCollideWhitelist = new HashSet<>(); + private final Set _gadgetCollideWhitelist = new HashSet<>(); + private final Set _swimmingPlayers = new HashSet<>(); - public GadgetManager(CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, - PetManager petManager, PreferencesManager preferencesManager, DisguiseManager disguiseManager, - BlockRestore blockRestore, ProjectileManager projectileManager, AchievementManager achievementManager, - PacketHandler packetHandler, HologramManager hologramManager, IncognitoManager incognitoManager, CastleManager castleManager) + private GadgetManager() { super("Gadget"); - _clientManager = clientManager; - _donationManager = donationManager; - _inventoryManager = inventoryManager; - _petManager = petManager; - _preferencesManager = preferencesManager; - _disguiseManager = disguiseManager; - _blockRestore = blockRestore; - _projectileManager = projectileManager; - _achievementManager = achievementManager; - _packetManager = packetHandler; - _hologramManager = hologramManager; + _clientManager = require(CoreClientManager.class); + _donationManager = require(DonationManager.class); + _inventoryManager = require(InventoryManager.class); + _petManager = require(PetManager.class); + _preferencesManager = require(PreferencesManager.class); + _disguiseManager = require(DisguiseManager.class); + _blockRestore = require(BlockRestore.class); + _projectileManager = require(ProjectileManager.class); + _achievementManager = require(AchievementManager.class); + _packetManager = require(PacketHandler.class); + _hologramManager = require(HologramManager.class); _userGadgetPersistence = new UserGadgetPersistence(this); _boosterManager = new OutfitWindUpSuitBoosterManager(this); - _incognitoManager = incognitoManager; + _incognitoManager = require(IncognitoManager.class); _gameCosmeticManager = require(GameCosmeticManager.class); _soulManager = new SoulManager(); - _castleManager = castleManager; + _castleManager = require(CastleManager.class); createGadgets(); createSets(); @@ -466,6 +469,7 @@ public class GadgetManager extends MiniPlugin addSet(new SetFreedom(this)); addSet(new SetSpring(this)); addSet(new SetCanadian(this)); + addSet(new SetHalloween(this)); } private void createGadgets() @@ -492,6 +496,7 @@ public class GadgetManager extends MiniPlugin addGadget(new ItemBow(this)); addGadget(new ItemLovePotion(this)); addGadget(new ItemFlowerGift(this)); + addGadget(new ItemCandy(this)); // Costume addGadget(new OutfitRaveSuitHelmet(this)); @@ -587,6 +592,7 @@ public class GadgetManager extends MiniPlugin addGadget(new MountCake(this)); addGadget(new MountLoveTrain(this)); addGadget(new MountStPatricksHorse(this)); + addGadget(new MountPumpkin(this)); // Particles addGadget(new ParticleFoot(this)); @@ -624,7 +630,7 @@ public class GadgetManager extends MiniPlugin addGadget(new ParticleAuraNiceness(this)); addGadget(new ParticleCanadian(this)); - //addGadget(new ParticlePulse(this)); + addGadget(new ParticleHalloween(this)); // Arrow Trails @@ -660,6 +666,7 @@ public class GadgetManager extends MiniPlugin addGadget(new DeathPresentDanger(this)); addGadget(new DeathSpring(this)); addGadget(new DeathMapleLeaf(this)); + addGadget(new DeathHalloween(this)); // Double Jump addGadget(new DoubleJumpFrostLord(this)); @@ -730,6 +737,7 @@ public class GadgetManager extends MiniPlugin addGadget(new EternalTaunt(this)); addGadget(new BlowAKissTaunt(this)); addGadget(new RainbowTaunt(this)); + addGadget(new InfernalTaunt(this)); // Flags addGadget(new FlagGadget(this, FlagType.CANADA)); @@ -742,6 +750,7 @@ public class GadgetManager extends MiniPlugin addGadget(new RainbowDanceKitSelector(this)); addGadget(new RainCloudKitSelector(this)); addGadget(new ShimmeringRingKitSelector(this)); + addGadget(new HalloweenKitSelector(this)); for (SingleParticleKitSelector.SingleParticleSelectors singleParticleSelectors : SingleParticleKitSelector.SingleParticleSelectors.values()) { @@ -1510,44 +1519,13 @@ public class GadgetManager extends MiniPlugin @EventHandler public void checkPlayerSwim(PlayerMoveEvent event) { - Material material = event.getPlayer().getLocation().getBlock().getType(); - UUID uuid = event.getPlayer().getUniqueId(); - if (material == Material.WATER || material == Material.STATIONARY_WATER) - { - if (!SwimManager.isSwimming(uuid)) - { - SwimManager.addPlayer(uuid); - SwimManager.removePlayerLava(uuid); - Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), true, false)); - } - } - else if (material == Material.LAVA || material == Material.STATIONARY_LAVA) - { - if (!SwimManager.isInLava(uuid)) - { - SwimManager.addPlayerLava(uuid); - SwimManager.removePlayer(uuid); - Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), true, false)); - } - } - else - { - if (SwimManager.isSwimming(uuid) || SwimManager.isInLava(uuid)) - { - SwimManager.removeLavaAndWater(uuid); - Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), false, false)); - } - } - } + Player player = event.getPlayer(); + boolean inWater = UtilEnt.isInWater(player); - public void setTreasureManager(TreasureManager treasureManager) - { - _treasureManager = treasureManager; - } - - public TreasureManager getTreasureManager() - { - return _treasureManager; + if (inWater && _swimmingPlayers.add(player) || !inWater && _swimmingPlayers.remove(player)) + { + UtilServer.CallEvent(new PlayerToggleSwimEvent(player, inWater)); + } } public SoulManager getSoulManager() @@ -1555,11 +1533,6 @@ public class GadgetManager extends MiniPlugin return _soulManager; } - /** - * Handles taunt commands - * - * @param event - */ @EventHandler public void onTauntCommand(TauntCommandEvent event) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/PlayerToggleSwimEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/PlayerToggleSwimEvent.java index 49803ac80..2d5c5f00b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/PlayerToggleSwimEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/PlayerToggleSwimEvent.java @@ -10,9 +10,9 @@ public class PlayerToggleSwimEvent extends Event private static final HandlerList handlers = new HandlerList(); private Player _player; - private boolean _swimming, _lava; + private boolean _swimming; - public PlayerToggleSwimEvent(Player player, boolean swimming, boolean lava) + public PlayerToggleSwimEvent(Player player, boolean swimming) { _player = player; _swimming = swimming; @@ -28,11 +28,6 @@ public class PlayerToggleSwimEvent extends Event return _swimming; } - public boolean isInLava() - { - return _lava; - } - public HandlerList getHandlers() { return handlers; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/arrowtrail/ArrowTrailFreedom.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/arrowtrail/ArrowTrailFreedom.java index fa5f7ade2..d123091b7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/arrowtrail/ArrowTrailFreedom.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/arrowtrail/ArrowTrailFreedom.java @@ -58,7 +58,7 @@ public class ArrowTrailFreedom extends ArrowEffectGadget @Override public void doHitEffect(Arrow arrow) { - BabyFireworkEffect babyFireworkEffect = new BabyFireworkEffect(arrow.getLocation(), Manager.getPlugin(), _color); + BabyFireworkEffect babyFireworkEffect = new BabyFireworkEffect(arrow.getLocation(), _color); babyFireworkEffect.start(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/death/DeathHalloween.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/death/DeathHalloween.java new file mode 100644 index 000000000..37215988d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/death/DeathHalloween.java @@ -0,0 +1,35 @@ +package mineplex.core.gadget.gadgets.death; + +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import mineplex.core.blood.BloodEvent; +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilText; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.types.DeathEffectGadget; +import mineplex.core.gadget.util.CostConstants; + +public class DeathHalloween extends DeathEffectGadget +{ + + public DeathHalloween(GadgetManager manager) + { + super(manager, "Spooky Death", + UtilText.splitLineToArray(C.cGray + "Explode in a flurry of fright.", LineFormat.LORE), + CostConstants.FOUND_IN_TRICK_OR_TREAT, Material.PUMPKIN, (byte) 0); + } + + @Override + public void onBlood(Player player, BloodEvent event) + { + event.setItem(Material.PUMPKIN, (byte) 0); + UtilParticle.PlayParticleToAll(ParticleType.FLAME, player.getLocation().add(0, 1.1, 0), 0.4F, 0.4F, 0.4F, 0.1F, 30, ViewDist.LONG); + } + + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/emblems/EmblemType.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/emblems/EmblemType.java index c3aad1965..f85611b9b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/emblems/EmblemType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/emblems/EmblemType.java @@ -2,7 +2,7 @@ package mineplex.core.gadget.gadgets.gamemodifiers.moba.emblems; import org.bukkit.Material; -import mineplex.core.reward.RewardRarity; +import mineplex.core.treasure.reward.RewardRarity; public enum EmblemType { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/shopmorph/ShopMorphType.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/shopmorph/ShopMorphType.java index 5bd271ed7..8254ac23d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/shopmorph/ShopMorphType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/shopmorph/ShopMorphType.java @@ -25,7 +25,7 @@ import mineplex.core.disguise.disguises.DisguiseSnowman; import mineplex.core.disguise.disguises.DisguiseSpider; import mineplex.core.disguise.disguises.DisguiseWitch; import mineplex.core.disguise.disguises.DisguiseZombie; -import mineplex.core.reward.RewardRarity; +import mineplex.core.treasure.reward.RewardRarity; public enum ShopMorphType { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/skins/HeroSkinGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/skins/HeroSkinGadget.java index 2602d8ebb..c624427b2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/skins/HeroSkinGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/skins/HeroSkinGadget.java @@ -19,7 +19,7 @@ import mineplex.core.gadget.types.GameModifierGadget; import mineplex.core.gadget.util.CostConstants; import mineplex.core.game.GameDisplay; import mineplex.core.google.GoogleSheetsManager; -import mineplex.core.reward.RewardRarity; +import mineplex.core.treasure.reward.RewardRarity; public class HeroSkinGadget extends GameModifierGadget { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/skins/HeroSkinGadgetData.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/skins/HeroSkinGadgetData.java index eb7df252a..3bbfd13a6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/skins/HeroSkinGadgetData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/moba/skins/HeroSkinGadgetData.java @@ -1,8 +1,7 @@ package mineplex.core.gadget.gadgets.gamemodifiers.moba.skins; import mineplex.core.common.skin.SkinData; -import mineplex.core.gadget.gadgets.gamemodifiers.moba.skins.HeroSkinGadget; -import mineplex.core.reward.RewardRarity; +import mineplex.core.treasure.reward.RewardRarity; public class HeroSkinGadgetData { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCandy.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCandy.java new file mode 100644 index 000000000..5f9ed0706 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCandy.java @@ -0,0 +1,55 @@ +package mineplex.core.gadget.gadgets.item; + +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.entity.Snowball; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.NautHashMap; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilText; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.gadgets.Ammo; +import mineplex.core.gadget.types.ItemGadget; +import mineplex.core.gadget.util.CostConstants; + +public class ItemCandy extends ItemGadget +{ + + private static final PotionEffectType[] POTION_EFFECTS = { + PotionEffectType.SPEED, + PotionEffectType.JUMP, + }; + + public ItemCandy(GadgetManager manager) + { + super(manager, "Halloween Candy", + UtilText.splitLineToArray(C.cWhite + "Get some serious sugar rush", LineFormat.LORE), + CostConstants.FOUND_IN_TRICK_OR_TREAT, Material.COOKIE, (byte) 0, 2000, new Ammo("Halloween Candy", "1 Halloween Candy", Material.COOKIE, (byte) 0, new String[] + { + } + , CostConstants.FOUND_IN_TRICK_OR_TREAT, 1)); + } + + @Override + public void ActivateCustom(Player player) + { + player.sendMessage(F.main(Manager.getName(), "Sugar Rush!!!")); + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1); + + PotionEffectType effectType = UtilMath.randomElement(POTION_EFFECTS); + + if (effectType == null) + { + return; + } + + player.removePotionEffect(effectType); + player.addPotionEffect(new PotionEffect(effectType, 10 * 20, 5 + UtilMath.r(5))); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCoal.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCoal.java index 118f1b8b9..87a6f263b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCoal.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCoal.java @@ -3,7 +3,6 @@ package mineplex.core.gadget.gadgets.item; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; @@ -34,8 +33,8 @@ import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.pet.PetType; import mineplex.core.recharge.Recharge; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; import mineplex.core.reward.rewards.PetReward; +import mineplex.core.treasure.reward.RewardRarity; public class ItemCoal extends ItemGadget { @@ -132,13 +131,10 @@ public class ItemCoal extends ItemGadget Recharge.Instance.use(player, getName(), 30000, true, true); PetReward reward = new PetReward( - Manager.getPetManager(), - Manager.getInventoryManager(), - Manager.getDonationManager(), - "Coal Apparition", "Coal Apparition", PetType.PIG_ZOMBIE, RewardRarity.OTHER, 0, 0); + "Coal Apparition", PetType.PIG_ZOMBIE, RewardRarity.LEGENDARY, 0); if (reward.canGiveReward(player)) - reward.giveReward(null, player, new Callback() + reward.giveReward(player, new Callback() { @Override public void run(RewardData data) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/kitselector/HalloweenKitSelector.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/kitselector/HalloweenKitSelector.java new file mode 100644 index 000000000..cd837ec40 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/kitselector/HalloweenKitSelector.java @@ -0,0 +1,46 @@ +package mineplex.core.gadget.gadgets.kitselector; + +import java.awt.*; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.particles.ColoredParticle; +import mineplex.core.common.util.particles.DustSpellColor; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.types.KitSelectorGadget; + +public class HalloweenKitSelector extends KitSelectorGadget +{ + + private static final DustSpellColor COLOR_A = new DustSpellColor(Color.ORANGE); + private static final DustSpellColor COLOR_B = new DustSpellColor(Color.BLACK); + + public HalloweenKitSelector(GadgetManager manager) + { + super(manager, "Haunted Kit", UtilText.splitLinesToArray(new String[]{C.cGray + "Are you scared?"}, LineFormat.LORE), + 0, Material.PUMPKIN, (byte) 0); + } + + + @Override + public void playParticle(Entity entity, Player playTo) + { + Location location = entity.getLocation().add(0, 1.1, 0); + + new ColoredParticle(ParticleType.RED_DUST, COLOR_A, UtilAlg.getRandomLocation(location, 1)) + .display(ViewDist.NORMAL, playTo); + new ColoredParticle(ParticleType.RED_DUST, COLOR_B, UtilAlg.getRandomLocation(location, 1)) + .display(ViewDist.NORMAL, playTo); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/kitselector/SingleParticleKitSelector.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/kitselector/SingleParticleKitSelector.java index a2ec8e93b..35e503c22 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/kitselector/SingleParticleKitSelector.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/kitselector/SingleParticleKitSelector.java @@ -38,7 +38,8 @@ public class SingleParticleKitSelector extends KitSelectorGadget EMBER("Ember", UtilText.splitLinesToArray(new String[]{C.cGray + "I'd like my kit well done."}, LineFormat.LORE), 0, Material.COAL, (byte) 0, UtilParticle.ParticleType.SMOKE, 3), LOVE("Kit Love", UtilText.splitLinesToArray(new String[]{C.cGray + "I think I LIKE this kit, if you know what I mean."}, LineFormat.LORE), - 0, Material.POTION, (byte) 8233, UtilParticle.ParticleType.HEART); + 0, Material.POTION, (byte) 8233, UtilParticle.ParticleType.HEART), + ; private String _name; private String[] _lore; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSquid.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSquid.java index 1cb807f6e..b164fdfa1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSquid.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphSquid.java @@ -24,7 +24,6 @@ import mineplex.core.common.util.UtilText; import mineplex.core.disguise.disguises.DisguiseSquid; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.event.PlayerToggleSwimEvent; -import mineplex.core.gadget.gadgets.morph.managers.SwimManager; import mineplex.core.gadget.gadgets.morph.managers.UtilMorph; import mineplex.core.gadget.types.MorphGadget; import mineplex.core.gadget.types.OutfitGadget; @@ -57,7 +56,6 @@ public class MorphSquid extends MorphGadget implements IThrown applyArmor(player, message); DisguiseSquid disguiseSquid = new DisguiseSquid(player); UtilMorph.disguise(player, disguiseSquid, Manager); - onToggleSwim(new PlayerToggleSwimEvent(player, SwimManager.isSwimming(player.getUniqueId()), SwimManager.isInLava(player.getUniqueId()))); } @Override @@ -92,7 +90,9 @@ public class MorphSquid extends MorphGadget implements IThrown public void onToggleSwim(PlayerToggleSwimEvent event) { if (!isActive(event.getPlayer())) + { return; + } if (event.isSwimming()) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphWitch.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphWitch.java index ddcdbb9ed..93555c66b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphWitch.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphWitch.java @@ -102,23 +102,23 @@ public class MorphWitch extends MorphGadget return; } - // Checks if player is opening a treasure chest/close to a treasure area - if (Manager.getTreasureManager() != null) - { - if (Manager.getTreasureManager().isOpening(event.getPlayer())) - { - UtilPlayer.message(event.getPlayer(), F.main("Witch Morph", "You can't place the cauldron there!")); - return; - } - for (Location blockLocation : Manager.getTreasureManager().getBlockLocations()) - { - if (blockLocation.distanceSquared(cauldronLocation) <= 25) - { - UtilPlayer.message(event.getPlayer(), F.main("Witch Morph", "You can't place the cauldron there!")); - return; - } - } - } +// // Checks if player is opening a treasure chest/close to a treasure area +// if (Manager.getTreasureManager() != null) +// { +// if (Manager.getTreasureManager().isOpening(event.getPlayer())) +// { +// UtilPlayer.message(event.getPlayer(), F.main("Witch Morph", "You can't place the cauldron there!")); +// return; +// } +// for (Location blockLocation : Manager.getTreasureManager().getBlockLocations()) +// { +// if (blockLocation.distanceSquared(cauldronLocation) <= 25) +// { +// UtilPlayer.message(event.getPlayer(), F.main("Witch Morph", "You can't place the cauldron there!")); +// return; +// } +// } +// } // Checks if the player is close to a cactus for (int x = -3; x < 3; x++) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/WitchEffectManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/WitchEffectManager.java index a30b400fe..98b06e6d1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/WitchEffectManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/WitchEffectManager.java @@ -41,7 +41,7 @@ public class WitchEffectManager bat.setCustomNameVisible(true); _bat = bat; - _witchParticleEffect = new WitchParticleEffect(_location, UtilServer.getPlugin()); + _witchParticleEffect = new WitchParticleEffect(_location); _witchParticleEffect.start(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/SwimManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/SwimManager.java deleted file mode 100644 index ab526bad0..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/SwimManager.java +++ /dev/null @@ -1,55 +0,0 @@ -package mineplex.core.gadget.gadgets.morph.managers; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class SwimManager -{ - - private static List _swimming = new ArrayList<>(); - private static List _lava = new ArrayList<>(); - - public static void addPlayer(UUID uuid) - { - _swimming.add(uuid); - } - - public static void removePlayer(UUID uuid) - { - if (_swimming.contains(uuid)) - { - _swimming.remove(uuid); - } - } - - public static void addPlayerLava(UUID uuid) - { - _lava.add(uuid); - } - - public static void removePlayerLava(UUID uuid) - { - if (_lava.contains(uuid)) - { - _lava.remove(uuid); - } - } - - public static void removeLavaAndWater(UUID uuid) - { - removePlayerLava(uuid); - removePlayer(uuid); - } - - public static boolean isSwimming(UUID uuid) - { - return _swimming.contains(uuid); - } - - public static boolean isInLava(UUID uuid) - { - return _lava.contains(uuid); - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/moba/MorphAnath.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/moba/MorphAnath.java index a5769707c..8316ea408 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/moba/MorphAnath.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/moba/MorphAnath.java @@ -183,7 +183,7 @@ public class MorphAnath extends MorphGadget Block block = player.getLocation().getBlock(); - while (!UtilBlock.solid(block)) + while (!UtilBlock.solid(block) && block.getLocation().getBlockY() > 10) { block = block.getRelative(BlockFace.DOWN); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountBabyReindeer.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountBabyReindeer.java index c6bcbb631..ca47010c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountBabyReindeer.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountBabyReindeer.java @@ -57,12 +57,6 @@ public class MountBabyReindeer extends HorseMount return data; } - @Override - protected boolean shouldRide(Player player, SingleEntityMountData data, boolean head) - { - return data.ownsMount(player); - } - @EventHandler public void fly(UpdateEvent event) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountFreedomHorse.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountFreedomHorse.java index b3c4484b2..28b685515 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountFreedomHorse.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountFreedomHorse.java @@ -52,7 +52,7 @@ public class MountFreedomHorse extends HorseMount data.getEntity().getInventory().setArmor(new ItemStack(Material.DIAMOND_BARDING)); - FreedomTrailEffect effect = new FreedomTrailEffect(horse, Manager.getPlugin()); + FreedomTrailEffect effect = new FreedomTrailEffect(horse); effect.start(); _trailMap.put(data, effect); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountPumpkin.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountPumpkin.java new file mode 100644 index 000000000..e5b14786c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountPumpkin.java @@ -0,0 +1,119 @@ +package mineplex.core.gadget.gadgets.mount.types; + +import java.util.HashSet; +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilText; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.gadgets.mount.Mount; +import mineplex.core.gadget.gadgets.mount.SingleEntityMountData; +import mineplex.core.gadget.util.CostConstants; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class MountPumpkin extends Mount +{ + + private static final ItemStack HELMET = new ItemStack(Material.JACK_O_LANTERN); + + public MountPumpkin(GadgetManager manager) + { + super(manager, + "Pumpkin Mount", + UtilText.splitLinesToArray(new String[] + { + C.cGray + "One of the Pumpkin King's flying minions.", + "", + C.cBlue + "Earned by defeating the Pumpkin King", + C.cBlue + "in the 2017 Halloween Horror Event." + }, LineFormat.LORE), + CostConstants.NO_LORE, + Material.JACK_O_LANTERN, + (byte) 0 + ); + } + + @Override + public SingleEntityMountData spawnMount(Player player) + { + ArmorStand stand = player.getWorld().spawn(player.getLocation(), ArmorStand.class); + + stand.setCustomName(player.getName() + "'s Pumpkin Mount"); + stand.setGravity(false); + stand.setVisible(false); + stand.setHelmet(HELMET); + stand.setPassenger(player); + stand.getWorld().playSound(stand.getLocation(), Sound.FIZZ, 1, 0.8F); + + return new SingleEntityMountData<>(player, stand); + } + + @EventHandler + public void updateLocation(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + Set toRemove = new HashSet<>(); + + for (Player player : getActiveMounts().keySet()) + { + SingleEntityMountData data = getActiveMounts().get(player); + + if (data == null) + { + toRemove.add(player); + continue; + } + + if (!data.getEntity().isValid() || data.getEntity().getPassenger() == null) + { + data.getEntity().remove(); + toRemove.add(player); + continue; + } + + Location playerLocation = player.getLocation(); + Location location = data.getEntity().getLocation().add(playerLocation.getDirection()); + ((CraftEntity) data.getEntity()).getHandle().setPositionRotation(location.getX(), location.getY(), location.getZ(), playerLocation.getYaw(), playerLocation.getPitch()); + } + + for (Player player : toRemove) + { + disable(player); + } + } + + @EventHandler + public void updateParticles(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + for (Player player : getActiveMounts().keySet()) + { + Entity entity = getActiveMounts().get(player).getEntity(); + + UtilParticle.PlayParticleToAll(ParticleType.FLAME, entity.getLocation().add(0, 1.4, 0), 0.2F, 0.2F, 0.2F, 0.05F, 4, ViewDist.NORMAL); + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountSpider.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountSpider.java index e2e218efb..076a47942 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountSpider.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountSpider.java @@ -111,7 +111,7 @@ public class MountSpider extends HorseMount Player player = entry.getKey(); Horse horse = entry.getValue().getEntity(); - if (!horse.getPassenger().equals(player)) + if (horse.getPassenger() == null || !horse.getPassenger().equals(player)) { continue; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountStPatricksHorse.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountStPatricksHorse.java index 77fd64941..b4f04619c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountStPatricksHorse.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/mount/types/MountStPatricksHorse.java @@ -56,7 +56,7 @@ public class MountStPatricksHorse extends HorseMount SingleEntityMountData data = super.spawnMount(player); Horse horse = data.getEntity(); - RainbowTrailEffect effect = new RainbowTrailEffect(horse, Manager.getPlugin(), _items); + RainbowTrailEffect effect = new RainbowTrailEffect(horse, _items); effect.start(); _trailMap.put(data, effect); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/freezesuit/OutfitFreezeSuit.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/freezesuit/OutfitFreezeSuit.java index 0cba46733..3e8e9e88f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/freezesuit/OutfitFreezeSuit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/freezesuit/OutfitFreezeSuit.java @@ -9,7 +9,6 @@ import java.util.UUID; import org.bukkit.Color; import org.bukkit.Effect; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -126,29 +125,29 @@ public class OutfitFreezeSuit extends OutfitGadget Map blocks = UtilBlock.getInRadius(player.getLocation(), RANGE); - boolean setBlocks = true, forceBreak = false; + //boolean setBlocks = true, forceBreak = false; for (Block block : blocks.keySet()) { - if (Manager.getTreasureManager() != null) - { - if (Manager.getTreasureManager().isOpening(player)) - { - forceBreak= true; - } - for (Location blockLocation : Manager.getTreasureManager().getBlockLocations()) - { - if (blockLocation.distanceSquared(block.getLocation()) <= 25) - { - setBlocks = false; - } - } - } - if (forceBreak) - break; - - if (!setBlocks) - continue; +// if (Manager.getTreasureManager() != null) +// { +// if (Manager.getTreasureManager().isOpening(player)) +// { +// forceBreak= true; +// } +// for (Location blockLocation : Manager.getTreasureManager().getBlockLocations()) +// { +// if (blockLocation.distanceSquared(block.getLocation()) <= 25) +// { +// setBlocks = false; +// } +// } +// } +// if (forceBreak) +// break; +// +// if (!setBlocks) +// continue; Manager.getBlockRestore().snow(block, (byte) 1, (byte) 1, (int) (DURATION * (1 + blocks.get(block))), 250, 0); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleChristmasTree.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleChristmasTree.java index 8261df65c..8bd689c89 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleChristmasTree.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleChristmasTree.java @@ -38,7 +38,7 @@ public class ParticleChristmasTree extends ParticleGadget { if (!_effects.containsKey(player.getUniqueId())) { - ChristmasTreeEffect christmasTreeEffect = new ChristmasTreeEffect(Manager.getPlugin(), player, Manager); + ChristmasTreeEffect christmasTreeEffect = new ChristmasTreeEffect(player, Manager); christmasTreeEffect.start(); _effects.put(player.getUniqueId(), christmasTreeEffect); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticlePulse.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleHalloween.java similarity index 89% rename from Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticlePulse.java rename to Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleHalloween.java index 2d6c732e9..85495f329 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticlePulse.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleHalloween.java @@ -18,10 +18,11 @@ import mineplex.core.common.util.particles.ColoredParticle; import mineplex.core.common.util.particles.DustSpellColor; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.types.ParticleGadget; +import mineplex.core.gadget.util.CostConstants; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -public class ParticlePulse extends ParticleGadget +public class ParticleHalloween extends ParticleGadget { private static final int ARRAY_SIZE = 300; @@ -36,11 +37,11 @@ public class ParticlePulse extends ParticleGadget private int[] _nextIndexes; private int _index, _inIndex; - public ParticlePulse(GadgetManager manager) + public ParticleHalloween(GadgetManager manager) { - super(manager, "Lotus", UtilText - .splitLineToArray(C.cGray + "I need healing. Mada mada", LineFormat.LORE), -2, - Material.INK_SACK, (byte) 10); + super(manager, "Halloween Aura", UtilText + .splitLineToArray(C.cGray + "Scary Skeletons", LineFormat.LORE), CostConstants.FOUND_IN_TRICK_OR_TREAT, + Material.PUMPKIN, (byte) 0); _nextIndexes = new int[INDEXES_PER_ITERATION]; _x = new ArrayList<>(ARRAY_SIZE); @@ -82,7 +83,7 @@ public class ParticlePulse extends ParticleGadget public void playParticle(Player player, UpdateEvent event) { Location location = player.getLocation().add(0, 0.3, 0); - DustSpellColor color = new DustSpellColor(_index < _inIndex ? Color.MAGENTA : Color.CYAN); + DustSpellColor color = new DustSpellColor(_index < _inIndex ? Color.BLACK : Color.ORANGE); if (Manager.isMoving(player)) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleRain.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleRain.java index 4311666c0..b9861e992 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleRain.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleRain.java @@ -1,8 +1,5 @@ package mineplex.core.gadget.gadgets.particle; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -13,7 +10,6 @@ import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.types.ParticleGadget; @@ -43,10 +39,6 @@ public class ParticleRain extends ParticleGadget { Location loc = player.getLocation().add(0, 3.5, 0); UtilParticle.PlayParticle(ParticleType.EXPLODE, loc, 0.6f, 0f, 0.6f, 0, 8, ViewDist.NORMAL, player); - - List others = new ArrayList(); - others.addAll(UtilServer.getPlayersCollection()); - others.remove(player); UtilParticle.PlayParticle(ParticleType.CLOUD, loc, 0.6f, 0.1f, 0.6f, 0, 8, ViewDist.NORMAL); UtilParticle.playParticleFor(player, ParticleType.DRIP_WATER, loc, 0.4f, 0.1f, 0.4f, 0, 2, ViewDist.NORMAL); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/freedom/ParticleFreedom.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/freedom/ParticleFreedom.java index bafa31183..9382136f5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/freedom/ParticleFreedom.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/freedom/ParticleFreedom.java @@ -38,7 +38,7 @@ public class ParticleFreedom extends ParticleGadget @Override public void startEffect(Player player) { - _effects.put(player.getUniqueId(), new FreedomFireworkEffect(player, Manager.getPlugin(), true)); + _effects.put(player.getUniqueId(), new FreedomFireworkEffect(player, true)); _effects.get(player.getUniqueId()).start(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java index cab1f0ac1..f9afe33c0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java @@ -50,7 +50,7 @@ public class ParticleSpringHalo extends ParticleGadget super.enableCustom(player, message); Manager.removeGadgetType(player, GadgetType.MORPH, this); Manager.removeOutfit(player, OutfitGadget.ArmorSlot.HELMET); - ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false); + ColoredCircleEffect circleEffect = new ColoredCircleEffect(player, 0.7d, false); RGBData colorA = UtilColor.hexToRgb(0x5a92ed); RGBData colorB = UtilColor.hexToRgb(0xdb5aed); RGBData colorC = UtilColor.hexToRgb(0xd2cdf2); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/BlowAKissTaunt.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/BlowAKissTaunt.java index c246b2975..bff6daafa 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/BlowAKissTaunt.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/BlowAKissTaunt.java @@ -46,7 +46,7 @@ public class BlowAKissTaunt extends TauntGadget ignore.add(Material.AIR); Location loc = player.getTargetBlock(ignore, 64).getLocation().add(0.5, 0.5, 0.5); - BlowAKissEffect blowAKissEffect = new BlowAKissEffect(player, loc, this); + BlowAKissEffect blowAKissEffect = new BlowAKissEffect(player, loc); blowAKissEffect.start(); return true; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/EternalTaunt.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/EternalTaunt.java index 84cd12c94..e41f5ff49 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/EternalTaunt.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/EternalTaunt.java @@ -11,11 +11,11 @@ import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.util.Vector; import mineplex.core.common.util.C; @@ -99,6 +99,7 @@ public class EternalTaunt extends TauntGadget Item clock = player.getWorld().dropItem(player.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.WATCH, (byte) 0, 1, " " + i)); + clock.setPickupDelay(Integer.MAX_VALUE); enableArcadeSpawnEvent = new EnableArcadeSpawnEvent(false); Bukkit.getPluginManager().callEvent(enableArcadeSpawnEvent); @@ -128,15 +129,16 @@ public class EternalTaunt extends TauntGadget @Override public void onFinish(Player player) { - if (_disguises.containsKey(player.getUniqueId())) + DisguiseBase disguise = _disguises.remove(player.getUniqueId()); + + if (disguise != null) { - Manager.getDisguiseManager().undisguise(_disguises.remove(player.getUniqueId())); + Manager.getDisguiseManager().undisguise(disguise); } if (_clocks.containsKey(player.getUniqueId())) { - _clocks.get(player.getUniqueId()).forEach(c -> c.remove()); - _clocks.get(player.getUniqueId()).clear(); + _clocks.get(player.getUniqueId()).forEach(Entity::remove); _clocks.remove(player.getUniqueId()); } } @@ -149,19 +151,4 @@ public class EternalTaunt extends TauntGadget Manager.getDonationManager().Get(event.getPlayer()).addOwnedUnknownSalesPackage(getName()); } } - - @EventHandler - public void onClockPickup(PlayerPickupItemEvent event) - { - for (List clocks : _clocks.values()) - { - for (Item item : clocks) - { - if (event.getItem().equals(item)) - { - event.setCancelled(true); - } - } - } - } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/InfernalTaunt.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/InfernalTaunt.java new file mode 100644 index 000000000..f380a1d57 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/InfernalTaunt.java @@ -0,0 +1,97 @@ +package mineplex.core.gadget.gadgets.taunts; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.entity.Skeleton.SkeletonType; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.disguise.disguises.DisguiseBase; +import mineplex.core.disguise.disguises.DisguiseSkeleton; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.types.TauntGadget; +import mineplex.core.gadget.util.CostConstants; +import mineplex.core.game.GameDisplay; +import mineplex.core.particleeffects.TextEffect; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; + +public class InfernalTaunt extends TauntGadget +{ + + private static final int COOLDOWN = 60000; + private static final int PVP_COOLDOWN = 10000; + + private final Map _disguises = new HashMap<>(); + + public InfernalTaunt(GadgetManager manager) + { + super(manager, "Infernal Taunt", new String[] + { + C.cGray + "Shows everyone your name in", + C.cGray + "burning text!", + "", + C.cWhite + "Use /taunt in game to use this taunt.", + C.cRed + "Cannot be used while in PvP!" + }, CostConstants.FOUND_IN_TRICK_OR_TREAT, Material.SKULL_ITEM, (byte) 1); + + setCanPlayWithPvp(false); + setPvpCooldown(PVP_COOLDOWN); + setShouldPlay(true); + setEventType(UpdateType.FASTER); + addDisabledGames(GameDisplay.Smash, GameDisplay.SmashTeams, GameDisplay.SmashDomination, GameDisplay.SmashTraining); + } + + @Override + public boolean onStart(Player player) + { + if (!Recharge.Instance.use(player, getName(), COOLDOWN, true, false, "Cosmetics")) + { + return false; + } + + player.getWorld().strikeLightningEffect(player.getLocation()); + Bukkit.broadcastMessage(F.main("Taunt", F.name(player.getName()) + " unleashed the " + F.name("Infernal Horror") + "!")); + + if (!Manager.getDisguiseManager().isDisguised(player)) + { + DisguiseSkeleton disguiseSkeleton = new DisguiseSkeleton(player); + disguiseSkeleton.setName(player.getName()); + disguiseSkeleton.setCustomNameVisible(true); + disguiseSkeleton.showArmor(); + disguiseSkeleton.SetSkeletonType(SkeletonType.WITHER); + Manager.getDisguiseManager().disguise(disguiseSkeleton); + _disguises.put(player.getUniqueId(), disguiseSkeleton); + } + + new TextEffect(40, player.getName(), player.getLocation().add(0, 5, 0), false, false, ParticleType.FLAME) + .start(); + return true; + } + + @Override + public void onPlay(Player player) + { + if (getPlayerTicks(player) >= 40) + { + finish(player); + } + } + + @Override + public void onFinish(Player player) + { + DisguiseBase disguise = _disguises.remove(player.getUniqueId()); + + if (disguise != null) + { + Manager.getDisguiseManager().undisguise(disguise); + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/RainbowTaunt.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/RainbowTaunt.java index 6a49fe8c4..f1387bece 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/RainbowTaunt.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/RainbowTaunt.java @@ -50,7 +50,7 @@ public class RainbowTaunt extends TauntGadget Location start = player.getLocation().clone().add(sideA.multiply(4).toLocation(player.getWorld())); Location end = player.getLocation().clone().add(sideB.multiply(4).toLocation(player.getWorld())); - RainbowTauntEffect rainbowTauntEffect = new RainbowTauntEffect(start, Manager.getPlugin()); + RainbowTauntEffect rainbowTauntEffect = new RainbowTauntEffect(start); rainbowTauntEffect.setTargetLocation(new EffectLocation(end)); rainbowTauntEffect.start(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/WinEffectHalloween.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/WinEffectHalloween.java index ee4b91efa..ff479cf61 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/WinEffectHalloween.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/WinEffectHalloween.java @@ -182,11 +182,11 @@ public class WinEffectHalloween extends WinEffectGadget BabyFireworkEffect babyFireworkEffect; if (i %2 == 0) { - babyFireworkEffect = new BabyFireworkEffect((randomLoc) ? randLocation : entityLocation, Manager.getPlugin(), color); + babyFireworkEffect = new BabyFireworkEffect((randomLoc) ? randLocation : entityLocation, color); } else { - babyFireworkEffect = new BabyFireworkEffect((randomLoc) ? randLocation : entityLocation, Manager.getPlugin(), Color.ORANGE, Color.BLACK); + babyFireworkEffect = new BabyFireworkEffect((randomLoc) ? randLocation : entityLocation, Color.ORANGE, Color.BLACK); } // Starts without the firework trail babyFireworkEffect.setCount(6); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/set/SetHalloween.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/set/SetHalloween.java new file mode 100644 index 000000000..5e2ac0d59 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/set/SetHalloween.java @@ -0,0 +1,22 @@ +package mineplex.core.gadget.set; + +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailHalloween; +import mineplex.core.gadget.gadgets.death.DeathHalloween; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpHalloween; +import mineplex.core.gadget.gadgets.particle.ParticleHalloween; +import mineplex.core.gadget.types.GadgetSet; + +public class SetHalloween extends GadgetSet +{ + + public SetHalloween(GadgetManager manager) + { + super(manager, "Spooky", "Increased chance of spawning Flaming Pumpkins in game (During Halloween)", + manager.getGadget(ArrowTrailHalloween.class), + manager.getGadget(DeathHalloween.class), + manager.getGadget(DoubleJumpHalloween.class), + manager.getGadget(ParticleHalloween.class) + ); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/TauntGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/TauntGadget.java index 637c41d7b..829282b96 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/TauntGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/TauntGadget.java @@ -84,27 +84,27 @@ public abstract class TauntGadget extends Gadget public abstract void onFinish(Player player); - public void setCanPlayWithPvp(boolean canPlayWithPvp) + protected void setCanPlayWithPvp(boolean canPlayWithPvp) { _canPlayWithPvp = canPlayWithPvp; } - public void setPvpCooldown(long pvpCooldown) + protected void setPvpCooldown(long pvpCooldown) { _pvpCooldown = pvpCooldown; } - public void setShouldPlay(boolean shouldPlay) + protected void setShouldPlay(boolean shouldPlay) { _shouldPlay = shouldPlay; } - public void setEventType(UpdateType updateType) + protected void setEventType(UpdateType updateType) { _updateType = updateType; } - public void addDisabledGames(GameDisplay... disabledGames) + protected void addDisabledGames(GameDisplay... disabledGames) { _disabledGames.addAll(Arrays.asList(disabledGames)); } @@ -124,9 +124,9 @@ public abstract class TauntGadget extends Gadget return _pvpCooldown; } - public int getPlayerTicks(Player player) + protected int getPlayerTicks(Player player) { - return (_ticksPerPlayer.containsKey(player.getUniqueId())) ? _ticksPerPlayer.get(player.getUniqueId()) : -1; + return _ticksPerPlayer.getOrDefault(player.getUniqueId(), -1); } @EventHandler diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/util/CostConstants.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/util/CostConstants.java index eb1996dab..5fa7db300 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/util/CostConstants.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/util/CostConstants.java @@ -71,6 +71,10 @@ public class CostConstants * Found in Thankful Treasure */ public static final int FOUND_IN_THANKFUL_CHESTS = -21; + /** + * Found in Trick or Treat Treasure + */ + public static final int FOUND_IN_TRICK_OR_TREAT = -22; /** * Unlocked with Ultra Rank */ diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java deleted file mode 100644 index 2ebc0d0a4..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java +++ /dev/null @@ -1,96 +0,0 @@ -package mineplex.core.globalpacket; - -import java.util.Arrays; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.MiniPlugin; -import mineplex.core.account.CoreClientManager; -import mineplex.core.account.permissions.Permission; -import mineplex.core.account.permissions.PermissionGroup; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.donation.DonationManager; -import mineplex.core.globalpacket.command.GlobalPacketCommand; -import mineplex.core.globalpacket.listeners.GlobalGiveCoins; -import mineplex.core.globalpacket.listeners.GlobalGiveGems; -import mineplex.core.globalpacket.listeners.GlobalGiveItem; -import mineplex.core.globalpacket.redis.GlobalPacketHandler; -import mineplex.core.globalpacket.redis.GlobalPacketMessage; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.pet.PetManager; -import mineplex.core.reward.RewardManager; -import mineplex.core.stats.StatsManager; -import mineplex.core.status.ServerStatusManager; -import mineplex.serverdata.commands.ServerCommandManager; - -public class GlobalPacketManager extends MiniPlugin -{ - public enum Perm implements Permission - { - GLOBAL_PACKET_COMMAND, - } - - private CoreClientManager _clientManager; - private ServerStatusManager _statusManager; - private InventoryManager _inventoryManager; - private DonationManager _donationManager; - private RewardManager _rewardManager; - - public GlobalPacketManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager, InventoryManager inventoryManager, DonationManager donationManager, PetManager petManager, StatsManager statsManager, RewardManager rewardmanager) - { - super("Global Packet Manager", plugin); - - _clientManager = clientManager; - _statusManager = statusManager; - _inventoryManager = inventoryManager; - _donationManager = donationManager; - _rewardManager = rewardmanager; - - ServerCommandManager.getInstance().registerCommandType("GlobalPacketMessage", GlobalPacketMessage.class, new GlobalPacketHandler(statusManager)); - - getPluginManager().registerEvents(new GlobalGiveItem(inventoryManager, _rewardManager), getPlugin()); - getPluginManager().registerEvents(new GlobalGiveGems(donationManager), getPlugin()); - getPluginManager().registerEvents(new GlobalGiveCoins(donationManager, clientManager), getPlugin()); - - generatePermissions(); - } - - private void generatePermissions() - { - - PermissionGroup.ADMIN.setPermission(Perm.GLOBAL_PACKET_COMMAND, true, true); - } - - public void callGlobalCommand(Player caller, String[] args) - { - String callerName = null; - UUID callerUUID = null; - List callerRanks = null; - - if (caller != null) - { - callerName = caller.getName(); - callerUUID = caller.getUniqueId(); - callerRanks = _clientManager.Get(caller).getAdditionalGroups().stream().map(PermissionGroup::name).collect(Collectors.toList()); - callerRanks.add(_clientManager.Get(caller).getPrimaryGroup().name()); - - UtilPlayer.message(caller, F.main("Global", "Sending Global Command with Arguments;")); - UtilPlayer.message(caller, F.main("Global", F.elem(Arrays.toString(args)))); - UtilPlayer.message(caller, F.main("Global", "Please be patient for a response.")); - } - - GlobalPacketMessage message = new GlobalPacketMessage(callerName, callerUUID, callerRanks, _statusManager.getCurrentServerName(), args); - message.publish(); - } - - @Override - public void addCommands() - { - addCommand(new GlobalPacketCommand(this)); - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/command/GlobalPacketCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/command/GlobalPacketCommand.java deleted file mode 100644 index 84daffd32..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/command/GlobalPacketCommand.java +++ /dev/null @@ -1,29 +0,0 @@ -package mineplex.core.globalpacket.command; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.globalpacket.GlobalPacketManager; - -public class GlobalPacketCommand extends CommandBase -{ - public GlobalPacketCommand(GlobalPacketManager plugin) - { - super(plugin, GlobalPacketManager.Perm.GLOBAL_PACKET_COMMAND, "global", "globalpacket"); - } - - @Override - public void Execute(Player caller, String[] args) - { - if (args == null || args.length < 1) - { - UtilPlayer.message(caller, F.main("Global", "Please call the global command with at least 1 argument")); - UtilPlayer.message(caller, F.main("Global", "For help please see /global google doc")); - return; - } - - Plugin.callGlobalCommand(caller, args); - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/event/GlobalPacketEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/event/GlobalPacketEvent.java deleted file mode 100644 index 9f2b564b0..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/event/GlobalPacketEvent.java +++ /dev/null @@ -1,82 +0,0 @@ -package mineplex.core.globalpacket.event; - -import java.util.List; -import java.util.UUID; - -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class GlobalPacketEvent extends Event -{ - private Player _caller; - private String _callerName; - private UUID _callerUUID; - private List _callerGroups; - private String _sourceServer; - private String[] _parts; - - public GlobalPacketEvent(Player caller, String callerName, UUID callerUUID, List callerGroups, String sourceServer, String[] parts) - { - _caller = caller; - _callerName = callerName; - _callerUUID = callerUUID; - _callerGroups = callerGroups; - _sourceServer = sourceServer; - _parts = parts; - } - - /** - * The player that executed this global command. - * This player will be NULL when called on the servers that aren't _sourceServer - */ - public Player getCaller() - { - return _caller; - } - - /** - * The player name of the player that called the command - */ - public String getCallerName() - { - return _callerName; - } - - /** - * The UUID of the player that called the command - */ - public UUID getCallerUUID() - { - return _callerUUID; - } - - /** - * Get the rank of the player that called this global command - */ - public List getCallerGroups() - { - return _callerGroups; - } - - /** - * The server name that this global command came from - */ - public String getSourceServer() - { - return _sourceServer; - } - - /** - * Get the unprocessed parts of this command - */ - public String[] getParts() - { - return _parts; - } - - // Bukkit event stuff - private static final HandlerList handlers = new HandlerList(); - public static HandlerList getHandlerList() { return handlers; } - public HandlerList getHandlers() { return handlers; } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalGiveCoins.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalGiveCoins.java deleted file mode 100644 index 8aa2c302c..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalGiveCoins.java +++ /dev/null @@ -1,93 +0,0 @@ -package mineplex.core.globalpacket.listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import mineplex.core.account.CoreClientManager; -import mineplex.core.account.permissions.PermissionGroup; -import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.donation.DonationManager; -import mineplex.core.globalpacket.GlobalPacketManager; -import mineplex.core.globalpacket.event.GlobalPacketEvent; - -public class GlobalGiveCoins implements Listener -{ - private DonationManager _donationManager; - private CoreClientManager _clientManager; - - public GlobalGiveCoins(DonationManager donationManager, CoreClientManager coreClientManager) - { - _donationManager = donationManager; - _clientManager = coreClientManager; - } - - @EventHandler - public void giveCoins(final GlobalPacketEvent e) - { - boolean allowed = false; - for (String id : e.getCallerGroups()) - { - if (PermissionGroup.valueOf(id).hasPermission(GlobalPacketManager.Perm.GLOBAL_PACKET_COMMAND)) - { - allowed = true; - break; - } - } - - if (!allowed) - { - return; - } - - if (e.getParts() == null || e.getParts().length < 1) - return; - - if (!e.getParts()[0].equalsIgnoreCase("givecoins")) - return; - - if (e.getParts().length != 2) - { - if (e.getCaller() != null) - { - UtilPlayer.message(e.getCaller(), F.main("Global", "/global givecoins ")); - } - - return; - } - - int amount = 1; - try - { - amount = Integer.parseInt(e.getParts()[1]); - } - catch (Exception ex) - { - // No number - if (e.getCaller() != null) - { - UtilPlayer.message(e.getCaller(), F.main("Global", "[" + F.elem(amount + "") + "] is not a valid amount.")); - } - - return; - } - - final int fAmount = amount; - for (final Player p : UtilServer.getPlayers()) - { - _donationManager.rewardCurrency(GlobalCurrency.TREASURE_SHARD, p, "Global Coins", amount, response -> - { - if (response) - { - UtilPlayer.message(p, F.main("Global", "You received " + F.elem(fAmount + " Coins") + ".")); - UtilTextMiddle.display(C.cYellow + fAmount + " Coins", C.cGold + "received from " + e.getCallerName() + "!", p); - } - }); - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalGiveGems.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalGiveGems.java deleted file mode 100644 index fd38327e3..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalGiveGems.java +++ /dev/null @@ -1,87 +0,0 @@ -package mineplex.core.globalpacket.listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import mineplex.core.account.permissions.PermissionGroup; -import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.donation.DonationManager; -import mineplex.core.globalpacket.GlobalPacketManager; -import mineplex.core.globalpacket.event.GlobalPacketEvent; - -public class GlobalGiveGems implements Listener -{ - private DonationManager _donationManager; - - public GlobalGiveGems(DonationManager donationManager) - { - _donationManager = donationManager; - } - - @EventHandler - public void giveGems(final GlobalPacketEvent e) - { - boolean allowed = false; - for (String id : e.getCallerGroups()) - { - if (PermissionGroup.valueOf(id).hasPermission(GlobalPacketManager.Perm.GLOBAL_PACKET_COMMAND)) - { - allowed = true; - break; - } - } - - if (!allowed) - { - return; - } - - if (e.getParts() == null || e.getParts().length < 1) - return; - - if (!e.getParts()[0].equalsIgnoreCase("givegems")) - return; - - if (e.getParts().length != 2) - { - if (e.getCaller() != null) - { - UtilPlayer.message(e.getCaller(), F.main("Global", "/global givegems ")); - } - - return; - } - - int amount = 1; - try - { - amount = Integer.parseInt(e.getParts()[1]); - } - catch (Exception ex) - { - // No number - if (e.getCaller() != null) - { - UtilPlayer.message(e.getCaller(), F.main("Global", "[" + F.elem(amount + "") + "] is not a valid amount.")); - } - - return; - } - - final int fAmount = amount; - for (final Player p : UtilServer.getPlayers()) - { - _donationManager.rewardCurrency(GlobalCurrency.GEM, p, "Global Gems", amount, success -> - { - UtilPlayer.message(p, F.main("Global", "You received " + F.elem(fAmount + " Gems") + ".")); - UtilTextMiddle.display(C.cYellow + fAmount + " Gems", C.cGold + "received from " + e.getCallerName() + "!", p); - }); - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalGiveItem.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalGiveItem.java deleted file mode 100644 index 66fb5523c..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/listeners/GlobalGiveItem.java +++ /dev/null @@ -1,159 +0,0 @@ -package mineplex.core.globalpacket.listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import mineplex.core.account.permissions.PermissionGroup; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.globalpacket.GlobalPacketManager; -import mineplex.core.globalpacket.event.GlobalPacketEvent; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.reward.Reward; -import mineplex.core.reward.RewardManager; -import mineplex.core.reward.RewardType; - -public class GlobalGiveItem implements Listener -{ - private InventoryManager _inventoryManager; - private RewardManager _rewardManager; - - public GlobalGiveItem(InventoryManager inventoryManager, RewardManager rewardManager) - { - _inventoryManager = inventoryManager; - _rewardManager = rewardManager; - } - - public enum GlobalItem - { - OLD_CHEST("Old Chest"), - ANCIENT_CHEST("Ancient Chest"), - MYTHICAL_CHEST("Mythical Chest"), - - GAME_LOOT("Game Loot"); - - private String _invName; - - GlobalItem(String invName) - { - _invName = invName; - } - - public String getInvName() - { - return _invName; - } - } - - @EventHandler - public void giveItem(final GlobalPacketEvent e) - { - boolean allowed = false; - for (String id : e.getCallerGroups()) - { - if (PermissionGroup.valueOf(id).hasPermission(GlobalPacketManager.Perm.GLOBAL_PACKET_COMMAND)) - { - allowed = true; - break; - } - } - - if (!allowed) - { - return; - } - - if (e.getParts() == null || e.getParts().length < 1) - return; - - if (!e.getParts()[0].equalsIgnoreCase("giveitem")) - return; - - if (e.getParts().length != 3) - { - if (e.getCaller() != null) - { - UtilPlayer.message(e.getCaller(), F.main("Global", "/global giveitem ")); - } - - return; - } - - GlobalItem item = null; - - try - { - item = GlobalItem.valueOf(e.getParts()[1]); - } - catch (Exception ex) - { - // Wrong item - - if (e.getCaller() != null) - { - UtilPlayer.message(e.getCaller(), F.main("Global", "That GlobalItem type can't be found. Types:")); - - String list = ""; - for (GlobalItem i : GlobalItem.values()) - { - list += i.toString() + " "; - } - - UtilPlayer.message(e.getCaller(), C.cYellow + list); - } - - return; - } - - int amount = 1; // Default, shouldn't happen anyway. - - try - { - amount = Integer.parseInt(e.getParts()[2]); - } - catch (Exception ex) - { - // Not a number - - if (e.getCaller() != null) - { - UtilPlayer.message(e.getCaller(), F.main("Global", "[" + F.elem(e.getParts()[2]) + "] is not a valid number.")); - } - - return; - } - - if (item.toString().contains("CHEST")) - { - for (final Player p : UtilServer.getPlayers()) - { - final int fAmount = amount; - final GlobalItem fItem = item; - _inventoryManager.addItemToInventory(data -> - { - UtilPlayer.message(p, F.main("Global", "You received " + F.elem(fAmount + " " + fItem.getInvName() + "(s)") + " from " + F.name(e.getCallerName()) + ".")); - UtilTextMiddle.display(C.cYellow + fAmount + " " + fItem.getInvName() + "(s)", C.cGold + "received from " + e.getCallerName() + "!", p); - }, p, item.getInvName(), amount); - } - - return; - } - else if (item.toString().equalsIgnoreCase("GAME_LOOT")) - { - for (final Player p : UtilServer.getPlayers()) - { - Reward reward = _rewardManager.nextReward(p, null, false, RewardType.GAME_LOOT, true); - reward.giveReward(RewardType.GAME_LOOT, p, data -> - { - UtilPlayer.message(p, F.main("Global", "You received " + F.elem("Game Loot") + " from " + F.name(e.getCallerName()) + ".")); - UtilPlayer.message(p, F.main("Global", "You won " + F.elem(data.getFriendlyName()) + "!")); - UtilTextMiddle.display(C.cYellow + data.getFriendlyName(), C.cGold + "received from " + e.getCallerName() + "!", p); - }); - } - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketHandler.java deleted file mode 100644 index 4c76811d2..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketHandler.java +++ /dev/null @@ -1,39 +0,0 @@ -package mineplex.core.globalpacket.redis; - -import org.bukkit.entity.Player; - -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.globalpacket.event.GlobalPacketEvent; -import mineplex.core.status.ServerStatusManager; -import mineplex.serverdata.commands.CommandCallback; -import mineplex.serverdata.commands.ServerCommand; - -public class GlobalPacketHandler implements CommandCallback -{ - private ServerStatusManager _serverStatus; - - public GlobalPacketHandler(ServerStatusManager serverStatus) - { - _serverStatus = serverStatus; - } - - @Override - public void run(ServerCommand command) - { - if (command instanceof GlobalPacketMessage) - { - GlobalPacketMessage packetMessage = ((GlobalPacketMessage) command); - - Player caller = null; - if (packetMessage.getSourceServer() != null && packetMessage.getSourceServer().equals(_serverStatus.getCurrentServerName())) - { - caller = UtilPlayer.searchExact(packetMessage.getCallerUUID()); - } - - GlobalPacketEvent event = new GlobalPacketEvent(caller, packetMessage.getCallerName(), packetMessage.getCallerUUID(), - packetMessage.getCallerGroups(), packetMessage.getSourceServer(), packetMessage.getParts()); - UtilServer.getServer().getPluginManager().callEvent(event); - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketMessage.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketMessage.java deleted file mode 100644 index 5c9cbd95b..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketMessage.java +++ /dev/null @@ -1,49 +0,0 @@ -package mineplex.core.globalpacket.redis; - -import java.util.List; -import java.util.UUID; - -import mineplex.serverdata.commands.ServerCommand; - -public class GlobalPacketMessage extends ServerCommand -{ - private String _callerName; - private UUID _callerUUID; - private List _callerGroups; - private String _sourceServer; - private String[] _parts; - - public GlobalPacketMessage(String callerName, UUID callerUUID, List callerGroups, String sourceServer, String[] parts) - { - _callerName = callerName; - _callerUUID = callerUUID; - _callerGroups = callerGroups; - _sourceServer = sourceServer; - _parts = parts; - } - - public String getCallerName() - { - return _callerName; - } - - public UUID getCallerUUID() - { - return _callerUUID; - } - - public List getCallerGroups() - { - return _callerGroups; - } - - public String getSourceServer() - { - return _sourceServer; - } - - public String[] getParts() - { - return _parts; - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java index a765a3904..5d6e016f6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java @@ -366,7 +366,7 @@ public class Hologram { if (_hideBoundingBox) { DataWatcher watcher = packet.l; - packet.d = (int) ((getLocation().getY() + ((double) textRow * 0.285)) * 32); + packet.d = (int) ((getLocation().getY() + ((double) textRow * 0.31)) * 32); watcher.a(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16); } @@ -384,7 +384,7 @@ public class Hologram { packet.a = entityId; packet.b = 30; packet.c = (int) (getLocation().getX() * 32); - packet.d = (int) ((getLocation().getY() - 2.1 + ((double) textRow * 0.285)) * 32); + packet.d = (int) ((getLocation().getY() - 2.1 + ((double) textRow * 0.31)) * 32); packet.e = (int) (getLocation().getZ() * 32); packet.l = watcher; packet.uuid = UUID.randomUUID(); @@ -537,7 +537,7 @@ public class Hologram { PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(); teleportPacket.a = entityId; teleportPacket.b = x; - teleportPacket.c = (int) Math.floor((oldLocation.getY() + (-2.1) + ((double) i * 0.285)) * 32); + teleportPacket.c = (int) Math.floor((oldLocation.getY() + (-2.1) + ((double) i * 0.31)) * 32); teleportPacket.d = z; packets1_9[i] = teleportPacket; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/imagemap/ImageMapManager.java b/Plugins/Mineplex.Core/src/mineplex/core/imagemap/ImageMapManager.java index 4cfc9486b..5d7892641 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/imagemap/ImageMapManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/imagemap/ImageMapManager.java @@ -1,12 +1,15 @@ package mineplex.core.imagemap; -import mineplex.core.MiniPlugin; -import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.imagemap.objects.PlayerMapBoard; -import mineplex.core.imagemap.objects.PlayerMapImage; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -18,15 +21,14 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.imagemap.objects.MapImage; +import mineplex.core.imagemap.objects.PlayerMapBoard; +import mineplex.core.imagemap.objects.PlayerMapImage; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; @ReflectivelyCreateMiniPlugin public class ImageMapManager extends MiniPlugin @@ -60,7 +62,13 @@ public class ImageMapManager extends MiniPlugin { Player player = event.getPlayer(); - runSyncLater(() -> _boards.forEach(board -> board.onPlayerJoin(player)), 40); + runSyncLater(() -> _boards.forEach(board -> + { + if (board.isHandleJoin()) + { + board.onPlayerJoin(player); + } + }), 40); } @EventHandler @@ -82,7 +90,39 @@ public class ImageMapManager extends MiniPlugin _boards.forEach(PlayerMapBoard::onRefresh); } + public MapImage createBoard(Location topLeft, BlockFace direction, int width, int height, String image) + { + BufferedImage bufferedImage = getImage(new File(IMAGE_DIR + File.separator + image)); + return createBoard(topLeft, direction, width, height, bufferedImage); + } + + public MapImage createBoard(Location topLeft, BlockFace direction, int width, int height, File image) + { + BufferedImage bufferedImage = getImage(image); + return createBoard(topLeft, direction, width, height, bufferedImage); + } + + public MapImage createBoard(Location topLeft, BlockFace direction, int width, int height, URL image) + { + BufferedImage bufferedImage = getImage(image); + return createBoard(topLeft, direction, width, height, bufferedImage); + } + + public MapImage createBoard(Location topLeft, BlockFace direction, int width, int height, BufferedImage image) + { + List itemFrames = createItemFrames(topLeft, direction, width, height); + MapImage mapImage = new MapImage(image, itemFrames, width, height); + mapImage.create(); + + return mapImage; + } + public PlayerMapBoard createPlayerBoard(Location topLeft, BlockFace direction, int width, int height, String... images) + { + return createPlayerBoard(topLeft, direction, width, height, true, images); + } + + public PlayerMapBoard createPlayerBoard(Location topLeft, BlockFace direction, int width, int height, boolean handleJoin, String... images) { BufferedImage[] bufferedImages = new BufferedImage[images.length]; @@ -91,22 +131,15 @@ public class ImageMapManager extends MiniPlugin bufferedImages[i] = getImage(new File(IMAGE_DIR + File.separator + images[i])); } - return createPlayerBoard(topLeft, direction, width, height, bufferedImages); + return createPlayerBoard(topLeft, direction, width, height, handleJoin, bufferedImages); } public PlayerMapBoard createPlayerBoard(Location topLeft, BlockFace direction, int width, int height, File... images) { - BufferedImage[] bufferedImages = new BufferedImage[images.length]; - - for (int i = 0; i < images.length; i++) - { - bufferedImages[i] = getImage(images[i]); - } - - return createPlayerBoard(topLeft, direction, width, height, bufferedImages); + return createPlayerBoard(topLeft, direction, width, height, true, images); } - public PlayerMapBoard createPlayerBoard(Location topLeft, BlockFace direction, int width, int height, URL... images) + public PlayerMapBoard createPlayerBoard(Location topLeft, BlockFace direction, int width, int height, boolean handleJoin, File... images) { BufferedImage[] bufferedImages = new BufferedImage[images.length]; @@ -115,10 +148,27 @@ public class ImageMapManager extends MiniPlugin bufferedImages[i] = getImage(images[i]); } - return createPlayerBoard(topLeft, direction, width, height, bufferedImages); + return createPlayerBoard(topLeft, direction, width, height, handleJoin, bufferedImages); } - public PlayerMapBoard createPlayerBoard(Location topLeft, BlockFace direction, int width, int height, BufferedImage... images) + public PlayerMapBoard createPlayerBoard(Location topLeft, BlockFace direction, int width, int height, URL... images) + { + return createPlayerBoard(topLeft, direction, width, height, true, images); + } + + public PlayerMapBoard createPlayerBoard(Location topLeft, BlockFace direction, int width, int height, boolean handleJoin, URL... images) + { + BufferedImage[] bufferedImages = new BufferedImage[images.length]; + + for (int i = 0; i < images.length; i++) + { + bufferedImages[i] = getImage(images[i]); + } + + return createPlayerBoard(topLeft, direction, width, height, handleJoin, bufferedImages); + } + + public PlayerMapBoard createPlayerBoard(Location topLeft, BlockFace direction, int width, int height, boolean handleJoin, BufferedImage... images) { List itemFrames = createItemFrames(topLeft, direction, width, height); List mapImageList = new ArrayList<>(); @@ -131,9 +181,12 @@ public class ImageMapManager extends MiniPlugin mapImageList.add(mapImage); } - PlayerMapBoard board = new PlayerMapBoard(topLeft, mapImageList); + PlayerMapBoard board = new PlayerMapBoard(topLeft, mapImageList, handleJoin); - runSyncLater(() -> Bukkit.getOnlinePlayers().forEach(board::onPlayerJoin), 50); + if (handleJoin) + { + runSyncLater(() -> Bukkit.getOnlinePlayers().forEach(board::onPlayerJoin), 50); + } _boards.add(board); return board; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/MapImage.java b/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/MapImage.java index 37c6d315f..ea741454d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/MapImage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/MapImage.java @@ -1,6 +1,9 @@ package mineplex.core.imagemap.objects; -import mineplex.core.imagemap.ImageMapRenderer; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; @@ -8,20 +11,21 @@ import org.bukkit.entity.ItemFrame; import org.bukkit.inventory.ItemStack; import org.bukkit.map.MapView; -import java.awt.image.BufferedImage; -import java.util.List; +import mineplex.core.imagemap.ImageMapRenderer; public class MapImage { - protected final BufferedImage _image; + private final BufferedImage _image; protected final List _itemFrames; + protected final List _mapViews; protected final int _width, _height; public MapImage(BufferedImage image, List itemFrames, int width, int height) { _image = image; _itemFrames = itemFrames; + _mapViews = new ArrayList<>(itemFrames.size()); _width = width; _height = height; } @@ -50,6 +54,7 @@ public class MapImage map.addRenderer(new ImageMapRenderer(_image, x, y)); item.setDurability(map.getId()); + _mapViews.add(map); return item; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/PlayerMapBoard.java b/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/PlayerMapBoard.java index fb58bd7ac..d9f9e29f9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/PlayerMapBoard.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/PlayerMapBoard.java @@ -18,12 +18,14 @@ public class PlayerMapBoard private final Location _location; private final List _images; private final Map _viewers; + private final boolean _handleJoin; - public PlayerMapBoard(Location location, List images) + public PlayerMapBoard(Location location, List images, boolean handleJoin) { _location = location; _images = images; _viewers = new HashMap<>(); + _handleJoin = handleJoin; } public void goTo(Player player, boolean next) @@ -45,8 +47,13 @@ public class PlayerMapBoard } int newIndex = next ? index + 1 : index - 1; - _viewers.put(player, newIndex); - _images.get(newIndex).addViewer(player, true); + goTo(player, newIndex); + } + + public void goTo(Player player, int index) + { + _viewers.put(player, index); + _images.get(index).addViewer(player, true); } public void onPlayerJoin(Player player) @@ -87,4 +94,8 @@ public class PlayerMapBoard return _location; } + public boolean isHandleJoin() + { + return _handleJoin; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/PlayerMapImage.java b/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/PlayerMapImage.java index 2f21cd59b..deb102b29 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/PlayerMapImage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/imagemap/objects/PlayerMapImage.java @@ -1,15 +1,15 @@ package mineplex.core.imagemap.objects; -import mineplex.core.common.util.UtilServer; -import mineplex.core.imagemap.CustomItemFrames; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.World; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.List; +import mineplex.core.imagemap.CustomItemFrames; public class PlayerMapImage extends MapImage { @@ -48,14 +48,16 @@ public class PlayerMapImage extends MapImage { if (sendMap) { - //FIXME - int slot = 8; - for (ItemStack itemStack : _itemMaps) - { - player.getInventory().setItem(slot++, itemStack); - } +// //FIXME +// int slot = 8; +// for (ItemStack itemStack : _itemMaps) +// { +// player.getInventory().setItem(slot++, itemStack); +// } +// +// UtilServer.runSyncLater(() -> player.getInventory().removeItem(_itemMaps.toArray(new ItemStack[0])), 5); - UtilServer.runSyncLater(() -> player.getInventory().removeItem(_itemMaps.toArray(new ItemStack[0])), 5); + _mapViews.forEach(player::sendMap); } for (int i = 0; i < _itemMaps.size(); i++) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPC.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPC.java new file mode 100644 index 000000000..11d44065c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPC.java @@ -0,0 +1,171 @@ +package mineplex.core.newnpc; + +import java.util.Arrays; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.EntityEquipment; + +import mineplex.core.Managers; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.HologramManager; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.utils.UtilVariant; +import mineplex.serverdata.database.column.Column; +import mineplex.serverdata.database.column.ColumnByte; +import mineplex.serverdata.database.column.ColumnDouble; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; + +public class NPC +{ + + private final HologramManager HOLOGRAM_MANAGER = Managers.require(HologramManager.class); + + private int _id; + protected EntityType _entityType; + protected String _name; + protected Location _spawn; + private Material _inHand; + private byte _inHandData; + private Material _helmet; + private Material _chestplate; + private Material _leggings; + private Material _boots; + private String _metadata; + + private LivingEntity _entity; + private Hologram _nameTag; + + public NPC(int id, EntityType entityType, String name, Location spawn, Material inHand, byte inHandData, Material helmet, Material chestplate, Material leggings, Material boots, String metadata) + { + _id = id; + _entityType = entityType; + _name = name; + _spawn = spawn; + _inHand = inHand; + _inHandData = inHandData; + _helmet = helmet; + _chestplate = chestplate; + _leggings = leggings; + _boots = boots; + _metadata = metadata; + } + + public LivingEntity spawnEntity() + { + _spawn.getChunk().load(true); + LivingEntity entity; + + //TODO remove this terrible hack + if (_name.contains("Halloween")) + { + entity = UtilVariant.spawnWitherSkeleton(_spawn); + } + else + { + entity = (LivingEntity) _spawn.getWorld().spawnEntity(_spawn, _entityType); + } + + boolean nullName = _name.equals("NULL"); + + entity.setCanPickupItems(false); + entity.setRemoveWhenFarAway(false); + entity.setCustomName(nullName ? null : ChatColor.translateAlternateColorCodes('&', _name)); + entity.setCustomNameVisible(!nullName); + + EntityEquipment equipment = entity.getEquipment(); + + if (_inHand != null) + { + equipment.setItemInHand(ItemStackFactory.Instance.CreateStack(_inHand, _inHandData)); + } + if (_helmet != null) + { + equipment.setHelmet(ItemStackFactory.Instance.CreateStack(_helmet)); + } + if (_chestplate != null) + { + equipment.setChestplate(ItemStackFactory.Instance.CreateStack(_chestplate)); + } + if (_leggings != null) + { + equipment.setLeggings(ItemStackFactory.Instance.CreateStack(_leggings)); + } + if (_boots != null) + { + equipment.setBoots(ItemStackFactory.Instance.CreateStack(_boots)); + } + + UtilEnt.vegetate(entity); + UtilEnt.setFakeHead(entity, true); + UtilEnt.CreatureLook(entity, _spawn.getPitch(), _spawn.getYaw()); + UtilEnt.ghost(entity, true, false); + UtilEnt.silence(entity, true); + + _entity = entity; + return entity; + } + + public Hologram getNameTag() + { + if (_nameTag == null) + { + _nameTag = new Hologram(HOLOGRAM_MANAGER, _entity.getLocation().add(0, UtilEnt.getHeight(_entity), 0), true, _entity.getCustomName()) + .start(); + + _entity.setCustomNameVisible(false); + _entity.setCustomName(null); + } + + return _nameTag; + } + + void setId(int id) + { + _id = id; + } + + public int getId() + { + return _id; + } + + public String getMetadata() + { + return _metadata; + } + + public LivingEntity getEntity() + { + return _entity; + } + + public List> toDatabaseQuery() + { + return Arrays.asList( + new ColumnVarChar("entity_type", 32, _entityType.name()), + new ColumnVarChar("name", 32, _name), + new ColumnVarChar("world", 32, _spawn.getWorld().getName()), + new ColumnDouble("x", _spawn.getBlockX() + 0.5), + new ColumnDouble("y", _spawn.getY()), + new ColumnDouble("z", _spawn.getBlockZ() + 0.5), + new ColumnInt("yaw", (int) _spawn.getYaw()), + new ColumnInt("pitch", (int) _spawn.getPitch()), + new ColumnVarChar("in_hand", 32, _inHand == null ? "NULL" : _inHand.name()), + new ColumnByte("in_hand_data", _inHandData), + new ColumnVarChar("helmet", 32, _helmet == null ? "NULL" : _helmet.name()), + new ColumnVarChar("chestplate", 32, _chestplate == null ? "NULL" : _chestplate.name()), + new ColumnVarChar("leggings", 32, _leggings == null ? "NULL" : _leggings.name()), + new ColumnVarChar("boots", 32, _boots == null ? "NULL" : _boots.name()), + new ColumnVarChar("metadata", 32, _metadata), + new ColumnVarChar("skinValue", 400, "NULL"), + new ColumnVarChar("skinSignature", 700, "NULL") + ); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPCBuilder.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPCBuilder.java new file mode 100644 index 000000000..c0b68ca29 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPCBuilder.java @@ -0,0 +1,115 @@ +package mineplex.core.newnpc; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.PlayerInventory; + +import mineplex.core.common.skin.SkinData; +import mineplex.core.utils.UtilGameProfile; + +public class NPCBuilder +{ + + private EntityType _type; + private String _name; + private String _metadata; + private boolean _useSkin; + + public void build(Player player, NewNPCManager manager) + { + Location location = player.getLocation(); + PlayerInventory inventory = player.getInventory(); + Material inHand = inventory.getItemInHand() == null ? null : inventory.getItemInHand().getType(); + byte inHandData = inventory.getItemInHand() == null ? 0 : inventory.getItemInHand().getData().getData(); + Material helmet = inventory.getHelmet() == null ? null : inventory.getHelmet().getType(); + Material chestplate = inventory.getChestplate() == null ? null : inventory.getChestplate().getType(); + Material leggings = inventory.getLeggings() == null ? null : inventory.getLeggings().getType(); + Material boots = inventory.getBoots() == null ? null : inventory.getBoots().getType(); + + NPC npc; + + if (_type == EntityType.PLAYER) + { + SkinData data; + + if (_useSkin) + { + data = SkinData.constructFromGameProfile(UtilGameProfile.getGameProfile(player), true, true); + } + else + { + data = SkinData.STEVE; + } + + npc = new PlayerNPC( + -1, + _name, + location, + inHand, + inHandData, + helmet, + chestplate, + leggings, + boots, + _metadata, + data.getProperty().getValue(), + data.getProperty().getSignature() + ); + } + else + { + npc = new NPC( + -1, + _type, + _name, + location, + inHand, + inHandData, + helmet, + chestplate, + leggings, + boots, + _metadata + ); + } + + manager.addNPC(npc); + } + + public void setType(EntityType type) + { + _type = type; + } + + public EntityType getType() + { + return _type; + } + + public void setName(String name) + { + _name = name; + } + + public String getName() + { + return _name; + } + + public void setMetadata(String metadata) + { + _metadata = metadata; + } + + public String getMetadata() + { + return _metadata; + } + + public void setUseSkin(boolean useSkin) + { + _useSkin = useSkin; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCManager.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCManager.java new file mode 100644 index 000000000..0decb30d9 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCManager.java @@ -0,0 +1,510 @@ +package mineplex.core.newnpc; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.world.ChunkUnloadEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.permissions.Permission; +import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilText; +import mineplex.core.creature.Creature; +import mineplex.core.creature.event.CreatureKillEntitiesEvent; +import mineplex.core.newnpc.command.NPCCommand; +import mineplex.core.newnpc.command.NPCDeleteCommand; +import mineplex.core.newnpc.command.NPCMoveCommand; +import mineplex.core.newnpc.event.NPCInteractEvent; +import mineplex.core.newnpc.event.NPCRefreshEvent; +import mineplex.core.recharge.Recharge; + +/** + * NPCManager is a new version of the previous NpcManager to improve usability and more general purpose. + *
+ * NPCs are saved in the table newNPCs in the accounts database. + *
+ * Details on how to create NPCs can be found in the {@link NPC} and {@link PlayerNPC} classes. + */ +@ReflectivelyCreateMiniPlugin +public class NewNPCManager extends MiniPlugin +{ + + public enum Perm implements Permission + { + NPC_COMMAND, + BUILD_NPC_COMMAND, + CLEAR_NPC_COMMAND, + DELETE_NPC_COMMAND, + REFRESH_NPC_COMMAND, + MOVE_NPC_COMMAND + } + + private final Creature _creature; + + private final NewNPCRepository _repository; + + private final List _npcs; + private final Map _builders; + private final Map _teleportMap; + + private NewNPCManager() + { + super("NPC"); + + _creature = require(Creature.class); + _repository = new NewNPCRepository(); + _npcs = new ArrayList<>(); + _builders = new HashMap<>(); + _teleportMap = new HashMap<>(); + + // Loading NPCs on the main thread makes sure that _npcs is populated before anything tries to spawn NPCs. + loadNPCs(); + // Any NPC with the metadata DUMMY will always be spawned regardless, useful for testing designs + spawnNPCs("DUMMY", npc -> + { + if (npc instanceof PlayerNPC) + { + npc.getNameTag(); + } + }); + + generatePermissions(); + } + + private void generatePermissions() + { + PermissionGroup.ADMIN.setPermission(Perm.NPC_COMMAND, true, true); + PermissionGroup.ADMIN.setPermission(Perm.BUILD_NPC_COMMAND, true, true); + PermissionGroup.DEV.setPermission(Perm.CLEAR_NPC_COMMAND, true, true); + PermissionGroup.ADMIN.setPermission(Perm.DELETE_NPC_COMMAND, true, true); + PermissionGroup.ADMIN.setPermission(Perm.REFRESH_NPC_COMMAND, true, true); + PermissionGroup.ADMIN.setPermission(Perm.MOVE_NPC_COMMAND, true, true); + } + + @Override + public void addCommands() + { + addCommand(new NPCCommand(this)); + } + + /** + * Loads synchronously all NPCs from the database and populates the {@link #_npcs} list if the npc was not already + * contained within the collection. Thus this method can be called more than once during runtime. Though it is + * recommended that if the caller is not calling this during startup then this should not be called from the main + * thread. + */ + private void loadNPCs() + { + _repository.getNPCs(npcs -> + { + npcs.forEach(npc -> + { + if (_npcs.contains(npc)) + { + return; + } + + _npcs.add(npc); + }); + }); + } + + /** + * Spawns all NPCs that have the metadata specified. + * + * @param metadata The metadata that must equal the NPC's metadata. + * @param after A callback consumer for each npc. + */ + public void spawnNPCs(String metadata, Consumer after) + { + _creature.SetForce(true); + + List npcs = getUnloadedNPCs(metadata); + + npcs.forEach(npc -> + { + npc.spawnEntity(); + + if (after != null) + { + after.accept(npc); + } + }); + + _creature.SetForce(false); + } + + /** + * Calls {@link #loadNPCs()} then the {@link NPCRefreshEvent} + */ + public void refreshNPCS() + { + loadNPCs(); + + UtilServer.CallEvent(new NPCRefreshEvent()); + } + + /** + * Removes an NPC's entity and removes it from the database. + * + * @param npc The NPC you want to delete. + */ + public void deleteNPC(NPC npc) + { + runAsync(() -> _repository.deleteNPC(npc)); + + if (npc.getEntity() != null) + { + npc.getEntity().remove(); + } + + _npcs.remove(npc); + } + + /** + * Deletes every NPC. + * + * @param deleteFromDB If true, all NPC's are deleted from the database. If false this action is only temporary. + */ + public void clearNPCS(boolean deleteFromDB) + { + if (deleteFromDB) + { + runAsync(_repository::clearNPCs); + } + + _npcs.forEach(npc -> + { + if (npc.getEntity() != null) + { + npc.getEntity().remove(); + } + }); + + _npcs.clear(); + } + + /** + * @param npc The NPC you want to spawn. + * @see #addNPC(NPC, boolean) + */ + public void addNPC(NPC npc) + { + addNPC(npc, true); + } + + /** + * Adds and spawns an NPC. + * + * @param npc The NPC you want to spawn. + * @param saveToDB If true the NPC will be saved to the database. + */ + public void addNPC(NPC npc, boolean saveToDB) + { + _creature.SetForce(true); + + _npcs.add(npc); + npc.spawnEntity(); + + if (saveToDB) + { + runAsync(() -> _repository.insertNPCIfNotExists(npc)); + } + + _creature.SetForce(false); + } + + /** + * Used by {@link NPCMoveCommand}. Has no other purpose. + */ + public void setPlayerTeleport(Player player) + { + _teleportMap.put(player, player.getLocation()); + } + + /** + * Teleports an NPC to a location and saves that in the database for future reference. + * + * @param npc The NPC you want to move. + * @param location The Location you want to move the NPC to. + */ + public void teleport(NPC npc, Location location) + { + // If there isn't an entity or the location to go is null, then don't teleport. + if (npc.getEntity() == null || location == null) + { + return; + } + + npc.getEntity().teleport(location); + runAsync(() -> _repository.teleportNPC(npc, location)); + } + + /** + * Used by {@link mineplex.core.newnpc.command.NPCBuildCommand}. Has no other purpose. + */ + public void createBuilder(Player player) + { + _builders.put(player, new NPCBuilder()); + + player.sendMessage(F.main(_moduleName, "Hello " + F.name(player.getName()) + "! It seems you would like to create a new NPC. Hold or wear any items that you want your NPC to have.")); + player.sendMessage(F.main("Step 1", "Type in chat the Entity Type of your NPC.")); + } + + /** + * Cleans up NPC creation maps, if the player quits. + */ + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + Player player = event.getPlayer(); + + _builders.remove(player); + _teleportMap.remove(player); + } + + /** + * Handles {@link NPCBuilder} data input. + */ + @EventHandler(priority = EventPriority.LOWEST) + public void chat(AsyncPlayerChatEvent event) + { + Player player = event.getPlayer(); + NPCBuilder builder = _builders.get(player); + + if (builder == null) + { + return; + } + + event.setCancelled(true); + + if (builder.getType() == null) + { + try + { + builder.setType(EntityType.valueOf(event.getMessage().toUpperCase())); + player.sendMessage(F.main(_moduleName, "Set the entity type to " + F.name(builder.getType().toString()) + "!")); + + player.sendMessage(F.main("Step 2", "Now type in chat the name of your NPC. Using " + F.elem("&") + " as colour codes")); + } + catch (IllegalArgumentException e) + { + player.sendMessage(F.main(_moduleName, "That isn't a valid entity type")); + player.sendMessage(F.main(_moduleName, "Valid Entity Types: " + UtilText.listToString(Arrays.asList(EntityType.values()), true))); + } + } + else if (builder.getName() == null) + { + if (event.getMessage().length() > 32) + { + player.sendMessage(F.main(_moduleName, "The maximum length for NPC name's is 32 characters.")); + return; + } + + builder.setName(event.getMessage()); + + player.sendMessage(F.main(_moduleName, "Set the name to " + F.name(ChatColor.translateAlternateColorCodes('&', builder.getName())) + "!")); + + player.sendMessage(F.main("Step 3", "Now type in chat the metadata of your NPC. If you don't want to set any metadata, type " + F.elem("null") + ".")); + } + else if (builder.getMetadata() == null) + { + String uppercase = event.getMessage().toUpperCase(); + + if (uppercase.equals("NULL")) + { + event.setMessage(uppercase); + } + + builder.setMetadata(event.getMessage()); + + if (builder.getType() == EntityType.PLAYER) + { + player.sendMessage(F.main("Step 4", "Now type in chat " + F.elem("Yes") + " if you would like your NPC to use your Minecraft Skin. If not, then say anything else")); + } + else + { + buildNPC(player, builder); + } + } + else if (builder.getType() == EntityType.PLAYER) + { + if (event.getMessage().toUpperCase().equals("YES")) + { + builder.setUseSkin(true); + player.sendMessage(F.main(_moduleName, "Set your NPC to use your Minecraft Skin!")); + } + else + { + player.sendMessage(F.main(_moduleName, "Set your NPC to not use your Minecraft Skin. You (or someone else) can always change it in the database.")); + } + + buildNPC(player, builder); + } + } + + private void buildNPC(Player player, NPCBuilder builder) + { + player.sendMessage(F.main(_moduleName, "Creating your NPC...")); + runSync(() -> builder.build(player, this)); + player.sendMessage(F.main(_moduleName, "Created your NPC!")); + _builders.remove(player); + } + + /** + * Handles {@link NPCDeleteCommand} and {@link NPCMoveCommand} data input. + */ + @EventHandler(priority = EventPriority.LOWEST) + public void npcInteract(NPCInteractEvent event) + { + Player player = event.getPlayer(); + NPC npc = event.getNpc(); + + if (!Recharge.Instance.usable(player, NPCDeleteCommand.RECHARGE_KEY)) + { + event.setCancelled(true); + deleteNPC(npc); + player.sendMessage(F.main(_moduleName, "Deleted " + F.name(npc.getEntity().getCustomName()) + " (" + F.elem(npc.getId()) + ").")); + Recharge.Instance.recharge(player, NPCDeleteCommand.RECHARGE_KEY); + } + else if (!Recharge.Instance.usable(player, NPCMoveCommand.RECHARGE_KEY)) + { + event.setCancelled(true); + teleport(npc, _teleportMap.remove(player)); + player.sendMessage(F.main(_moduleName, "Moved " + F.name(npc.getEntity().getCustomName()) + " (" + F.elem(npc.getId()) + ").")); + Recharge.Instance.recharge(player, NPCMoveCommand.RECHARGE_KEY); + } + } + + /** + * Prevents chunk unloading when there is an NPC in it. + */ + @EventHandler + public void chunkUnload(ChunkUnloadEvent event) + { + for (Entity entity : event.getChunk().getEntities()) + { + if (isNPC(entity)) + { + event.setCancelled(true); + return; + } + } + } + + /* + A collection of listeners that make sure NPCs don't die. + */ + + @EventHandler + public void entityCombust(EntityCombustEvent event) + { + if (isNPC(event.getEntity())) + { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void entityDamage(EntityDamageEvent event) + { + if (isNPC(event.getEntity())) + { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void entityDamage(EntityDamageByEntityEvent event) + { + NPC npc = getNPC(event.getEntity()); + + if (event.getDamager() instanceof Player && npc != null) + { + callInteractEvent((Player) event.getDamager(), npc, true); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void entityInteract(PlayerInteractEntityEvent event) + { + NPC npc = getNPC(event.getRightClicked()); + + if (npc != null) + { + event.setCancelled(true); + callInteractEvent(event.getPlayer(), npc, false); + } + } + + private void callInteractEvent(Player player, NPC npc, boolean leftClick) + { + UtilServer.CallEvent(new NPCInteractEvent(player, npc, leftClick)); + } + + @EventHandler + public void creatureKill(CreatureKillEntitiesEvent event) + { + event.GetEntities().removeIf(this::isNPC); + } + + /** + * @param metadata The metadata you wish to find all the NPCs of. + * @return A list of {@link NPC} that are unloaded (have no entity attached to them) and that have the metadata which + * starts with that specified. + */ + private List getUnloadedNPCs(String metadata) + { + return _npcs.stream() + .filter(npc -> npc.getMetadata().startsWith(metadata) && npc.getEntity() == null) + .collect(Collectors.toList()); + } + + /** + * @param entity The entity you want to get it's NPC of. + * @return The {@link NPC} representation of that entity or null if the entity is not an NPC. + */ + public NPC getNPC(Entity entity) + { + for (NPC npc : _npcs) + { + if (npc.getEntity() != null && npc.getEntity().equals(entity)) + { + return npc; + } + } + + return null; + } + + /** + * @param entity The entity you want to check. + * @return true if the entity is a {@link NPC}. + */ + private boolean isNPC(Entity entity) + { + return getNPC(entity) != null; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCRepository.java new file mode 100644 index 000000000..7858eeea2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCRepository.java @@ -0,0 +1,203 @@ +package mineplex.core.newnpc; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.EntityType; + +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.Column; +import mineplex.serverdata.database.column.ColumnDouble; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; + +/** + * A repository class that provides an interface for getting and saving NPCs. + */ +class NewNPCRepository extends RepositoryBase +{ + + /** + * A SQL statement that returns all entries form the table. + */ + private static final String GET_NPCS = "SELECT * FROM newNPCs;"; + /** + * A SQL statement that inserts an entry and returns the id field generated. + */ + private static final String INSERT_NPC = "INSERT INTO newNPCs (entity_type, name, world, x, y, z, yaw, pitch, in_hand, in_hand_data, helmet, chestplate, leggings, boots, metadata, skinValue, skinSignature) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + /** + * A SQL statement that deletes an entry with a specific id field. + */ + private static final String DELETE_NPC = "DELETE FROM newNPCs WHERE id=?;"; + /** + * A SQL statement that removes all entries from the table. + */ + private static final String CLEAR_NPCS = "DELETE FROM newNPCs;"; + /** + * A SQL statement that adjusts the location properties of an entry with a specific id field. + */ + private static final String MOVE_NPC = "UPDATE newNPCs SET world=?, x=?, y=?, z=?, yaw=?, pitch=? WHERE id=?"; + + NewNPCRepository() + { + super(DBPool.getAccount()); + } + + /** + * Executes the SQL query: + *

+ * {@value GET_NPCS} + *

+ * The values return are parsed into an instance of {@link NPC} or one of it's subclasses such as {@link PlayerNPC} + * if appropriate. + * + * @param response The consumer callback that supplies the list of NPCs. + */ + void getNPCs(Consumer> response) + { + executeQuery(GET_NPCS, resultSet -> + { + List npcs = new ArrayList<>(); + + // While there are more entries + while (resultSet.next()) + { + int id = resultSet.getInt("id"); + EntityType entityType = EntityType.valueOf(resultSet.getString("entity_type")); + String name = resultSet.getString("name"); + String worldName = resultSet.getString("world"); + double x = resultSet.getDouble("x"); + double y = resultSet.getDouble("y"); + double z = resultSet.getDouble("z"); + int yaw = resultSet.getInt("yaw"); + int pitch = resultSet.getInt("pitch"); + Material inHand = parseMaterial(resultSet.getString("in_hand")); + byte inHandData = resultSet.getByte("in_hand_data"); + Material helmet = parseMaterial(resultSet.getString("helmet")); + Material chestplate = parseMaterial(resultSet.getString("chestplate")); + Material leggings = parseMaterial(resultSet.getString("leggings")); + Material boots = parseMaterial(resultSet.getString("boots")); + String metadata = resultSet.getString("metadata"); + String skinValue = resultSet.getString("skinValue"); + String skinSignature = resultSet.getString("skinSignature"); + + NPC npc; + World world = Bukkit.getWorld(worldName); + + // If the world is not loaded on the server then don't add it to the list + if (world == null) + { + continue; + } + + // If the entity type is of player then the NPC must be specified as a PlayerNPC + if (entityType == EntityType.PLAYER) + { + npc = new PlayerNPC(id, name, new Location(world, x, y, z, yaw, pitch), inHand, inHandData, helmet, chestplate, leggings, boots, metadata, skinValue, skinSignature); + } + else + { + npc = new NPC(id, entityType, name, new Location(world, x, y, z, yaw, pitch), inHand, inHandData, helmet, chestplate, leggings, boots, metadata); + } + + npcs.add(npc); + } + + response.accept(npcs); + }); + } + + // Simply calls Material.valueOf, if invalid null + private Material parseMaterial(String material) + { + try + { + return Material.valueOf(material); + } + catch (IllegalArgumentException e) + { + return null; + } + } + + /** + * Executes the SQL insert: + *

+ * {@value INSERT_NPC} + *

+ * If the NPC does not have an id of -1, the insert will not be run. + * + * @param npc The NPC you want to insert into the database. + */ + void insertNPCIfNotExists(NPC npc) + { + // If the id isn't -1 then it has already been inserted + if (npc.getId() != -1) + { + return; + } + + Column[] columns = npc.toDatabaseQuery().toArray(new Column[0]); + executeInsert(INSERT_NPC, resultSet -> + { + // If successful + if (resultSet.next()) + { + // Set the NPC's id with that generated by the database + npc.setId(resultSet.getInt(1)); + } + }, columns); + } + + /** + * Executes the SQL insert: + *

+ * {@value DELETE_NPC} + *

+ * + * @param npc The NPC you want to delete. + */ + void deleteNPC(NPC npc) + { + executeUpdate(DELETE_NPC, new ColumnInt("id", npc.getId())); + } + + /** + * Executes the SQL insert: + *

+ * {@value CLEAR_NPCS} + *

+ */ + void clearNPCs() + { + executeUpdate(CLEAR_NPCS); + } + + /** + * Executes the SQL insert: + *

+ * {@value MOVE_NPC} + *

+ * + * @param npc The NPC you want to teleport. + * @param location The Location that you want to the npc to teleport to. + */ + void teleportNPC(NPC npc, Location location) + { + executeUpdate(MOVE_NPC, + new ColumnVarChar("world", 32, location.getWorld().getName()), + new ColumnDouble("x", location.getBlockX() + 0.5), + new ColumnDouble("y", location.getY()), + new ColumnDouble("z", location.getBlockZ() + 0.5), + new ColumnInt("yaw", (int) location.getYaw()), + new ColumnInt("pitch", (int) location.getPitch()), + new ColumnInt("id", npc.getId()) + ); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/PlayerNPC.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/PlayerNPC.java new file mode 100644 index 000000000..24a16c9f1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/PlayerNPC.java @@ -0,0 +1,96 @@ +package mineplex.core.newnpc; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.EntityEquipment; + +import com.mojang.authlib.GameProfile; + +import mineplex.core.Managers; +import mineplex.core.common.skin.SkinData; +import mineplex.core.disguise.DisguiseManager; +import mineplex.core.disguise.disguises.DisguisePlayer; +import mineplex.core.hologram.Hologram; +import mineplex.serverdata.database.column.Column; +import mineplex.serverdata.database.column.ColumnVarChar; + +public class PlayerNPC extends NPC +{ + + private static final DisguiseManager MANAGER = Managers.require(DisguiseManager.class); + + private final SkinData _skinData; + + private DisguisePlayer _disguise; + + public PlayerNPC(int id, String name, Location spawn, Material inHand, byte inHandData, Material helmet, Material chestplate, Material leggings, Material boots, String metadata, String skinValue, String skinSignature) + { + super(id, EntityType.ARMOR_STAND, name, spawn, inHand, inHandData, helmet, chestplate, leggings, boots, metadata); + + _skinData = new SkinData(skinValue, skinSignature); + } + + @Override + public LivingEntity spawnEntity() + { + LivingEntity entity = super.spawnEntity(); + + if (entity == null) + { + return null; + } + + GameProfile profile = new GameProfile(UUID.randomUUID(), SkinData.getUnusedSkullName()); + profile.getProperties().clear(); + profile.getProperties().put("textures", _skinData.getProperty()); + + DisguisePlayer player = new DisguisePlayer(entity, profile); + + EntityEquipment equipment = entity.getEquipment(); + player.setHeldItem(equipment.getItemInHand()); + player.setHelmet(equipment.getHelmet()); + player.setChestplate(equipment.getChestplate()); + player.setLeggings(equipment.getLeggings()); + player.setBoots(equipment.getBoots()); + + _disguise = player; + + // Ensure the entity is loaded before disguising + MANAGER.runSyncLater(() -> MANAGER.disguise(player), 20); + return entity; + } + + @Override + public Hologram getNameTag() + { + if (!_disguise.hasHologram()) + { + _disguise.getHologram().setText(getEntity().getCustomName()); + } + + return _disguise.getHologram(); + } + + @Override + public List> toDatabaseQuery() + { + List> columns = new ArrayList<>(super.toDatabaseQuery()); + + columns.set(0, new ColumnVarChar("entity_type", 32, EntityType.PLAYER.name())); + columns.set(15, new ColumnVarChar("skinValue", 400, _skinData.getProperty().getValue())); + columns.set(16, new ColumnVarChar("skinSignature", 700, _skinData.getProperty().getSignature())); + + return columns; + } + + public DisguisePlayer getDisguise() + { + return _disguise; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCBuildCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCBuildCommand.java new file mode 100644 index 000000000..783fd1def --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCBuildCommand.java @@ -0,0 +1,22 @@ +package mineplex.core.newnpc.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.newnpc.NewNPCManager; +import mineplex.core.newnpc.NewNPCManager.Perm; + +public class NPCBuildCommand extends CommandBase +{ + + NPCBuildCommand(NewNPCManager plugin) + { + super(plugin, Perm.BUILD_NPC_COMMAND, "builder"); + } + + @Override + public void Execute(Player caller, String[] args) + { + Plugin.createBuilder(caller); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCClearCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCClearCommand.java new file mode 100644 index 000000000..a9718c000 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCClearCommand.java @@ -0,0 +1,39 @@ +package mineplex.core.newnpc.command; + +import java.util.concurrent.TimeUnit; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.util.F; +import mineplex.core.newnpc.NewNPCManager; +import mineplex.core.newnpc.NewNPCManager.Perm; +import mineplex.core.recharge.Recharge; + +public class NPCClearCommand extends CommandBase +{ + + private static final String RECHARGE_KEY = "Clear NPCS"; + + NPCClearCommand(NewNPCManager plugin) + { + super(plugin, Perm.CLEAR_NPC_COMMAND, "clear"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (Recharge.Instance.usable(caller, RECHARGE_KEY)) + { + caller.sendMessage(F.main(Plugin.getName(), "Are you really sure you want to delete ALL NPCs? This will remove every one off every server.")); + caller.sendMessage(F.main(Plugin.getName(), "If you are sure then run " + F.elem("/npc clear") + " again within " + F.time("10 seconds")) + "."); + Recharge.Instance.useForce(caller, RECHARGE_KEY, TimeUnit.SECONDS.toMillis(10)); + return; + } + + caller.sendMessage(F.main(Plugin.getName(), "Deleting all NPCs...")); + Plugin.clearNPCS(true); + caller.sendMessage(F.main(Plugin.getName(), "Deleted all NPCs.")); + Recharge.Instance.recharge(caller, RECHARGE_KEY); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCCommand.java new file mode 100644 index 000000000..6a595e9ca --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCCommand.java @@ -0,0 +1,35 @@ +package mineplex.core.newnpc.command; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import mineplex.core.command.MultiCommandBase; +import mineplex.core.common.util.F; +import mineplex.core.newnpc.NewNPCManager; +import mineplex.core.newnpc.NewNPCManager.Perm; + +public class NPCCommand extends MultiCommandBase +{ + + public NPCCommand(NewNPCManager plugin) + { + super(plugin, Perm.NPC_COMMAND, "newnpc"); + + AddCommand(new NPCBuildCommand(plugin)); + AddCommand(new NPCDeleteCommand(plugin)); + AddCommand(new NPCClearCommand(plugin)); + AddCommand(new NPCRefreshCommand(plugin)); + AddCommand(new NPCMoveCommand(plugin)); + } + + @Override + protected void Help(Player caller, String[] args) + { + caller.sendMessage(F.main(Plugin.getName(), "Command List:")); + caller.sendMessage(F.help("/" + _aliasUsed + " builder", "Creates a new NPC using the builder.", ChatColor.DARK_RED)); + caller.sendMessage(F.help("/" + _aliasUsed + " delete", "Deletes an NPC.", ChatColor.DARK_RED)); + caller.sendMessage(F.help("/" + _aliasUsed + " clear", "Removes all NPCs permanently.", ChatColor.DARK_RED)); + caller.sendMessage(F.help("/" + _aliasUsed + " refresh", "Reloads all NPCs.", ChatColor.DARK_RED)); + caller.sendMessage(F.help("/" + _aliasUsed + " move", "Moves an NPC.", ChatColor.DARK_RED)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCDeleteCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCDeleteCommand.java new file mode 100644 index 000000000..658006bf1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCDeleteCommand.java @@ -0,0 +1,29 @@ +package mineplex.core.newnpc.command; + +import java.util.concurrent.TimeUnit; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.util.F; +import mineplex.core.newnpc.NewNPCManager; +import mineplex.core.newnpc.NewNPCManager.Perm; +import mineplex.core.recharge.Recharge; + +public class NPCDeleteCommand extends CommandBase +{ + + public static final String RECHARGE_KEY = "Delete NPC"; + + NPCDeleteCommand(NewNPCManager plugin) + { + super(plugin, Perm.DELETE_NPC_COMMAND, "delete"); + } + + @Override + public void Execute(Player caller, String[] args) + { + caller.sendMessage(F.main(Plugin.getName(), "Punch the NPC you wish to remove. You will have " + F.time("10 seconds") + " to do so.")); + Recharge.Instance.useForce(caller, RECHARGE_KEY, TimeUnit.SECONDS.toMillis(10)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCMoveCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCMoveCommand.java new file mode 100644 index 000000000..51d98ea18 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCMoveCommand.java @@ -0,0 +1,30 @@ +package mineplex.core.newnpc.command; + +import java.util.concurrent.TimeUnit; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.util.F; +import mineplex.core.newnpc.NewNPCManager; +import mineplex.core.newnpc.NewNPCManager.Perm; +import mineplex.core.recharge.Recharge; + +public class NPCMoveCommand extends CommandBase +{ + + public static final String RECHARGE_KEY = "Move NPC"; + + NPCMoveCommand(NewNPCManager plugin) + { + super(plugin, Perm.DELETE_NPC_COMMAND, "move"); + } + + @Override + public void Execute(Player caller, String[] args) + { + caller.sendMessage(F.main(Plugin.getName(), "Punch the NPC you wish to move to this location. You will have " + F.time("30 seconds") + " to do so.")); + Plugin.setPlayerTeleport(caller); + Recharge.Instance.useForce(caller, RECHARGE_KEY, TimeUnit.SECONDS.toMillis(30)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCRefreshCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCRefreshCommand.java new file mode 100644 index 000000000..3d953bf76 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/command/NPCRefreshCommand.java @@ -0,0 +1,25 @@ +package mineplex.core.newnpc.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.util.F; +import mineplex.core.newnpc.NewNPCManager; +import mineplex.core.newnpc.NewNPCManager.Perm; + +public class NPCRefreshCommand extends CommandBase +{ + + NPCRefreshCommand(NewNPCManager plugin) + { + super(plugin, Perm.REFRESH_NPC_COMMAND, "refresh"); + } + + @Override + public void Execute(Player caller, String[] args) + { + caller.sendMessage(F.main(Plugin.getName(), "Refreshing NPCs...")); + Plugin.runAsync(() -> Plugin.refreshNPCS()); + caller.sendMessage(F.main(Plugin.getName(), "Refreshed NPCs")); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/event/NPCInteractEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/event/NPCInteractEvent.java new file mode 100644 index 000000000..310c3e319 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/event/NPCInteractEvent.java @@ -0,0 +1,64 @@ +package mineplex.core.newnpc.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import mineplex.core.newnpc.NPC; + +public class NPCInteractEvent extends PlayerEvent implements Cancellable +{ + + private static final HandlerList _handlers = new HandlerList(); + + private final NPC _npc; + private final boolean _leftClick; + + private boolean _cancel; + + public NPCInteractEvent(Player who, NPC npc, boolean leftClick) + { + super(who); + + _npc = npc; + _leftClick = leftClick; + } + + public NPC getNpc() + { + return _npc; + } + + public boolean isLeftClick() + { + return _leftClick; + } + + public boolean isRightClick() + { + return !isLeftClick(); + } + + public void setCancelled(boolean cancel) + { + _cancel = cancel; + } + + public boolean isCancelled() + { + return _cancel; + } + + public static HandlerList getHandlerList() + { + return _handlers; + } + + @Override + public HandlerList getHandlers() + { + return getHandlerList(); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/event/NPCRefreshEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/event/NPCRefreshEvent.java new file mode 100644 index 000000000..a44937d4b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/event/NPCRefreshEvent.java @@ -0,0 +1,22 @@ +package mineplex.core.newnpc.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class NPCRefreshEvent extends Event +{ + + private static final HandlerList _handlers = new HandlerList(); + + public static HandlerList getHandlerList() + { + return _handlers; + } + + @Override + public HandlerList getHandlers() + { + return getHandlerList(); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java index 591235d34..9522eaaca 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java @@ -114,7 +114,7 @@ public class NpcManager extends MiniPlugin NPC_COMMAND, REFRESH_NPCS_COMMAND, } - + private final Creature _creature; private final List _npcs = new ArrayList<>(); private final Queue _queuedNpcs = new LinkedList<>(); @@ -140,17 +140,17 @@ public class NpcManager extends MiniPlugin require(DisguiseManager.class); try - { + { loadNpcs(); } catch (SQLException e) { e.printStackTrace(); } - + generatePermissions(); } - + private void generatePermissions() { PermissionGroup.ADMIN.setPermission(Perm.ADD_NPC_COMMAND, true, true); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/BabyFireworkEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/BabyFireworkEffect.java index fc85c203f..32c9ba6de 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/BabyFireworkEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/BabyFireworkEffect.java @@ -1,10 +1,9 @@ package mineplex.core.particleeffects; -import java.awt.Color; +import java.awt.*; import java.util.Random; import org.bukkit.Location; -import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.particles.ColoredParticle; @@ -23,14 +22,14 @@ public class BabyFireworkEffect extends Effect private Color[] _colors; private boolean _trail = true; - public BabyFireworkEffect(Location location, JavaPlugin javaPlugin, Color color) + public BabyFireworkEffect(Location location, Color color) { - this(location, javaPlugin, color, -1); + this(location, color, -1); } - public BabyFireworkEffect(Location location, JavaPlugin javaPlugin, Color color, int maxCount) + public BabyFireworkEffect(Location location, Color color, int maxCount) { - super(10, new EffectLocation(location), javaPlugin, 2); + super(10, new EffectLocation(location), 2); _fireworkColor = color; _fireworkLocation = location.clone(); if (color == null) @@ -43,9 +42,9 @@ public class BabyFireworkEffect extends Effect _maxCount = maxCount; } - public BabyFireworkEffect(Location location, JavaPlugin javaPlugin, Color... colors) + public BabyFireworkEffect(Location location, Color... colors) { - super(10, new EffectLocation(location), javaPlugin, 2); + super(10, new EffectLocation(location), 2); _fireworkLocation = location.clone(); _colors = colors; _fireworkColor = _colors[0]; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/BlowAKissEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/BlowAKissEffect.java index 066521459..35345f4ff 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/BlowAKissEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/BlowAKissEffect.java @@ -9,22 +9,18 @@ import org.bukkit.util.Vector; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilServer; -import mineplex.core.gadget.types.Gadget; public class BlowAKissEffect extends Effect { - private int _particles = 100; private int _count = 0; private Vector _vector; private Location _fixedLoc; - private Gadget _gadget; private Player _player; - public BlowAKissEffect(Player player, Location target, Gadget gadget) + public BlowAKissEffect(Player player, Location target) { - super(-1, new EffectLocation(player), gadget.Manager.getPlugin()); - _gadget = gadget; + super(-1, new EffectLocation(player)); _player = player; setTargetLocation(new EffectLocation(target)); } @@ -45,7 +41,8 @@ public class BlowAKissEffect extends Effect Vector link = targetLoc.toVector().subtract(location.toVector()); float length = (float) link.length(); link.normalize(); - _vector = link.multiply(length / _particles); + int particles = 100; + _vector = link.multiply(length / particles); _fixedLoc = location.clone().subtract(_vector); } for (int i = 0; i < 5; i++){ diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ChristmasTreeEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ChristmasTreeEffect.java index bc2da7ac4..8e7840481 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ChristmasTreeEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ChristmasTreeEffect.java @@ -1,12 +1,11 @@ package mineplex.core.particleeffects; -import java.awt.Color; +import java.awt.*; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.particles.ColoredParticle; import mineplex.core.common.util.particles.DustSpellColor; @@ -17,20 +16,17 @@ public class ChristmasTreeEffect extends Effect private Player _player; private JavaPlugin _plugin; - private int _count = 0; private double _currentRadius = 0; private double _currentY = 0; - private BabyFireworkEffect _babyFireworkEffect = null; private GadgetManager _manager; private static final double MAX_RADIUS = 1.; private static final double MAX_Y = 2.5; - public ChristmasTreeEffect(JavaPlugin plugin, Player player, GadgetManager manager) + public ChristmasTreeEffect(Player player, GadgetManager manager) { - super(-1, new EffectLocation(player), plugin, 5); + super(-1, new EffectLocation(player), 5); _player = player; - _plugin = plugin; _manager = manager; } @@ -50,7 +46,7 @@ public class ChristmasTreeEffect extends Effect { double radius = MAX_RADIUS - _currentRadius; _currentRadius += 0.1; - CircleEffect circleEffect = new CircleEffect(_plugin, _player.getLocation().clone().add(0, _currentY, 0), radius, Color.GREEN); + CircleEffect circleEffect = new CircleEffect(_player.getLocation().clone().add(0, _currentY, 0), radius, Color.GREEN); circleEffect.addRandomColor(Color.RED); circleEffect.addRandomColor(Color.YELLOW); circleEffect.start(); @@ -58,18 +54,13 @@ public class ChristmasTreeEffect extends Effect } else { - BabyFireworkEffect babyFireworkEffect = new BabyFireworkEffect(_player.getLocation().clone().add(0, MAX_Y + .5, 0), _plugin, Color.YELLOW, 1); + BabyFireworkEffect babyFireworkEffect = new BabyFireworkEffect(_player.getLocation().clone().add(0, MAX_Y + .5, 0), Color.YELLOW, 1); babyFireworkEffect.setTrail(false); babyFireworkEffect.start(); - _babyFireworkEffect = babyFireworkEffect; - _babyFireworkEffect.setCallback(new Callback() + babyFireworkEffect.setCallback(data -> { - @Override - public void run(Effect data) - { - _currentY = 0; - _currentRadius = 0; - } + _currentY = 0; + _currentRadius = 0; }); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CircleEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CircleEffect.java index 60d83be21..0d8afbf29 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CircleEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CircleEffect.java @@ -1,12 +1,11 @@ package mineplex.core.particleeffects; -import java.awt.Color; +import java.awt.*; import java.util.ArrayList; import java.util.List; import org.bukkit.Location; import org.bukkit.entity.Entity; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; import mineplex.core.common.util.UtilMath; @@ -30,36 +29,36 @@ public class CircleEffect extends Effect private static final double RANDOM_COLOR_CHANCE = 0.5; - public CircleEffect(JavaPlugin plugin, Location location, double radius, Color color) + public CircleEffect(Location location, double radius, Color color) { - super(-1, new EffectLocation(location), plugin); + super(-1, new EffectLocation(location)); _radius = radius; _color = color; } - public CircleEffect(JavaPlugin plugin, Location location, double radius, Color color, boolean instantly) + public CircleEffect(Location location, double radius, Color color, boolean instantly) { - this(plugin, location, radius, color); + this(location, radius, color); _instantly = instantly; } - public CircleEffect(JavaPlugin plugin, Entity entity, double radius, Color color, boolean instantly) + public CircleEffect(Entity entity, double radius, Color color, boolean instantly) { - super(-1, new EffectLocation(entity), plugin); + super(-1, new EffectLocation(entity)); _radius = radius; _color = color; _instantly = instantly; } - public CircleEffect(JavaPlugin plugin, Location location, double radius, Color color, boolean instantly, int particles) + public CircleEffect(Location location, double radius, Color color, boolean instantly, int particles) { - this(plugin, location, radius, color, instantly); + this(location, radius, color, instantly); _particles = particles; } - public CircleEffect(JavaPlugin plugin, Entity entity, double radius, Color color, boolean instantly, int particles) + public CircleEffect(Entity entity, double radius, Color color, boolean instantly, int particles) { - this(plugin, entity, radius, color, instantly); + this(entity, radius, color, instantly); _particles = particles; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CloverEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CloverEffect.java deleted file mode 100644 index 7f62e7100..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CloverEffect.java +++ /dev/null @@ -1,33 +0,0 @@ -package mineplex.core.particleeffects; - -import java.awt.Color; - -import org.bukkit.Location; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -import mineplex.core.common.shape.ShapeWings; -import mineplex.core.common.util.UtilParticle; - -public class CloverEffect extends Effect -{ - - private ShapeWings _cloverBlack = new ShapeWings(UtilParticle.ParticleType.RED_DUST.particleName, new Vector(1, 1, 1), 1, 0, '#', ShapeWings.DEFAULT_ROTATION, ShapeWings.FOUR_LEAF_CLOVER); - private ShapeWings _cloverDarkGreen = new ShapeWings(UtilParticle.ParticleType.RED_DUST.particleName, new Vector(1, 1, 1), 1, 0, '%', ShapeWings.DEFAULT_ROTATION, ShapeWings.FOUR_LEAF_CLOVER); - private ShapeWings _cloverGreen = new ShapeWings(UtilParticle.ParticleType.RED_DUST.particleName, new Vector(1, 1, 1), 1, 0, '*', ShapeWings.DEFAULT_ROTATION, ShapeWings.FOUR_LEAF_CLOVER); - - public CloverEffect(JavaPlugin plugin, Location location) - { - super(-1, new EffectLocation(location), plugin, 1); - } - - @Override - public void runEffect() - { - Location location = getEffectLocation().getLocation(); - _cloverBlack.displayColored(location, Color.BLACK); - _cloverDarkGreen.displayColored(location, new Color(0, 100, 0)); - _cloverGreen.displayColored(location, Color.GREEN); - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java index 21a4b2681..433b85e1a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java @@ -1,6 +1,6 @@ package mineplex.core.particleeffects; -import java.awt.Color; +import java.awt.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -8,7 +8,6 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; import mineplex.core.common.util.RGBData; @@ -31,9 +30,9 @@ public class ColoredCircleEffect extends Effect private static final int PARTICLES_PER_CIRCLE = 20; - public ColoredCircleEffect(JavaPlugin plugin, Entity entity, double radius, boolean instantly, Color... colors) + public ColoredCircleEffect(Entity entity, double radius, boolean instantly, Color... colors) { - super(-1, new EffectLocation(entity), plugin); + super(-1, new EffectLocation(entity)); _radius = radius; _colors = new ArrayList<>(); _instantly = instantly; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/Effect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/Effect.java index f72a32fbf..9dd7397b2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/Effect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/Effect.java @@ -1,72 +1,70 @@ package mineplex.core.particleeffects; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; import mineplex.core.common.util.Callback; -import mineplex.core.particleeffects.events.EffectStopEvent; +import mineplex.core.common.util.UtilServer; public abstract class Effect { - public int _ticksToRun = 20, _ticks = 0, _task; - public long _delay = 1; - public EffectLocation _effectLocation; - public EffectLocation _targetLocation; - protected JavaPlugin _javaPlugin; + private int _ticksToRun = 20, _ticks = 0; + private BukkitTask _task; + protected long _period = 1; + protected EffectLocation _effectLocation; + private EffectLocation _targetLocation; private boolean _running = false; private Callback _callback; - public Effect(int ticks, EffectLocation effectLocation, JavaPlugin javaPlugin) + public Effect(int ticks, EffectLocation effectLocation) { _ticksToRun = ticks; _effectLocation = effectLocation; - _javaPlugin = javaPlugin; } - public Effect(int ticks, EffectLocation effectLocation, JavaPlugin javaPlugin, long delay) + public Effect(int ticks, EffectLocation effectLocation, long delay) { _ticksToRun = ticks; _effectLocation = effectLocation; - _javaPlugin = javaPlugin; - _delay = delay; + _period = delay; } public void start() { onStart(); _running = true; - _task = Bukkit.getScheduler().scheduleSyncRepeatingTask(_javaPlugin, new Runnable() + _task = UtilServer.runSyncTimer(() -> { - @Override - public void run() - { - runEffect(); - update(); - } - }, 1, _delay); + runEffect(); + update(); + }, 1, _period); } public void stop() { _running = false; - Bukkit.getScheduler().cancelTask(_task); - EffectStopEvent effectStopEvent = new EffectStopEvent(this); - Bukkit.getPluginManager().callEvent(effectStopEvent); + _task.cancel(); + if (_callback != null) + { _callback.run(this); + } + onStop(); } - public void onStart(){}; + public void onStart(){} - public void onStop(){}; + public void onStop(){} private void update() { _ticks++; + if (_ticks == _ticksToRun) - Bukkit.getScheduler().cancelTask(_task); + { + _task.cancel(); + } } public boolean isRunning() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/FreedomFireworkEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/FreedomFireworkEffect.java index c89fd92cf..6854f7b85 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/FreedomFireworkEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/FreedomFireworkEffect.java @@ -10,13 +10,13 @@ public class FreedomFireworkEffect extends Effect { private Color _fireworkColor = Color.RED; - private int _count = 0, _max = -1; + private int _count = 0; private boolean _increaseY; private Entity _playerEntity; - public FreedomFireworkEffect(Entity entity, JavaPlugin javaPlugin, boolean increaseY) + public FreedomFireworkEffect(Entity entity, boolean increaseY) { - super(-1, new EffectLocation(entity), javaPlugin, 15); + super(-1, new EffectLocation(entity), 15); _increaseY = increaseY; _playerEntity = entity; } @@ -29,13 +29,13 @@ public class FreedomFireworkEffect extends Effect this.stop(); return; } - if (_count == _max) + if (_count == -1) { this.stop(); return; } Location location = _effectLocation.getLocation().clone().add(0, (_increaseY) ? 1 : 0, 0); - BabyFireworkEffect babyFireworkEffect = new BabyFireworkEffect(location, _javaPlugin, _fireworkColor); + BabyFireworkEffect babyFireworkEffect = new BabyFireworkEffect(location, _fireworkColor); babyFireworkEffect.start(); _count++; if (_fireworkColor == null) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/FreedomTrailEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/FreedomTrailEffect.java index 373b6c570..9bedfd2d1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/FreedomTrailEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/FreedomTrailEffect.java @@ -1,10 +1,9 @@ package mineplex.core.particleeffects; -import java.awt.Color; +import java.awt.*; import org.bukkit.FireworkEffect; import org.bukkit.entity.Entity; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; import mineplex.core.common.util.UtilFirework; @@ -20,9 +19,9 @@ public class FreedomTrailEffect extends Effect private boolean _isJumping = false; private Entity _entity; - public FreedomTrailEffect(Entity entity, JavaPlugin javaPlugin) + public FreedomTrailEffect(Entity entity) { - super(-1, new EffectLocation(entity), javaPlugin); + super(-1, new EffectLocation(entity)); _entity = entity; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/HalloweenSmashedEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/HalloweenSmashedEffect.java deleted file mode 100644 index f99fe1ad8..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/HalloweenSmashedEffect.java +++ /dev/null @@ -1,26 +0,0 @@ -package mineplex.core.particleeffects; - -import org.bukkit.FireworkEffect; -import org.bukkit.Location; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.common.util.UtilFirework; - -public class HalloweenSmashedEffect extends Effect -{ - - private FireworkEffect _fireworkEffect; - - public HalloweenSmashedEffect(Location location, FireworkEffect fireworkEffect, JavaPlugin javaPlugin) - { - super(140, new EffectLocation(location), javaPlugin, 5); - _fireworkEffect = fireworkEffect; - } - - @Override - public void runEffect() - { - UtilFirework.playFirework(_effectLocation.getLocation(), _fireworkEffect); - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LineEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LineEffect.java deleted file mode 100644 index 15a55f406..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LineEffect.java +++ /dev/null @@ -1,52 +0,0 @@ -package mineplex.core.particleeffects; - -import java.awt.Color; - -import org.bukkit.Location; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.particles.ColoredParticle; -import mineplex.core.common.util.particles.DustSpellColor; - -public class LineEffect extends Effect -{ - - private int _particles = 100; - private Color _color; - private int _count = 0; - private Vector _vector; - private Location _fixedLoc; - - public LineEffect(JavaPlugin plugin, Location location, Location target, Color color) - { - super(-1, new EffectLocation(location), plugin); - setTargetLocation(new EffectLocation(target)); - _color = color; - } - - @Override - public void runEffect() - { - Location location = _effectLocation.getFixedLocation().clone().add(0, 1, 0); - if (_vector == null) - { - Location targetLoc = getTargetLocation().getFixedLocation().clone(); - Vector link = targetLoc.toVector().subtract(location.toVector()); - float length = (float) link.length(); - link.normalize(); - Vector vector = link.multiply(length / _particles); - _vector = vector; - _fixedLoc = location.clone().subtract(_vector); - } - ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, - new DustSpellColor(_color), _effectLocation.getLocation().clone()); - _fixedLoc.add(_vector); - if (_count == _particles) - { - stop(); - } - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LoveDoctorEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LoveDoctorEffect.java index 85c293e6f..fad8f33df 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LoveDoctorEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LoveDoctorEffect.java @@ -18,17 +18,15 @@ import mineplex.core.gadget.types.Gadget; public class LoveDoctorEffect extends Effect { - private int _particles = 100; private int _count = 0; private Vector _vector; private Location _fixedLoc; private Gadget _gadget; private Player _player; - private boolean _forceStop = false; public LoveDoctorEffect(Player player, Location target, Gadget gadget) { - super(-1, new EffectLocation(player), gadget.Manager.getPlugin()); + super(-1, new EffectLocation(player)); _gadget = gadget; _player = player; setTargetLocation(new EffectLocation(target)); @@ -50,7 +48,8 @@ public class LoveDoctorEffect extends Effect Vector link = targetLoc.toVector().subtract(location.toVector()); float length = (float) link.length(); link.normalize(); - _vector = link.multiply(length / _particles); + int particles = 100; + _vector = link.multiply(length / particles); _fixedLoc = location.clone().subtract(_vector); } for (int i = 0; i < 5; i++){ @@ -63,7 +62,6 @@ public class LoveDoctorEffect extends Effect } else if (_count >= 1000) { - _forceStop = true; stop(); } _count += 5; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LoveDoctorHitEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LoveDoctorHitEffect.java index 5b7678fa1..88a325855 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LoveDoctorHitEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LoveDoctorHitEffect.java @@ -11,7 +11,7 @@ public class LoveDoctorHitEffect extends Effect public LoveDoctorHitEffect(Player player) { - super(200, new EffectLocation(player.getLocation()), UtilServer.getPlugin()); + super(200, new EffectLocation(player.getLocation())); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/MetalManEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/MetalManEffect.java index d9382e15e..c960e4969 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/MetalManEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/MetalManEffect.java @@ -22,7 +22,6 @@ import mineplex.core.gadget.types.Gadget; public class MetalManEffect extends Effect { - private int _particles = 100; private int _color; private int _count = 0; private Vector _vector; @@ -34,7 +33,7 @@ public class MetalManEffect extends Effect public MetalManEffect(Location location, Location target, int color, Gadget gadget, Player player) { - super(-1, new EffectLocation(player), gadget.Manager.getPlugin()); + super(-1, new EffectLocation(player)); _color = color; _gadget = gadget; _player = player; @@ -57,7 +56,8 @@ public class MetalManEffect extends Effect Vector link = targetLoc.toVector().subtract(location.toVector()); float length = (float) link.length(); link.normalize(); - Vector vector = link.multiply(length / _particles); + int particles = 100; + Vector vector = link.multiply(length / particles); _vector = vector; _fixedLoc = location.clone().subtract(_vector); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/NewYearEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/NewYearEffect.java deleted file mode 100644 index 114dd4c50..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/NewYearEffect.java +++ /dev/null @@ -1,155 +0,0 @@ -package mineplex.core.particleeffects; - -public class NewYearEffect //extends Effect -{ - - /*private static final int SECONDS_IN_A_MINUTE = 60; - - private final Location _ballLocation, _clockLocation, _timerLocation, _timerLocationTen; - - private int _seconds = 90; - private Collection _blocks = new ArrayList<>(); - private List _schematics = new ArrayList<>(); - private boolean _placed = false; - private int _currentRun = 0; - - public NewYearEffect(JavaPlugin plugin, Location location) - { - super(-1, new EffectLocation(location), plugin, 10); - _ballLocation = new Location(location.clone().getWorld(), 0, 71, 38); - _clockLocation = _ballLocation.clone().add(-12, 0, -15); - _timerLocation = _clockLocation.clone().add(19, 7, 0); - _timerLocationTen = _timerLocation.clone().add(1, 0, 0); - try - { - for (int i = 0; i <= 10; i++) - { - Schematic schematic = UtilSchematic.loadSchematic(new File("../../update/schematic/NewYearBall" + i + ".schematic")); - _schematics.add(i, schematic); - } - Schematic schematic = UtilSchematic.loadSchematic(new File("../../update/schematic/NewYearClock.schematic")); - _schematics.add(11, schematic); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void runEffect() - { - if (!_placed) - { - pasteSchematic(10, true); - _placed = true; - } - - if (_seconds == -60) - { - stop(); - return; - } - - if (_seconds == 0) - { - List fireworkLocations = new ArrayList<>(); - List fixedFireworkLocations = new ArrayList<>(); - int[][] fireworkCoords = new int[][] - { - {0, 77, -37}, - {-6, 71, 17}, - {6, 71, 17}, - {12, 71, 7}, - {-12, 71, 7}, - {5, 71, 92}, - {-7, 71, 92}, - {-9, 103, 37}, - {13, 107, 40} - }; - fireworkLocations.addAll(Arrays.asList(fireworkCoords)); - int[][] fixedFireworkCoords = new int[][] - { - {0, 80, 0}, - {0, 80, -32}, - {6, 80, -26}, - {-6, 80, -26} - }; - fixedFireworkLocations.addAll(Arrays.asList(fixedFireworkCoords)); - NewYearFireworkEffect newYearFireworkEffect = new NewYearFireworkEffect(_javaPlugin, fireworkLocations, fixedFireworkLocations, getEffectLocation().getFixedLocation().getWorld()); - newYearFireworkEffect.start(); - } - - if (_currentRun % 2 != 0 && _seconds >= 0) - { - //Format seconds - int totalMinutes = 0, totalSeconds = 0, placeholder; - placeholder = _seconds; - if (_seconds > SECONDS_IN_A_MINUTE) - { - while (placeholder > SECONDS_IN_A_MINUTE) - { - totalMinutes++; - placeholder -= SECONDS_IN_A_MINUTE; - } - } - totalSeconds = placeholder; - String formatted = String.format("%02d:%02d", totalMinutes, totalSeconds); - if (_seconds <= 10) - { - formatted = "| " + _seconds + " |"; - pasteSchematic(_seconds, false); - } - updateTimer(formatted, (byte) 0); - _seconds--; - } - else if (_seconds >= 0 && _seconds <= 10) - { - updateTimer("| " + _seconds + " |", (byte) 14); - } - else if (_currentRun % 2 != 0 && _seconds < 0) - { - updateTimer("2017!", (byte) 0); - _seconds--; - } - else if (_seconds < 0) - { - updateTimer("2017!", (byte) 14); - } - - _currentRun++; - } - - @Override - public void onStop() - { - _blocks.forEach(b -> b.setType(Material.AIR)); - _blocks.clear(); - updateTimer("2017!", (byte) 14); - } - - private void pasteSchematic(int second, boolean pasteClock) - { - Schematic schematic = _schematics.get(second); - if (schematic != null) - { - schematic.paste(_ballLocation, false, true); - - if (pasteClock) - { - Schematic clockSchematic = _schematics.get(11); - clockSchematic.paste(_clockLocation); - } - } - } - - private void updateTimer(String time, byte color) - { - // Clears previous blocks - _blocks.forEach(b -> b.setType(Material.AIR)); - - Collection blocks = UtilBlockText.MakeText(time, (_seconds <= 10 && _seconds >= 0) ? _timerLocationTen : _timerLocation, BlockFace.WEST, Material.STAINED_CLAY.getId(), color, UtilBlockText.TextAlign.LEFT, false); - _blocks = blocks; - }*/ - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/NewYearFireworkEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/NewYearFireworkEffect.java deleted file mode 100644 index 58e0df200..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/NewYearFireworkEffect.java +++ /dev/null @@ -1,46 +0,0 @@ -package mineplex.core.particleeffects; - -public class NewYearFireworkEffect //extends Effect -{ - - /*private static final int MAX_TICKS = 1200; - - private List _locations = new ArrayList<>(); - private List _fixedLocations = new ArrayList<>(); - private int _ticks = 0; - - public NewYearFireworkEffect(JavaPlugin plugin, List locations, List fixedLocations, World world) - { - super(-1, null, plugin, 5); - for (int[] locCoords : locations) - { - _locations.add(new Location(world, locCoords[0], locCoords[1], locCoords[2])); - } - for (int[] locCoords : fixedLocations) - { - _locations.add(new Location(world, locCoords[0], locCoords[1], locCoords[2])); - } - } - - @Override - public void runEffect() - { - for (int i = 0; i < 5; i++) - { - int r = UtilMath.random.nextInt(_locations.size() - 1); - Location location = _locations.get(r); - UtilFirework.launchFirework(location, UtilFirework.getRandomFireworkEffect(true, 2, 2), - new Vector((Math.random() - 0.5) * 0.05, 0.1, (Math.random() - 0.5) * 0.05), 1); - } - for (Location location : _fixedLocations) - { - UtilFirework.launchFirework(location, UtilFirework.getRandomFireworkEffect(true, 2, 2), - new Vector((Math.random() - 0.5) * 0.05, 0.1, (Math.random() - 0.5) * 0.05), 1); - } - _ticks += 5; - if (_ticks >= MAX_TICKS) - { - stop(); - } - }*/ -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/RainbowTauntEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/RainbowTauntEffect.java index a571a3f0c..64820cafd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/RainbowTauntEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/RainbowTauntEffect.java @@ -24,9 +24,9 @@ public class RainbowTauntEffect extends Effect private static final Color INDIGO = new Color(75, 0, 130); private static final Color VIOLET = new Color(143, 0, 255); - public RainbowTauntEffect(Location start, JavaPlugin javaPlugin) + public RainbowTauntEffect(Location start) { - super(16, new EffectLocation(start), javaPlugin, 5); + super(16, new EffectLocation(start), 5); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/RainbowTrailEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/RainbowTrailEffect.java index 04652f71e..892674160 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/RainbowTrailEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/RainbowTrailEffect.java @@ -35,9 +35,9 @@ public class RainbowTrailEffect extends Effect private Color _color = _red; - public RainbowTrailEffect(Entity entity, JavaPlugin javaPlugin, HashSet items) + public RainbowTrailEffect(Entity entity, HashSet items) { - super(-1, new EffectLocation(entity), javaPlugin); + super(-1, new EffectLocation(entity)); _entity = entity; _items = items; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/TextEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/TextEffect.java index 93c5a8883..7e8439895 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/TextEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/TextEffect.java @@ -4,40 +4,44 @@ import java.awt.*; import java.awt.image.BufferedImage; import org.bukkit.Location; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilText; -import mineplex.core.common.util.particles.ColoredParticle; -import mineplex.core.common.util.particles.DustSpellColor; public class TextEffect extends Effect { private static final double IMAGE_SIZE = 0.2; + private static final Font FONT = new Font("Tahoma", Font.PLAIN, 16); + + private final boolean _realTime; + private final boolean _invert; + private final ParticleType _particleType; private String _text; - private Font _font; - private boolean _realtime; - private boolean _invert; private BufferedImage _bufferedImage; - private ColoredParticle _coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, new DustSpellColor(Color.GREEN), null); - - public TextEffect(JavaPlugin plugin, int ticks, String text, Location location, boolean realtime, boolean invert) throws Exception + public TextEffect(int ticks, String text, Location location, boolean realTime, boolean invert, ParticleType particleType) { - super(ticks, new EffectLocation(location), plugin); + super(ticks, new EffectLocation(location)); + _text = text; - _font = new Font("Tahoma", Font.PLAIN, 16); - _realtime = realtime; + _realTime = realTime; _invert = invert; + _particleType = particleType; + _period = 4; } public void setText(String text) { - if (!_realtime) + if (!_realTime) + { return; + } _text = text; } @@ -45,42 +49,38 @@ public class TextEffect extends Effect @Override public void runEffect() { - if (_text == null || _font == null) + if (_text == null) { stop(); return; } - if (_bufferedImage == null || _realtime) + + if (_bufferedImage == null || _realTime) { - _bufferedImage = UtilText.stringToBufferedImage(_font, _text); + _bufferedImage = UtilText.stringToBufferedImage(FONT, _text); } - int color = 0; + + int color; + for (int y = 0; y < _bufferedImage.getHeight(); y++) { for (int x = 0; x < _bufferedImage.getWidth(); x++) { color = _bufferedImage.getRGB(x, y); + if (!_invert && java.awt.Color.black.getRGB() != color) + { continue; + } else if (_invert && java.awt.Color.black.getRGB() == color) + { continue; + } Vector vector = new Vector((float) _bufferedImage.getWidth() / 2 - x, (float) _bufferedImage.getHeight() / 2 - y, 0).multiply(IMAGE_SIZE); - vector = rotateAroundAxisY(vector, -_effectLocation.getFixedLocation().getYaw() * (Math.PI / 180)); - _coloredParticle.setLocation(_effectLocation.getFixedLocation().clone().add(vector)); - _coloredParticle.display(); + vector = UtilAlg.rotateAroundYAxis(vector, -_effectLocation.getFixedLocation().getYaw() * (Math.PI / 180)); + UtilParticle.PlayParticleToAll(_particleType, _effectLocation.getFixedLocation().clone().add(vector), 0, 0, 0, 0.0001F, 1, ViewDist.LONG); } } } - - private Vector rotateAroundAxisY(Vector v, double angle) - { - double x, z, cos, sin; - cos = Math.cos(angle); - sin = Math.sin(angle); - x = v.getX() * cos + v.getZ() * sin; - z = v.getX() * -sin + v.getZ() * cos; - return v.setX(x).setZ(z); - } - } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/WitchParticleEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/WitchParticleEffect.java index f53da0be7..063fbd431 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/WitchParticleEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/WitchParticleEffect.java @@ -1,7 +1,6 @@ package mineplex.core.particleeffects; import org.bukkit.Location; -import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilServer; @@ -9,10 +8,10 @@ import mineplex.core.common.util.UtilServer; public class WitchParticleEffect extends Effect { - public WitchParticleEffect(Location location, JavaPlugin javaPlugin) + public WitchParticleEffect(Location location) { - super(-1, new EffectLocation(location), javaPlugin); - _delay = 5; + super(-1, new EffectLocation(location)); + _period = 5; } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/events/EffectStopEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/events/EffectStopEvent.java deleted file mode 100644 index ac29342af..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/events/EffectStopEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -package mineplex.core.particleeffects.events; - -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -import mineplex.core.particleeffects.Effect; - -public class EffectStopEvent extends Event -{ - private static final HandlerList handlers = new HandlerList(); - - private Effect _effect; - - public EffectStopEvent(Effect effect) - { - _effect = effect; - } - - public Effect getEffect() - { - return _effect; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/commands/SendCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java similarity index 100% rename from Plugins/Mineplex.Core/src/mineplex/core/portal/commands/SendCommand.java rename to Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/commands/ServerCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java similarity index 100% rename from Plugins/Mineplex.Core/src/mineplex/core/portal/commands/ServerCommand.java rename to Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/profile/ProfileManager.java b/Plugins/Mineplex.Core/src/mineplex/core/profile/ProfileManager.java new file mode 100644 index 000000000..e4fdeac8b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/profile/ProfileManager.java @@ -0,0 +1,297 @@ +package mineplex.core.profile; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; + +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.mojang.authlib.GameProfile; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClient; +import mineplex.core.account.CoreClientManager; +import mineplex.core.achievement.Achievement; +import mineplex.core.achievement.AchievementManager; +import mineplex.core.achievement.leveling.LevelingManager; +import mineplex.core.achievement.leveling.rewards.LevelReward; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.skin.SkinData; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilTime; +import mineplex.core.disguise.DisguiseManager; +import mineplex.core.disguise.disguises.DisguisePlayer; +import mineplex.core.donation.DonationManager; +import mineplex.core.donation.Donor; +import mineplex.core.friend.FriendManager; +import mineplex.core.friend.data.FriendStatus; +import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.Hologram.HologramTarget; +import mineplex.core.newnpc.NPC; +import mineplex.core.newnpc.NewNPCManager; +import mineplex.core.quests.Quest; +import mineplex.core.quests.QuestClientData; +import mineplex.core.quests.QuestManager; +import mineplex.core.titles.Titles; +import mineplex.core.titles.tracks.TrackManager; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.utils.UtilGameProfile; + +@ReflectivelyCreateMiniPlugin +public class ProfileManager extends MiniPlugin +{ + + private static final String NPC_METADATA = "PROFILE"; + + private final AchievementManager _achievementManager; + private final CoreClientManager _clientManager; + private final DisguiseManager _disguiseManager; + private final DonationManager _donationManager; + private final FriendManager _friendManager; + private final LevelingManager _levelingManager; + private final NewNPCManager _npcManager; + private final QuestManager _questManager; + private final Titles _titles; + private final TrackManager _trackManager; + + private final Map _hologramMap; + + private final List> _rotationLines; + private int _lineIndex; + + private NPC _profileNPC; + + private ProfileManager() + { + super("Profile"); + + _achievementManager = require(AchievementManager.class); + _clientManager = require(CoreClientManager.class); + _disguiseManager = require(DisguiseManager.class); + _donationManager = require(DonationManager.class); + _friendManager = require(FriendManager.class); + _levelingManager = require(LevelingManager.class); + _npcManager = require(NewNPCManager.class); + _questManager = require(QuestManager.class); + _titles = require(Titles.class); + _trackManager = require(TrackManager.class); + + _hologramMap = new HashMap<>(); + + _rotationLines = Arrays.asList( + // Achievements + player -> + { + int completed = 0; + + for (Achievement achievement : Achievement.values()) + { + if (_achievementManager.get(player, achievement).getLevel() >= achievement.getMaxLevel()) + { + completed++; + } + } + + return "Achievements: " + C.cYellow + completed + C.cGray + "/" + C.cGreen + Achievement.values().length; + }, + // Friends + player -> + { + int online = 0; + int total = 0; + + for (FriendStatus status : _friendManager.Get(player).getFriends()) + { + if (status.Online) + { + online++; + } + + total++; + } + + return "Friends: " + C.cYellow + online + C.cGray + "/" + C.cGreen + total; + }, + // Missions + player -> + { + QuestClientData data = _questManager.Get(player); + int available = 5; + long questExpire = TimeUnit.DAYS.toMillis(1); + + for (int id : _questManager.getCurrentQuests()) + { + if (data.getQuestFromAll(id) == null) + { + continue; + } + + Quest quest = data.getQuestFromAll(id); + + if (quest.isActive()) + { + available--; + } + + if (!UtilTime.elapsed(quest.getLastCompleted(), questExpire)) + { + available--; + } + } + + return "Missions: " + C.cYellow + available + C.cGreen + " Available"; + }, + // Level Rewards + player -> + { + int available = 0; + + for (Entry entry : _levelingManager.getLevelRewards()) + { + if (_levelingManager.canClaim(player, entry.getKey()) && !_levelingManager.hasClaimed(player, entry.getKey())) + { + available++; + } + } + + return "Level Rewards: " + C.cYellow + available + C.cGreen + " Available"; + } + ); + + spawnNPC(); + } + + private void spawnNPC() + { + _npcManager.spawnNPCs(NPC_METADATA, npc -> _profileNPC = npc); + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + if (_profileNPC == null) + { + return; + } + + runSyncLater(() -> + { + Player player = event.getPlayer(); + GameProfile profile = UtilGameProfile.getGameProfile(player); + + try + { + UtilGameProfile.changeId(profile, UUID.randomUUID()); + UtilGameProfile.changeName(profile, SkinData.getUnusedSkullName()); + } + catch (ReflectiveOperationException e) + { + e.printStackTrace(); + return; + } + + DisguisePlayer playerDisguise = new DisguisePlayer(_profileNPC.getEntity(), profile); + playerDisguise.getHologram() + .setHologramTarget(HologramTarget.WHITELIST) + .addPlayer(player); + _hologramMap.put(player, playerDisguise.getHologram()); + updateHologram(player, playerDisguise.getHologram()); + _disguiseManager.disguise(playerDisguise, viewer -> viewer.equals(player)); + }, 20); + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + _hologramMap.remove(event.getPlayer()).stop(); + } + + @EventHandler + public void updateHologram(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW || _profileNPC == null) + { + return; + } + + World world = _profileNPC.getEntity().getWorld(); + + _hologramMap.forEach((player, hologram) -> + { + if (!player.getWorld().equals(world)) + { + return; + } + + updateHologram(player, hologram); + }); + + if (++_lineIndex == _rotationLines.size()) + { + _lineIndex = 0; + } + } + + private void updateHologram(Player player, Hologram hologram) + { + CoreClient client = _clientManager.Get(player); + Donor donor = _donationManager.Get(player); + Function line = _rotationLines.get(_lineIndex); + + + hologram.setText( + C.cGoldB + "MY PROFILE", + "Rank: " + client.getPrimaryGroup().getDisplay(true, true, true, true), + "Gems: " + C.cGreen + donor.getBalance(GlobalCurrency.GEM), + "Shards: " + C.cAqua + donor.getBalance(GlobalCurrency.TREASURE_SHARD), + "Level: " + Achievement.getExperienceString(_achievementManager.getMineplexLevelNumber(player, false)), + line.apply(player) + ); + } + + public AchievementManager getAchievementManager() + { + return _achievementManager; + } + + public CoreClientManager getClientManager() + { + return _clientManager; + } + + public DonationManager getDonationManager() + { + return _donationManager; + } + + public FriendManager getFriendManager() + { + return _friendManager; + } + + public LevelingManager getLevelingManager() + { + return _levelingManager; + } + + public Titles getTitles() + { + return _titles; + } + + public TrackManager getTrackManager() + { + return _trackManager; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/profile/ProfileShop.java b/Plugins/Mineplex.Core/src/mineplex/core/profile/ProfileShop.java new file mode 100644 index 000000000..0e4d4dfbc --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/profile/ProfileShop.java @@ -0,0 +1,24 @@ +package mineplex.core.profile; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.profile.ui.ProfileMainPage; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; + +public class ProfileShop extends ShopBase +{ + + public ProfileShop(ProfileManager plugin, CoreClientManager clientManager, DonationManager donationManager, String name) + { + super(plugin, clientManager, donationManager, name); + } + + @Override + protected ShopPageBase> buildPagesFor(Player player) + { + return new ProfileMainPage(getPlugin(), this, player, getPlugin().getAchievementManager().getStatsManager().Get(player)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/profile/ui/ProfileMainPage.java b/Plugins/Mineplex.Core/src/mineplex/core/profile/ui/ProfileMainPage.java new file mode 100644 index 000000000..d1236cae6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/profile/ui/ProfileMainPage.java @@ -0,0 +1,96 @@ +package mineplex.core.profile.ui; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.achievement.Achievement; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.profile.ProfileManager; +import mineplex.core.profile.ProfileShop; +import mineplex.core.shop.item.IButton; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.core.stats.PlayerStats; +import mineplex.core.titles.tracks.Track; +import mineplex.core.titles.tracks.TrackTier; + +public class ProfileMainPage extends ShopPageBase +{ + + private static final String NO_TITLE = C.cGray + "No Title"; + private static final ItemStack STATS_ITEM = new ItemBuilder(Material.PAPER) + .setTitle(C.cGoldB + "Stats") + .addLore("", "View your Global and Game", "Statistics.", "", C.cGreen + "Click to open this page.") + .build(); + + private final PlayerStats _stats; + + public ProfileMainPage(ProfileManager plugin, ProfileShop shop, Player player, PlayerStats stats) + { + super(plugin, shop, plugin.getClientManager(), plugin.getDonationManager(), "Your Profile", player); + + _stats = stats; + } + + @Override + protected void buildPage() + { + addProfileButton(); + } + + private void addProfileButton() + { + ItemBuilder builder = new ItemBuilder(Material.SKULL_ITEM, (byte) 3); + builder.setPlayerHead(_client.getName()); + + int level = Achievement.GLOBAL_MINEPLEX_LEVEL.getLevelData(_stats.getStat(Achievement.GLOBAL_MINEPLEX_LEVEL.getStats()[0])).getLevel(); + builder.setTitle(Achievement.getExperienceString(level) + " " + _client.getPrimaryGroup().getDisplay(true, true, true, true) + " " + C.cYellow + _client.getName()); + + Track track = _plugin.getTitles().getActiveTrack(_player); + + if (track != null) + { + TrackTier tier = track.getRequirements().getTier(_player); + + if (tier != null) + { + builder.addLore(tier.getTitle()); + } + else + { + builder.addLore(NO_TITLE); + } + } + else + { + builder.addLore(NO_TITLE); + } + + addButtonNoAction(0, builder.build()); + } + + private void addStatsButton() + { + //addButton(11, STATS_ITEM, new PageChangeButton()); + } + + private class PageChangeButton implements IButton + { + + private final ShopPageBase _page; + + PageChangeButton(ShopPageBase page) + { + _page = page; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + _page.getShop().openPageForPlayer(player, _page); + } + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/profile/ui/StatsMainPage.java b/Plugins/Mineplex.Core/src/mineplex/core/profile/ui/StatsMainPage.java new file mode 100644 index 000000000..02116e2af --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/profile/ui/StatsMainPage.java @@ -0,0 +1,27 @@ +package mineplex.core.profile.ui; + +import org.bukkit.entity.Player; + +import mineplex.core.profile.ProfileManager; +import mineplex.core.profile.ProfileShop; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.core.stats.PlayerStats; + +public class StatsMainPage extends ShopPageBase +{ + + private final PlayerStats _stats; + + public StatsMainPage(ProfileManager plugin, ProfileShop shop, Player player, PlayerStats stats) + { + super(plugin, shop, plugin.getClientManager(), plugin.getDonationManager(), "Stats", player); + + _stats = stats; + } + + @Override + protected void buildPage() + { + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/quests/QuestManager.java b/Plugins/Mineplex.Core/src/mineplex/core/quests/QuestManager.java index f2ed28796..b5ab3c0aa 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/quests/QuestManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/quests/QuestManager.java @@ -245,9 +245,9 @@ public class QuestManager extends MiniDbClientPlugin TriggerType.getByName(trigger), item.split(","), Integer.parseInt(statcompletion))); - - _availableQuests = Collections.unmodifiableList(quests); } + + _availableQuests = Collections.unmodifiableList(quests); } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/quests/repository/QuestData.java b/Plugins/Mineplex.Core/src/mineplex/core/quests/repository/QuestData.java index 7d46035db..9da769ae5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/quests/repository/QuestData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/quests/repository/QuestData.java @@ -18,14 +18,7 @@ public class QuestData @Override public boolean equals(Object obj) { - if (obj instanceof QuestData) - { - return ((QuestData)obj).QuestId == QuestId; - } - else - { - return false; - } + return obj instanceof QuestData && ((QuestData) obj).QuestId == QuestId; } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/quests/repository/QuestRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/quests/repository/QuestRepository.java index 09e2fb6b7..0deea388f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/quests/repository/QuestRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/quests/repository/QuestRepository.java @@ -25,7 +25,7 @@ public class QuestRepository extends RepositoryBase { super(DBPool.getAccount()); - createTable(); + //createTable(); } public void createTable() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RankRewardData.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RankRewardData.java index afaf7374b..4bbd8a026 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RankRewardData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RankRewardData.java @@ -3,14 +3,18 @@ package mineplex.core.reward; import org.bukkit.inventory.ItemStack; import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.common.util.C; +import mineplex.core.treasure.reward.RewardRarity; public class RankRewardData extends RewardData { - private PermissionGroup _rank; + + private final PermissionGroup _rank; public RankRewardData(String friendlyName, ItemStack displayItem, RewardRarity rarity, PermissionGroup rank) { - super(null, friendlyName, displayItem, rarity); + super(C.cRed + "Rank Upgrade", friendlyName, displayItem, rarity); + _rank = rank; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java index 281374325..f2176193b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java @@ -4,44 +4,55 @@ import java.util.Random; import org.bukkit.entity.Player; +import mineplex.core.Managers; +import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.Callback; +import mineplex.core.donation.DonationManager; +import mineplex.core.inventory.InventoryManager; +import mineplex.core.treasure.reward.RewardRarity; public abstract class Reward { + + protected static final CoreClientManager CLIENT_MANAGER = Managers.require(CoreClientManager.class); + protected static final DonationManager DONATION_MANAGER = Managers.require(DonationManager.class); + protected static final InventoryManager INVENTORY_MANAGER = Managers.require(InventoryManager.class); protected static final Random RANDOM = new Random(); private RewardRarity _rarity; - private int _weight; private int _shardValue; private boolean _requiresCallback; - public Reward(RewardRarity rarity, int weight, int shardValue) + public Reward(RewardRarity rarity, int shardValue) { - this(rarity, weight, shardValue, false); + this(rarity, shardValue, false); } - public Reward(RewardRarity rarity, int weight, int shardValue, boolean requiresCallback) + public Reward(RewardRarity rarity, int shardValue, boolean requiresCallback) { _rarity = rarity; - _weight = weight; _shardValue = shardValue; _requiresCallback = requiresCallback; } - public final void giveReward(RewardType rewardType, Player player, Callback rewardDataCallback) + public final void giveReward(Player player, Callback rewardDataCallback) { if (_requiresCallback) - giveRewardCallback(rewardType, player, rewardDataCallback); + { + giveRewardCallback(player, rewardDataCallback); + } else - rewardDataCallback.run(giveRewardCustom(player, rewardType)); + { + rewardDataCallback.run(giveRewardCustom(player)); + } } - protected void giveRewardCallback(RewardType rewardType, Player player, Callback rewardDataCallback) + protected void giveRewardCallback(Player player, Callback rewardDataCallback) { // do nothing } - protected abstract RewardData giveRewardCustom(Player player, RewardType rewardType); + protected abstract RewardData giveRewardCustom(Player player); public abstract RewardData getFakeRewardData(Player player); @@ -52,18 +63,8 @@ public abstract class Reward return _rarity; } - public int getWeight() - { - return _weight; - } - public int getShardValue() { return _shardValue; } - - public boolean isRequiresCallback() - { - return _requiresCallback; - } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java index 6f3acd00b..303b39e3c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java @@ -2,6 +2,8 @@ package mineplex.core.reward; import org.bukkit.inventory.ItemStack; +import mineplex.core.treasure.reward.RewardRarity; + public class RewardData { private final String _header; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java deleted file mode 100644 index 0678d25cd..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java +++ /dev/null @@ -1,1504 +0,0 @@ -package mineplex.core.reward; - -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.List; -import java.util.Random; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import mineplex.core.Managers; -import mineplex.core.account.CoreClientManager; -import mineplex.core.account.permissions.PermissionGroup; -import mineplex.core.common.util.banner.CountryFlag; -import mineplex.core.donation.DonationManager; -import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailBlood; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailCandyCane; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailConfetti; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailCupid; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailEmerald; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailEnchant; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailFreedom; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailFrostLord; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailHalloween; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailMusic; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailRedWhite; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailShadow; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailSpring; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailStorm; -import mineplex.core.gadget.gadgets.balloons.BalloonType; -import mineplex.core.gadget.gadgets.death.DeathBlood; -import mineplex.core.gadget.gadgets.death.DeathCandyCane; -import mineplex.core.gadget.gadgets.death.DeathCupidsBrokenHeart; -import mineplex.core.gadget.gadgets.death.DeathEmerald; -import mineplex.core.gadget.gadgets.death.DeathEnchant; -import mineplex.core.gadget.gadgets.death.DeathFreedom; -import mineplex.core.gadget.gadgets.death.DeathFrostLord; -import mineplex.core.gadget.gadgets.death.DeathMapleLeaf; -import mineplex.core.gadget.gadgets.death.DeathMusic; -import mineplex.core.gadget.gadgets.death.DeathPinataBurst; -import mineplex.core.gadget.gadgets.death.DeathPresentDanger; -import mineplex.core.gadget.gadgets.death.DeathShadow; -import mineplex.core.gadget.gadgets.death.DeathSpring; -import mineplex.core.gadget.gadgets.death.DeathStorm; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpBlood; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpCandyCane; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpCupidsWings; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpEmerald; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpEnchant; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpFirecracker; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpFreedom; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpFrostLord; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpHalloween; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpMaple; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpMusic; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpShadow; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpSpring; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpStorm; -import mineplex.core.gadget.gadgets.flag.FlagType; -import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.MineStrikeSkin; -import mineplex.core.gadget.gadgets.gamemodifiers.moba.skins.HeroSkinGadget; -import mineplex.core.gadget.gadgets.gamemodifiers.moba.shopmorph.ShopMorphType; -import mineplex.core.gadget.gadgets.gamemodifiers.moba.skins.HeroSkinGadgetData; -import mineplex.core.gadget.gadgets.hat.HatType; -import mineplex.core.gadget.gadgets.item.ItemBatGun; -import mineplex.core.gadget.gadgets.item.ItemBow; -import mineplex.core.gadget.gadgets.item.ItemCoal; -import mineplex.core.gadget.gadgets.item.ItemEtherealPearl; -import mineplex.core.gadget.gadgets.item.ItemFirework; -import mineplex.core.gadget.gadgets.item.ItemFleshHook; -import mineplex.core.gadget.gadgets.item.ItemFreezeCannon; -import mineplex.core.gadget.gadgets.item.ItemLovePotion; -import mineplex.core.gadget.gadgets.item.ItemMelonLauncher; -import mineplex.core.gadget.gadgets.item.ItemPaintballGun; -import mineplex.core.gadget.gadgets.item.ItemPartyPopper; -import mineplex.core.gadget.gadgets.item.ItemSnowball; -import mineplex.core.gadget.gadgets.item.ItemTNT; -import mineplex.core.gadget.gadgets.kitselector.HaloKitSelector; -import mineplex.core.gadget.gadgets.kitselector.RainCloudKitSelector; -import mineplex.core.gadget.gadgets.kitselector.RainbowDanceKitSelector; -import mineplex.core.gadget.gadgets.kitselector.ShimmeringRingKitSelector; -import mineplex.core.gadget.gadgets.kitselector.SingleParticleKitSelector; -import mineplex.core.gadget.gadgets.kitselector.WaterWingsKitSelector; -import mineplex.core.gadget.gadgets.morph.MorphAwkwardRabbit; -import mineplex.core.gadget.gadgets.morph.MorphBat; -import mineplex.core.gadget.gadgets.morph.MorphBlock; -import mineplex.core.gadget.gadgets.morph.MorphBunny; -import mineplex.core.gadget.gadgets.morph.MorphChicken; -import mineplex.core.gadget.gadgets.morph.MorphCow; -import mineplex.core.gadget.gadgets.morph.MorphEnderman; -import mineplex.core.gadget.gadgets.morph.MorphGrimReaper; -import mineplex.core.gadget.gadgets.morph.MorphLoveDoctor; -import mineplex.core.gadget.gadgets.morph.MorphPumpkinKing; -import mineplex.core.gadget.gadgets.morph.MorphSlime; -import mineplex.core.gadget.gadgets.morph.MorphSnowman; -import mineplex.core.gadget.gadgets.morph.MorphUncleSam; -import mineplex.core.gadget.gadgets.morph.MorphVillager; -import mineplex.core.gadget.gadgets.morph.moba.MorphAnath; -import mineplex.core.gadget.gadgets.morph.moba.MorphBardolf; -import mineplex.core.gadget.gadgets.morph.moba.MorphBiff; -import mineplex.core.gadget.gadgets.morph.moba.MorphIvy; -import mineplex.core.gadget.gadgets.morph.moba.MorphDana; -import mineplex.core.gadget.gadgets.morph.moba.MorphDevon; -import mineplex.core.gadget.gadgets.morph.moba.MorphHattori; -import mineplex.core.gadget.gadgets.morph.moba.MorphLarissa; -import mineplex.core.gadget.gadgets.morph.moba.MorphRowena; -import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuitBoots; -import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuitChestplate; -import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuitHelmet; -import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuitLeggings; -import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitBoots; -import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitChestplate; -import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitHelmet; -import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitLeggings; -import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitBoots; -import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitChestplate; -import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitHelmet; -import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitLeggings; -import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksBoots; -import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksChestplate; -import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksHat; -import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksLeggings; -import mineplex.core.gadget.gadgets.particle.ParticleBlood; -import mineplex.core.gadget.gadgets.particle.ParticleCandyCane; -import mineplex.core.gadget.gadgets.particle.ParticleChristmasTree; -import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes; -import mineplex.core.gadget.gadgets.particle.ParticleEmerald; -import mineplex.core.gadget.gadgets.particle.ParticleEnchant; -import mineplex.core.gadget.gadgets.particle.ParticleFairy; -import mineplex.core.gadget.gadgets.particle.ParticleFireRings; -import mineplex.core.gadget.gadgets.particle.ParticleFoot; -import mineplex.core.gadget.gadgets.particle.ParticleFrostLord; -import mineplex.core.gadget.gadgets.particle.ParticleHeart; -import mineplex.core.gadget.gadgets.particle.ParticleMusic; -import mineplex.core.gadget.gadgets.particle.ParticlePartyTime; -import mineplex.core.gadget.gadgets.particle.ParticleRain; -import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel; -import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons; -import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal; -import mineplex.core.gadget.gadgets.particle.ParticleWingsLove; -import mineplex.core.gadget.gadgets.particle.ParticleWingsPixie; -import mineplex.core.gadget.gadgets.particle.ParticleYinYang; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleAuraNiceness; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleCanadian; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedom; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedomFireworks; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleStarSpangled; -import mineplex.core.gadget.gadgets.particle.spring.ParticleSpringHalo; -import mineplex.core.gadget.gadgets.taunts.BlowAKissTaunt; -import mineplex.core.gadget.gadgets.taunts.RainbowTaunt; -import mineplex.core.gadget.gadgets.wineffect.WinEffectBabyChicken; -import mineplex.core.gadget.gadgets.wineffect.WinEffectFlames; -import mineplex.core.gadget.gadgets.wineffect.WinEffectHalloween; -import mineplex.core.gadget.gadgets.wineffect.WinEffectLavaTrap; -import mineplex.core.gadget.gadgets.wineffect.WinEffectLightningStrike; -import mineplex.core.gadget.gadgets.wineffect.WinEffectLoveIsABattlefield; -import mineplex.core.gadget.gadgets.wineffect.WinEffectMrPunchMan; -import mineplex.core.gadget.gadgets.wineffect.WinEffectRiseOfTheElderGuardian; -import mineplex.core.gadget.gadgets.wineffect.WinEffectSnowTrails; -import mineplex.core.gadget.gadgets.wineffect.WinEffectWinterWarfare; -import mineplex.core.gadget.types.Gadget; -import mineplex.core.gadget.types.GadgetType; -import mineplex.core.gadget.types.HatGadget; -import mineplex.core.gadget.types.ItemGadget; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.gadget.gadgets.mount.Mount; -import mineplex.core.gadget.gadgets.mount.types.MountBabyReindeer; -import mineplex.core.gadget.gadgets.mount.types.MountCake; -import mineplex.core.gadget.gadgets.mount.types.MountCart; -import mineplex.core.gadget.gadgets.mount.types.MountChicken; -import mineplex.core.gadget.gadgets.mount.types.MountFreedomHorse; -import mineplex.core.gadget.gadgets.mount.types.MountFrost; -import mineplex.core.gadget.gadgets.mount.types.MountLoveTrain; -import mineplex.core.gadget.gadgets.mount.types.MountMule; -import mineplex.core.gadget.gadgets.mount.types.MountNightmareSteed; -import mineplex.core.gadget.gadgets.mount.types.MountSlime; -import mineplex.core.gadget.gadgets.mount.types.MountSpider; -import mineplex.core.gadget.gadgets.mount.types.MountStPatricksHorse; -import mineplex.core.gadget.gadgets.mount.types.MountUndead; -import mineplex.core.gadget.gadgets.mount.types.MountValentinesSheep; -import mineplex.core.gadget.gadgets.mount.types.MountZombie; -import mineplex.core.pet.PetManager; -import mineplex.core.pet.PetType; -import mineplex.core.powerplayclub.PowerPlayData.SubscriptionDuration; -import mineplex.core.reward.RewardPool.Type; -import mineplex.core.reward.rewards.ChestReward; -import mineplex.core.reward.rewards.ExperienceReward; -import mineplex.core.reward.rewards.GameAmplifierReward; -import mineplex.core.reward.rewards.GemReward; -import mineplex.core.reward.rewards.InventoryReward; -import mineplex.core.reward.rewards.PetReward; -import mineplex.core.reward.rewards.PowerPlayReward; -import mineplex.core.reward.rewards.RankReward; -import mineplex.core.reward.rewards.RuneAmplifierReward; -import mineplex.core.reward.rewards.SpinTicketReward; -import mineplex.core.reward.rewards.TitleReward; -import mineplex.core.reward.rewards.TreasureShardReward; -import mineplex.core.reward.rewards.UnknownPackageReward; -import mineplex.core.stats.StatsManager; -import mineplex.core.titles.tracks.TrackManager; -import mineplex.core.treasure.TreasureType; - -public class RewardManager -{ - private EnumMap _rewardPools; - private Random _random; - - private final TrackManager _trackManager = Managers.require(TrackManager.class); - private CoreClientManager _clientManager; - private DonationManager _donationManager; - private InventoryManager _inventoryManager; - private GadgetManager _gadgetManager; - private PetManager _petManager; - private StatsManager _statsManager; - - private final double _gadgetMultiplier = 1; - - private int _commonAmmoMin = 20, _commonAmmoMax = 50, - _uncommonAmmoMin = 50, _uncommonAmmoMax = 100, - _rareAmmoMin = 100, _rareAmmoMax = 200, - _legendAmmoMin = 200, _legendAmmoMax = 300; - - private int _uncommonShards = 100; - private int _rareShards = 500; - private int _legendaryShards = 5000; - - public RewardManager(CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, - PetManager petManager, GadgetManager gadgetManager, StatsManager statsManager) - { - _rewardPools = new EnumMap<>(RewardPool.Type.class); - _random = new Random(); - - for (RewardPool.Type type : RewardPool.Type.values()) - { - _rewardPools.put(type, new RewardPool()); - } - - _clientManager = clientManager; - _donationManager = donationManager; - _inventoryManager = inventoryManager; - _gadgetManager = gadgetManager; - _petManager = petManager; - _statsManager = statsManager; - - _commonAmmoMin *= _gadgetMultiplier; - _commonAmmoMax *= _gadgetMultiplier; - _uncommonAmmoMin *= _gadgetMultiplier; - _uncommonAmmoMax *= _gadgetMultiplier; - _rareAmmoMin *= _gadgetMultiplier; - _rareAmmoMax *= _gadgetMultiplier; - _legendAmmoMin *= _gadgetMultiplier; - _legendAmmoMax *= _gadgetMultiplier; - - addCommon(); - addUncommon(); - addRare(); - addLegendary(); - } - - public void addCommon() - { - RewardRarity rarity = RewardRarity.COMMON; - - addReward(Type.CARL_SPINNER, new GemReward(_donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 25, 0, rarity)); - addReward(Type.CARL_SPINNER, new ExperienceReward(_statsManager, getAmmoMin(rarity)*5, getAmmoMax(rarity)*5, 25, 0, rarity)); - - //Normal Gadgets - addInventoryReward(Type.NORMAL, getGadget(ItemBatGun.class), rarity, 10, getShards(rarity), 4, 10); - addInventoryReward(Type.NORMAL, getGadget(ItemEtherealPearl.class), rarity, 10, getShards(rarity), 6, 15); - addInventoryReward(Type.NORMAL, getGadget(ItemFirework.class), rarity, 10, getShards(rarity), 10, 25); - addInventoryReward(Type.NORMAL, getGadget(ItemFleshHook.class), rarity, 10, getShards(rarity), 8, 20); - addInventoryReward(Type.NORMAL, getGadget(ItemMelonLauncher.class), rarity, 10, getShards(rarity), 10, 25); - addInventoryReward(Type.NORMAL, getGadget(ItemPaintballGun.class), rarity, 10, getShards(rarity), 20, 50); - addInventoryReward(Type.NORMAL, getGadget(ItemTNT.class), rarity, 10, getShards(rarity), 4, 10); - - //Winter Gadgets - addInventoryReward(Type.WINTER_HOLIDAY, getGadget(ItemCoal.class), rarity, 10, 0, 50, 100); - addInventoryReward(Type.WINTER_HOLIDAY, getGadget(ItemSnowball.class), rarity, 10, 0, 5, 20); - addInventoryReward(Type.WINTER_HOLIDAY, getGadget(ItemPartyPopper.class), rarity, 10, 0, 5, 10); - addInventoryReward(Type.WINTER_HOLIDAY, getGadget(ItemFreezeCannon.class), rarity, 10, 0, 5, 10); - addInventoryReward(Type.WINTER_HOLIDAY, getGadget(ItemTNT.class), rarity, 10, 0, 5, 10); - - //Valentines - addInventoryReward(Type.VALENTINES_GIFT, getGadget(ItemBow.class), rarity, 300, 0, 1, 5); - - // INFUSED CHESTS - - } - - public void addUncommon() - { - RewardRarity rarity = RewardRarity.UNCOMMON; - - addReward(Type.CARL_SPINNER, new GemReward(_donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 1200, 0, rarity)); - addReward(Type.CARL_SPINNER, new ExperienceReward(_statsManager, getAmmoMin(rarity)*5, getAmmoMax(rarity)*5, 1200, 0, rarity)); - - //Gadgets - addInventoryReward(Type.NORMAL, getGadget(ItemBatGun.class), rarity, 250, 0, 20, 40); - addInventoryReward(Type.NORMAL, getGadget(ItemEtherealPearl.class), rarity, 250, 0, 30, 60); - addInventoryReward(Type.NORMAL, getGadget(ItemFirework.class), rarity, 250, 0, 25, 50); - addInventoryReward(Type.NORMAL, getGadget(ItemFleshHook.class), rarity, 250, 0, 40, 80); - addInventoryReward(Type.NORMAL, getGadget(ItemMelonLauncher.class), rarity, 250, 0, 25, 50); - addInventoryReward(Type.NORMAL, getGadget(ItemPaintballGun.class), rarity, 250, 0, 100, 200); - addInventoryReward(Type.NORMAL, getGadget(ItemTNT.class), rarity, 250, 0, 20, 40); - - //Pets - addPetReward(Type.NORMAL, PetType.CHICKEN, rarity, 143); - addPetReward(Type.NORMAL, PetType.COW, rarity, 500); - addPetReward(Type.NORMAL, PetType.MUSHROOM_COW, rarity, 200); - addPetReward(Type.NORMAL, PetType.OCELOT, rarity, 167); - addPetReward(Type.NORMAL, PetType.PIG, rarity, 200); - addPetReward(Type.NORMAL, PetType.SHEEP, rarity, 333); - addPetReward(Type.NORMAL, PetType.WOLF, rarity, 125); - - - //Music Discs - addMusicReward(Type.NORMAL, "Blocks Disc", rarity, 25); - addMusicReward(Type.NORMAL, "Cat Disc", rarity, 25); - addMusicReward(Type.NORMAL, "Chirp Disc", rarity, 25); - addMusicReward(Type.NORMAL, "Far Disc", rarity, 25); - addMusicReward(Type.NORMAL, "Mall Disc", rarity, 25); - addMusicReward(Type.NORMAL, "Mellohi Disc", rarity, 25); - addMusicReward(Type.NORMAL, "Stal Disc", rarity, 25); - addMusicReward(Type.NORMAL, "Strad Disc", rarity, 25); - addMusicReward(Type.NORMAL, "Wait Disc", rarity, 25); - addMusicReward(Type.NORMAL, "Ward Disc", rarity, 25); - - - // VALENTINES Gadgets - addInventoryReward(Type.VALENTINES_GIFT, getGadget(ItemLovePotion.class), rarity, 100, 0, 1, 1); - - //Only enable on Valentince's Day? -// addInventoryReward(Type.VALENTINES_GIFT, getGadget(ItemFlowerGift.class), rarity, 100, 0, 1, 1); - - // WINTER Gadgets - addHat(Type.WINTER_HOLIDAY, HatType.PRESENT, rarity, 5); - addHat(Type.WINTER_HOLIDAY, HatType.SNOWMAN, rarity, 5); - - // FREEDOM - addGadget(Type.FREEDOM, getGadget(ArrowTrailRedWhite.class), rarity, 150); - addGadget(Type.FREEDOM, getGadget(ArrowTrailFreedom.class), rarity, 150); - - // Omega items - addGadget(Type.OMEGA, getGadget(ArrowTrailRedWhite.class), rarity, 2); - addGadget(Type.OMEGA, getGadget(ArrowTrailFreedom.class), rarity, 2); - - addMusicReward(Type.OMEGA, "Blocks Disc", rarity, 25); - addMusicReward(Type.OMEGA, "Cat Disc", rarity, 25); - addMusicReward(Type.OMEGA, "Chirp Disc", rarity, 25); - addMusicReward(Type.OMEGA, "Far Disc", rarity, 25); - addMusicReward(Type.OMEGA, "Mall Disc", rarity, 25); - addMusicReward(Type.OMEGA, "Mellohi Disc", rarity, 25); - addMusicReward(Type.OMEGA, "Stal Disc", rarity, 25); - addMusicReward(Type.OMEGA, "Strad Disc", rarity, 25); - addMusicReward(Type.OMEGA, "Wait Disc", rarity, 25); - addMusicReward(Type.OMEGA, "Ward Disc", rarity, 25); - - addGadget(Type.OMEGA, getGadget(ArrowTrailHalloween.class), rarity, 50); - - addHat(Type.OMEGA, HatType.PUMPKIN, rarity, 75); - addHat(Type.OMEGA, HatType.PRESENT, rarity, 5); - addHat(Type.OMEGA, HatType.SNOWMAN, rarity, 5); - - addBalloon(Type.OMEGA,BalloonType.BABY_COW, rarity, 10, 100); - addBalloon(Type.OMEGA, BalloonType.BABY_PIG, rarity, 10, 100); - addBalloon(Type.OMEGA, BalloonType.BABY_SHEEP, rarity, 15, 100); - - // Minestrike Skins - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.P2000_Fire_Elemental, rarity, 100, 500); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.M4A4_Howl, rarity, 100, 500); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Steyr_AUG_Torque, rarity, 100, 500); - - // Balloons - addBalloon(Type.NORMAL, BalloonType.BABY_COW, rarity, 10, 100); - addBalloon(Type.NORMAL, BalloonType.BABY_PIG, rarity, 10, 100); - addBalloon(Type.NORMAL, BalloonType.BABY_SHEEP, rarity, 15, 100); - - // INFUSED CHESTS - - for (ShopMorphType shopMorphType : ShopMorphType.values()) - { - if (shopMorphType.getRarity() == rarity) - { - addMOBAShopSkin(Type.MOBA, shopMorphType, rarity, 1); - } - } -// addMOBAShopSkin(Type.MOBA, ShopMorphType.SHEEP, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.COW, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.MOOSHROOM, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.PIG, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.HORSE, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.SNOW_GOLEM, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.IRON_GOLEM, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.ZOMBIE, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.SKELETON, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.SPIDER, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.SLIME, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.MAGMA_SLIME, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.WITHER_SKELETON, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.PIG_ZOMBIE, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.WITCH, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.BLAZE, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.GUARDIAN, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.ENDERMAN, rarity, 1); - - addAllMOBASkins(rarity); - } - - public void addRare() - { - RewardRarity rarity = RewardRarity.RARE; - - addReward(Type.CARL_SPINNER, new GemReward(_donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 150, 0, rarity)); - addReward(Type.CARL_SPINNER, new ExperienceReward(_statsManager, getAmmoMin(rarity)*5, getAmmoMax(rarity)*5, 150, 0, rarity)); - - //Morphs - addGadget(Type.NORMAL, getGadget(MorphVillager.class), rarity, 83); - addGadget(Type.NORMAL, getGadget(MorphCow.class), rarity, 167); - addGadget(Type.NORMAL, getGadget(MorphChicken.class), rarity, 50); - addGadget(Type.NORMAL, getGadget(MorphEnderman.class), rarity, 33); - - //Mounts - addMount(Type.NORMAL, getGadget(MountFrost.class), rarity, 50); - addMount(Type.NORMAL, getGadget(MountSlime.class), rarity, 67); - addMount(Type.NORMAL, getGadget(MountCart.class), rarity, 100); - addMount(Type.NORMAL, getGadget(MountMule.class), rarity, 200); - - //Outfit Rave - addGadget(Type.NORMAL, getGadget(OutfitRaveSuitHelmet.class), rarity, 30); - addGadget(Type.NORMAL, getGadget(OutfitRaveSuitChestplate.class), rarity, 30); - addGadget(Type.NORMAL, getGadget(OutfitRaveSuitLeggings.class), rarity, 30); - addGadget(Type.NORMAL, getGadget(OutfitRaveSuitBoots.class), rarity, 30); - //Outfit Space - addGadget(Type.NORMAL, getGadget(OutfitSpaceSuitHelmet.class), rarity, 50); - addGadget(Type.NORMAL, getGadget(OutfitSpaceSuitChestplate.class), rarity, 50); - addGadget(Type.NORMAL, getGadget(OutfitSpaceSuitLeggings.class), rarity, 50); - addGadget(Type.NORMAL, getGadget(OutfitSpaceSuitBoots.class), rarity, 50); - - //Arrow Trails - addGadget(Type.NORMAL, getGadget(ArrowTrailConfetti.class), rarity, 27); - addGadget(Type.NORMAL, getGadget(ArrowTrailBlood.class), rarity, 50); - addGadget(Type.NORMAL, getGadget(ArrowTrailEmerald.class), rarity, 25); - addGadget(Type.NORMAL, getGadget(ArrowTrailMusic.class), rarity, 27); - addGadget(Type.NORMAL, getGadget(ArrowTrailStorm.class), rarity, 30); - addGadget(Type.NORMAL, getGadget(ArrowTrailShadow.class), rarity, 15); - - //Double Jumps - addGadget(Type.NORMAL, getGadget(DoubleJumpFirecracker.class), rarity, 33); - addGadget(Type.NORMAL, getGadget(DoubleJumpEmerald.class), rarity, 25); - addGadget(Type.NORMAL, getGadget(DoubleJumpShadow.class), rarity, 15); - addGadget(Type.NORMAL, getGadget(DoubleJumpStorm.class), rarity, 30); - addGadget(Type.NORMAL, getGadget(DoubleJumpBlood.class), rarity, 50); - addGadget(Type.NORMAL, getGadget(DoubleJumpMusic.class), rarity, 20); - - //Death Effects - addGadget(Type.NORMAL, getGadget(DeathPinataBurst.class), rarity, 27); - addGadget(Type.NORMAL, getGadget(DeathEmerald.class), rarity, 25); - addGadget(Type.NORMAL, getGadget(DeathShadow.class), rarity, 15); - addGadget(Type.NORMAL, getGadget(DeathStorm.class), rarity, 30); - addGadget(Type.NORMAL, getGadget(DeathBlood.class), rarity, 50); - addGadget(Type.NORMAL, getGadget(DeathMusic.class), rarity, 20); - - //Particles - addGadget(Type.NORMAL, getGadget(ParticlePartyTime.class), rarity, 12); - - //Game Modifiers MineStrike - /*addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.AWP_Asiimov, rarity, 200); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.P90_Asiimov, rarity, 200); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.SSG_08_Blood_in_the_Water, rarity, 50); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.Galil_AR_Eco, rarity, 20); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.P2000_Fire_Elemental, rarity, 200); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.Nova_Koi, rarity, 25); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.FAMAS_Pulse, rarity, 20); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.SG553_Pulse, rarity, 20); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.PP_Bizon_Streak, rarity, 40); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.CZ75_Auto_Tigris, rarity, 100); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.Steyr_AUG_Torque, rarity, 30); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.XM1014_Tranquility, rarity, 30);*/ - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.SSG_08_Blood_in_the_Water, rarity, 150, 1000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Galil_AR_Eco, rarity, 150, 1000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Nova_Koi, rarity, 100, 1000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Knife_M9_Bayonette_Fade, rarity, 30, 2500); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.PP_Bizon_Streak, rarity, 150, 1000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.CZ75_Auto_Tigris, rarity, 100, 1000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.XM1014_Tranquility, rarity, 100, 1000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Desert_Eagle_Golden_Gun, rarity, 30, 2500); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.P90_Asiimov, rarity, 100, 1000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.SG553_Pulse, rarity, 100, 1000); - - // Titles - - addTitle(Type.NORMAL, "shrug", rarity, 10, 500); - addTitle(Type.NORMAL, "tableflip", rarity, 10, 500); - addTitle(Type.NORMAL, "tablerespecter", rarity, 15, 500); - addTitle(Type.NORMAL, "tableflip-disgusted", rarity, 15, 500); - addTitle(Type.NORMAL, "tableflip-enraged", rarity, 15, 500); - addTitle(Type.NORMAL, "tableflip-riot", rarity, 10, 500); - addTitle(Type.NORMAL, "teddy-bear", rarity, 10, 500); - addTitle(Type.NORMAL, "disgust", rarity, 10, 500); - addTitle(Type.NORMAL, "old-man", rarity, 5, 500); - addTitle(Type.NORMAL, "jake", rarity, 5, 500); - addTitle(Type.NORMAL, "finn", rarity, 5, 500); - addTitle(Type.NORMAL, "finn-and-jake", rarity, 5, 500); - addTitle(Type.NORMAL, "boxer", rarity, 5, 500); - addTitle(Type.NORMAL, "zoidberg", rarity, 5, 500); - - addTitle(Type.OMEGA, "shrug", rarity, 10, 500); - addTitle(Type.OMEGA, "tableflip", rarity, 10, 500); - addTitle(Type.OMEGA, "tablerespecter", rarity, 15, 500); - addTitle(Type.OMEGA, "tableflip-disgusted", rarity, 15, 500); - addTitle(Type.OMEGA, "tableflip-enraged", rarity, 15, 500); - addTitle(Type.OMEGA, "tableflip-riot", rarity, 10, 500); - addTitle(Type.OMEGA, "teddy-bear", rarity, 10, 500); - addTitle(Type.OMEGA, "disgust", rarity, 10, 500); - addTitle(Type.OMEGA, "old-man", rarity, 5, 500); - addTitle(Type.OMEGA, "jake", rarity, 5, 500); - addTitle(Type.OMEGA, "finn", rarity, 5, 500); - addTitle(Type.OMEGA, "finn-and-jake", rarity, 5, 500); - addTitle(Type.OMEGA, "boxer", rarity, 5, 500); - addTitle(Type.OMEGA, "zoidberg", rarity, 5, 500); - - // VALENTINES - //Hats - addHat(Type.VALENTINES_GIFT, HatType.COMPANION_BLOCK, rarity, 100, 0); - addHat(Type.VALENTINES_GIFT, HatType.LOVESTRUCK, rarity, 100, 0); - addHat(Type.VALENTINES_GIFT, HatType.SECRET_PACKAGE, rarity, 100, 0); - addHat(Type.VALENTINES_GIFT, HatType.TEDDY_BEAR, rarity, 100, 0); - - - // WINTER - //Candy Set - addGadget(Type.WINTER_HOLIDAY, getGadget(ArrowTrailConfetti.class), rarity, 5); - addGadget(Type.WINTER_HOLIDAY, getGadget(DeathCandyCane.class), rarity, 5); - addGadget(Type.WINTER_HOLIDAY, getGadget(DoubleJumpFirecracker.class), rarity, 5); - addGadget(Type.WINTER_HOLIDAY, getGadget(ParticleCandyCane.class), rarity, 5); - - // FREEDOM - addHat(Type.FREEDOM, HatType.UNCLE_SAM, rarity, 100); - addHat(Type.FREEDOM, HatType.AMERICA, rarity, 120); - addHat(Type.FREEDOM, HatType.CANADA, rarity, 120); - addGadget(Type.FREEDOM, getGadget(DoubleJumpFreedom.class), rarity, 50); - addGadget(Type.FREEDOM, getGadget(DoubleJumpMaple.class), rarity, 50); - addGadget(Type.FREEDOM, getGadget(DeathFreedom.class), rarity, 75); - addGadget(Type.FREEDOM, getGadget(DeathMapleLeaf.class), rarity, 75); - - // Omega Chest - addGadget(Type.OMEGA, getGadget(DoubleJumpFreedom.class), rarity, 5); - addGadget(Type.OMEGA, getGadget(DoubleJumpBlood.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(DoubleJumpFirecracker.class), rarity, 33); - addGadget(Type.OMEGA, getGadget(DoubleJumpEmerald.class), rarity, 25); - addGadget(Type.OMEGA, getGadget(DoubleJumpMusic.class), rarity, 20); - addGadget(Type.OMEGA, getGadget(DoubleJumpShadow.class), rarity, 15); - addGadget(Type.OMEGA, getGadget(DoubleJumpStorm.class), rarity, 30); - addGadget(Type.OMEGA, getGadget(DoubleJumpCandyCane.class), rarity, 20); - addGadget(Type.OMEGA, getGadget(DoubleJumpHalloween.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(DoubleJumpSpring.class), rarity, 40); - addGadget(Type.OMEGA, getGadget(DoubleJumpFreedom.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(DoubleJumpMaple.class), rarity, 50); - - addGadget(Type.OMEGA, getGadget(DeathFreedom.class), rarity, 15); - addGadget(Type.OMEGA, getGadget(DeathStorm.class), rarity, 30); - addGadget(Type.OMEGA, getGadget(DeathBlood.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(DeathEmerald.class), rarity, 25); - addGadget(Type.OMEGA, getGadget(DeathMusic.class), rarity, 20); - addGadget(Type.OMEGA, getGadget(DeathPinataBurst.class), rarity, 27); - addGadget(Type.OMEGA, getGadget(DeathShadow.class), rarity, 15); - addGadget(Type.OMEGA, getGadget(DeathCandyCane.class), rarity, 25); - addGadget(Type.OMEGA, getGadget(DeathSpring.class), rarity, 60); - addGadget(Type.OMEGA, getGadget(DeathMapleLeaf.class), rarity, 10); - - addGadget(Type.OMEGA, getGadget(ArrowTrailFreedom.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(ArrowTrailConfetti.class), rarity, 27); - addGadget(Type.OMEGA, getGadget(ArrowTrailBlood.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(ArrowTrailEmerald.class), rarity, 25); - addGadget(Type.OMEGA, getGadget(ArrowTrailMusic.class), rarity, 27); - addGadget(Type.OMEGA, getGadget(ArrowTrailStorm.class), rarity, 30); - addGadget(Type.OMEGA, getGadget(ArrowTrailShadow.class), rarity, 15); - addGadget(Type.OMEGA, getGadget(ArrowTrailCandyCane.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(ArrowTrailSpring.class), rarity, 60); - - addHat(Type.OMEGA, HatType.UNCLE_SAM, rarity, 25); - addHat(Type.OMEGA, HatType.COMPANION_BLOCK, rarity, 15); - addHat(Type.OMEGA, HatType.LOVESTRUCK, rarity, 20); - addHat(Type.OMEGA, HatType.SECRET_PACKAGE, rarity, 25); - addHat(Type.OMEGA, HatType.TEDDY_BEAR, rarity, 25); - addHat(Type.OMEGA, HatType.SANTA, rarity, 25); - addHat(Type.OMEGA, HatType.RUDOLPH, rarity, 25); - addHat(Type.OMEGA, HatType.COAL, rarity, 25); - addHat(Type.OMEGA, HatType.AMERICA, rarity, 50); - addHat(Type.OMEGA, HatType.CANADA, rarity, 50); - - addGadget(Type.OMEGA, getGadget(MorphChicken.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(MorphCow.class), rarity, 167); - addGadget(Type.OMEGA, getGadget(MorphEnderman.class), rarity, 33); - addGadget(Type.OMEGA, getGadget(MorphVillager.class), rarity, 83); - - addGadget(Type.OMEGA, getGadget(WinEffectFlames.class), rarity, 100); - addGadget(Type.OMEGA, getGadget(WinEffectSnowTrails.class), rarity, 100); - - addMount(Type.OMEGA, getGadget(MountFrost.class), rarity, 50); - addMount(Type.OMEGA, getGadget(MountCart.class), rarity, 100); - addMount(Type.OMEGA, getGadget(MountMule.class), rarity, 200); - addMount(Type.OMEGA, getGadget(MountSlime.class), rarity, 67); - addMount(Type.OMEGA, getGadget(MountLoveTrain.class), rarity, 20); - - addGadget(Type.OMEGA, getGadget(OutfitRaveSuitBoots.class), rarity, 30); - addGadget(Type.OMEGA, getGadget(OutfitRaveSuitChestplate.class), rarity, 30); - addGadget(Type.OMEGA, getGadget(OutfitRaveSuitLeggings.class), rarity, 30); - addGadget(Type.OMEGA, getGadget(OutfitRaveSuitHelmet.class), rarity, 30); - addGadget(Type.OMEGA, getGadget(OutfitSpaceSuitBoots.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(OutfitSpaceSuitChestplate.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(OutfitSpaceSuitLeggings.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(OutfitSpaceSuitHelmet.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(OutfitStPatricksChestplate.class),rarity, 50); - addGadget(Type.OMEGA, getGadget(OutfitStPatricksLeggings.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(OutfitStPatricksBoots.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(OutfitFreezeSuitChestplate.class),rarity, 50); - addGadget(Type.OMEGA, getGadget(OutfitFreezeSuitLeggings.class), rarity, 50); - addGadget(Type.OMEGA, getGadget(OutfitFreezeSuitBoots.class), rarity, 50); - - addGadget(Type.OMEGA, getGadget(ParticleCandyCane.class), rarity, 20); - addGadget(Type.OMEGA, getGadget(ParticleChristmasTree.class), rarity, 40); - - addBalloon(Type.OMEGA, BalloonType.BABY_ZOMBIE, rarity, 25, 500); - addBalloon(Type.OMEGA, BalloonType.BABY_MUSHROOM, rarity, 50, 500); - addBalloon(Type.OMEGA, BalloonType.BABY_OCELOT, rarity, 50, 500); - addBalloon(Type.OMEGA, BalloonType.BABY_WOLF, rarity, 75, 500); - addBalloon(Type.OMEGA, BalloonType.BABY_VILLAGER, rarity, 25, 500); - addBalloon(Type.OMEGA, BalloonType.BABY_SLIME, rarity, 25, 500); - addBalloon(Type.OMEGA, BalloonType.BAT, rarity, 50, 500); - - // Balloons - addBalloon(Type.NORMAL, BalloonType.BABY_ZOMBIE, rarity, 25, 500); - addBalloon(Type.NORMAL, BalloonType.BABY_MUSHROOM, rarity, 50, 500); - addBalloon(Type.NORMAL, BalloonType.BABY_OCELOT, rarity, 50, 500); - addBalloon(Type.NORMAL, BalloonType.BABY_WOLF, rarity, 75, 500); - addBalloon(Type.NORMAL, BalloonType.BABY_VILLAGER, rarity, 25, 500); - addBalloon(Type.NORMAL, BalloonType.BABY_SLIME, rarity, 25, 500); - addBalloon(Type.NORMAL, BalloonType.BAT, rarity, 50, 500); - - // HAUNTED CHEST - addGadget(Type.HAUNTED, getGadget(DoubleJumpHalloween.class), rarity, 10); - addHat(Type.HAUNTED, HatType.PUMPKIN, rarity, 10); - addGadget(Type.HAUNTED, getGadget(ArrowTrailHalloween.class), rarity, 100); - - // TRICK OR TREAT - addReward(Type.TRICK_OR_TREAT, new SpinTicketReward(_clientManager, 1, 3, rarity, 150, 0)); - addReward(Type.TRICK_OR_TREAT, new GameAmplifierReward(_inventoryManager, 1, 2, rarity, 150, 0)); - addReward(Type.TRICK_OR_TREAT, new RuneAmplifierReward(_inventoryManager, 20, 1, 3, rarity, 120, 0)); - addReward(Type.TRICK_OR_TREAT, new UnknownPackageReward(_donationManager, _inventoryManager, "Clan Banner Access", "Wear/Place Clan Banner", "Clan Banner Usage", new ItemStack(Material.BANNER), rarity, 110, 0)); - addReward(Type.TRICK_OR_TREAT, new ChestReward(_inventoryManager, TreasureType.OLD, 1, 5, rarity, 150, 0)); - addReward(Type.TRICK_OR_TREAT, new ChestReward(_inventoryManager, TreasureType.ANCIENT, 1, 5, rarity, 80, 0)); - - // INFUSED CHESTS - addHat(Type.INFUSED_CHESTS, HatType.COMPANION_BLOCK, rarity, 100); - addHat(Type.INFUSED_CHESTS, HatType.LOVESTRUCK, rarity, 100); - addHat(Type.INFUSED_CHESTS, HatType.SECRET_PACKAGE, rarity, 100); - addHat(Type.INFUSED_CHESTS, HatType.TEDDY_BEAR, rarity, 100); - - // THANKFUL - addReward(Type.THANKFUL, new SpinTicketReward(_clientManager, 1, 3, rarity, 150, 0)); - addReward(Type.THANKFUL, new RuneAmplifierReward(_inventoryManager, 20, 1, 3, rarity, 120, 0)); - addReward(Type.THANKFUL, new UnknownPackageReward(_donationManager, _inventoryManager, "Clan Banner Access", "Wear/Place Clan Banner", "Clan Banner Usage", new ItemStack(Material.BANNER), rarity, 110, 0)); - addReward(Type.THANKFUL, new ChestReward(_inventoryManager, TreasureType.OLD, 1, 5, rarity, 150, 0)); - addReward(Type.THANKFUL, new ChestReward(_inventoryManager, TreasureType.ANCIENT, 1, 5, rarity, 80, 0)); - - // GINGERBREAD CHEST - addGadget(Type.GINGERBREAD, getGadget(ParticleChristmasTree.class), rarity, 25); - addGadget(Type.GINGERBREAD, getGadget(OutfitFreezeSuitChestplate.class), rarity, 100); - addGadget(Type.GINGERBREAD, getGadget(OutfitFreezeSuitLeggings.class), rarity, 100); - addGadget(Type.GINGERBREAD, getGadget(OutfitFreezeSuitBoots.class), rarity, 50); - - // LOVE CHEST - addMount(Type.LOVECHEST, getGadget(MountLoveTrain.class), rarity, 30, 500); - - addPetReward(Type.LOVECHEST, PetType.CUPID_PET, rarity, 50, 500); - - addGadget(Type.LOVECHEST, getGadget(WinEffectLoveIsABattlefield.class), rarity, 100, 500); - - // ST PATRICKS - addGadget(Type.STPATRICKS, getGadget(OutfitStPatricksChestplate.class), rarity, 50); - addGadget(Type.STPATRICKS, getGadget(OutfitStPatricksLeggings.class), rarity, 50); - addGadget(Type.STPATRICKS, getGadget(OutfitStPatricksBoots.class), rarity, 50); - - // SPRING - addGadget(Type.SPRING, getGadget(ArrowTrailSpring.class), rarity, 100); - addGadget(Type.SPRING, getGadget(DeathSpring.class), rarity, 100); - addGadget(Type.SPRING, getGadget(DoubleJumpSpring.class), rarity, 100); - - // KIT SELECTORS - addGadget(Type.OMEGA, getGadget(HaloKitSelector.class), rarity, 100); - addGadget(Type.ILLUMINATED, getGadget(HaloKitSelector.class), rarity, 100); - addGadget(Type.MYTHICAL, getGadget(HaloKitSelector.class), rarity, 100); - - addGadget(Type.OMEGA, getGadget(RainbowDanceKitSelector.class), rarity, 100); - addGadget(Type.ILLUMINATED, getGadget(RainbowDanceKitSelector.class), rarity, 100); - addGadget(Type.MYTHICAL, getGadget(RainbowDanceKitSelector.class), rarity, 100); - - addGadget(Type.OMEGA, getGadget(ShimmeringRingKitSelector.class), rarity, 150); - addGadget(Type.ILLUMINATED, getGadget(ShimmeringRingKitSelector.class), rarity, 150); - addGadget(Type.MYTHICAL, getGadget(ShimmeringRingKitSelector.class), rarity, 150); - - addGadget(Type.OMEGA, getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors.FLAMES_OF_FURY), rarity, 150); - addGadget(Type.ILLUMINATED, getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors.FLAMES_OF_FURY), rarity, 150); - addGadget(Type.MYTHICAL, getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors.FLAMES_OF_FURY), rarity, 150); - - for (ShopMorphType shopMorphType : ShopMorphType.values()) - { - if (shopMorphType.getRarity() == rarity) - { - addMOBAShopSkin(Type.MOBA, shopMorphType, rarity, 1); - } - } -// addMOBAShopSkin(Type.MOBA, ShopMorphType.SANTA, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.BOB_ROSS, rarity, 1); -// addMOBAShopSkin(Type.MOBA, ShopMorphType.REVOLUTIONARY, rarity, 1); - - addAllMOBASkins(rarity); - } - - public void addLegendary() - { - RewardRarity rarity = RewardRarity.LEGENDARY; - - addReward(Type.CARL_SPINNER, new GemReward(_donationManager, getAmmoMin(rarity), getAmmoMax(rarity), 10, 0, rarity)); - addReward(Type.CARL_SPINNER, new ExperienceReward(_statsManager, getAmmoMin(rarity)*5, getAmmoMax(rarity)*5, 10, 0, rarity)); - - //REGULAR - - //Enchant set - addGadget(Type.NORMAL, getGadget(ArrowTrailEnchant.class), rarity, 10); - addGadget(Type.NORMAL, getGadget(DeathEnchant.class), rarity, 10); - addGadget(Type.NORMAL, getGadget(DoubleJumpEnchant.class), rarity, 10); - - //Morphs - addGadget(Type.NORMAL, getGadget(MorphSlime.class), rarity, 10); - addGadget(Type.NORMAL, getGadget(MorphBat.class), rarity, 25); - addGadget(Type.NORMAL, getGadget(MorphBlock.class), rarity, 20); - - //Mounts - addMount(Type.NORMAL, getGadget(MountUndead.class), rarity, 33); - - //Particle Trails - addGadget(Type.NORMAL, getGadget(ParticleWingsAngel.class), rarity, 15); - addGadget(Type.NORMAL, getGadget(ParticleBlood.class), rarity, 10); - addGadget(Type.NORMAL, getGadget(ParticleWingsDemons.class), rarity, 15); - addGadget(Type.NORMAL, getGadget(ParticleEnchant.class), rarity, 25); - addGadget(Type.NORMAL, getGadget(ParticleFairy.class), rarity, 4); - addGadget(Type.NORMAL, getGadget(ParticleFireRings.class), rarity, 17); - addGadget(Type.NORMAL, getGadget(ParticleEmerald.class), rarity, 8); - addGadget(Type.NORMAL, getGadget(ParticleHeart.class), rarity, 2); - addGadget(Type.NORMAL, getGadget(ParticleWingsInfernal.class), rarity, 4); - addGadget(Type.NORMAL, getGadget(ParticleMusic.class), rarity, 15); - addGadget(Type.NORMAL, getGadget(ParticleWingsPixie.class), rarity, 4); - addGadget(Type.NORMAL, getGadget(ParticleRain.class), rarity, 13); - addGadget(Type.NORMAL, getGadget(ParticleFoot.class), rarity, 33); - addGadget(Type.NORMAL, getGadget(ParticleYinYang.class), rarity, 20); - - //Win Effects - addGadget(Type.NORMAL, getGadget(WinEffectBabyChicken.class), rarity, 10); - addGadget(Type.NORMAL, getGadget(WinEffectLavaTrap.class), rarity, 20); - addGadget(Type.NORMAL, getGadget(WinEffectLightningStrike.class), rarity, 20); - addGadget(Type.NORMAL, getGadget(WinEffectMrPunchMan.class), rarity, 33); - addGadget(Type.NORMAL, getGadget(WinEffectRiseOfTheElderGuardian.class), rarity, 4); - - //GameModifier MineStrike - /*addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.AWP_Asiimov, rarity, 8); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.P90_Asiimov, rarity, 8); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.Desert_Eagle_Blaze, rarity, 10); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.Glock_18_Fade, rarity, 20); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.M4A4_Howl, rarity, 5); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.Knife_M9_Bayonette_Fade, rarity, 1); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.P250_Muertos, rarity, 20); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.FAMAS_Pulse, rarity, 33); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.SG553_Pulse, rarity, 33); - addMineStrikeSkin(Type.NORMAL, MineStrikeSkin.AK_47_Vulcan, rarity, 5);*/ - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Desert_Eagle_Blaze, rarity, 100, 5000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Glock_18_Fade, rarity, 100, 5000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.P250_Muertos, rarity, 100, 5000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.AK_47_Vulcan, rarity, 100, 5000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Knife_Counter_Terrorist_Sword, rarity, 50, 6500); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Knife_Terrorist_Sword, rarity, 50, 6500); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.Knife_M9_Bayonette_Glass, rarity, 50, 6500); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.AK_47_Guardian, rarity, 10, 7500); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.AWP_Asiimov, rarity, 100, 5000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.FAMAS_Pulse, rarity, 100, 5000); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.XM1014_Pig_Gun, rarity, 10, 7500); - addMineStrikeSkin(Type.MINESTRIKE, MineStrikeSkin.M4A4_Enderman, rarity, 10, 7500); - - // Titles - - addTitle(Type.NORMAL, "ayyye", rarity, 25, 500); - addTitle(Type.NORMAL, "ameno", rarity, 15, 5000); - addTitle(Type.NORMAL, "magician", rarity, 25, 5000); - addTitle(Type.NORMAL, "fireball", rarity, 75, 5000); - addTitle(Type.NORMAL, "magic-missile", rarity, 75, 5000); - addTitle(Type.NORMAL, "pewpewpew", rarity, 75, 5000); - addTitle(Type.NORMAL, "stardust", rarity, 60, 5000); - addTitle(Type.NORMAL, "blow-a-kiss", rarity, 60, 5000); - addTitle(Type.NORMAL, "cool-guy", rarity, 60, 5000); - addTitle(Type.NORMAL, "deal-with-it", rarity, 60, 5000); - addTitle(Type.NORMAL, "party-time", rarity, 55, 5000); - addTitle(Type.NORMAL, "lalala", rarity, 30, 5000); - addTitle(Type.NORMAL, "gotta-go", rarity, 30, 5000); - addTitle(Type.NORMAL, "whaaat", rarity, 30, 5000); - - addTitle(Type.OMEGA, "ayyye", rarity, 25, 500); - addTitle(Type.OMEGA, "ameno", rarity, 15, 5000); - addTitle(Type.OMEGA, "magician", rarity, 25, 5000); - addTitle(Type.OMEGA, "fireball", rarity, 75, 5000); - addTitle(Type.OMEGA, "magic-missile", rarity, 75, 5000); - addTitle(Type.OMEGA, "pewpewpew", rarity, 75, 5000); - addTitle(Type.OMEGA, "stardust", rarity, 60, 5000); - addTitle(Type.OMEGA, "blow-a-kiss", rarity, 60, 5000); - addTitle(Type.OMEGA, "cool-guy", rarity, 60, 5000); - addTitle(Type.OMEGA, "deal-with-it", rarity, 60, 5000); - addTitle(Type.OMEGA, "party-time", rarity, 55, 5000); - addTitle(Type.OMEGA, "lalala", rarity, 30, 5000); - addTitle(Type.OMEGA, "gotta-go", rarity, 30, 5000); - addTitle(Type.OMEGA, "whaaat", rarity, 30, 5000); - - //WINTER - - //Arrow Trails - addGadget(Type.WINTER_HOLIDAY, getGadget(ArrowTrailFrostLord.class), rarity, 5); - addGadget(Type.WINTER_HOLIDAY, getGadget(DeathFrostLord.class), rarity, 5); - addGadget(Type.WINTER_HOLIDAY, getGadget(DoubleJumpFrostLord.class), rarity, 5); - addGadget(Type.WINTER_HOLIDAY, getGadget(ParticleFrostLord.class), rarity, 5); - addHat(Type.WINTER_HOLIDAY, HatType.GRINCH, rarity, 5); - addGadget(Type.WINTER_HOLIDAY, getGadget(MorphSnowman.class), rarity, 5); - addMount(Type.WINTER_HOLIDAY, getGadget(MountBabyReindeer.class), rarity, 5); - - //VALENTINES - - //Cupid Set - addGadget(Type.VALENTINES_GIFT, getGadget(ArrowTrailCupid.class), rarity, 100); - addGadget(Type.VALENTINES_GIFT, getGadget(DeathCupidsBrokenHeart.class), rarity, 100); - addGadget(Type.VALENTINES_GIFT, getGadget(DoubleJumpCupidsWings.class), rarity, 100); - addGadget(Type.VALENTINES_GIFT, getGadget(ParticleHeart.class), rarity, 100, 0); - - // FREEDOM - addMount(Type.FREEDOM, getGadget(MountFreedomHorse.class), rarity, 1); - addGadget(Type.FREEDOM, getGadget(MorphUncleSam.class), rarity, 5); - addGadget(Type.FREEDOM, getGadget(ParticleFreedom.class), rarity, 50); - addGadget(Type.FREEDOM, getGadget(ParticleFreedomFireworks.class), rarity, 95); - addGadget(Type.FREEDOM, getGadget(ParticleAuraNiceness.class), rarity, 40); - addGadget(Type.FREEDOM, getGadget(ParticleCanadian.class), rarity, 10); - addGadget(Type.FREEDOM, getGadget(ParticleStarSpangled.class), rarity, 10); - addFlag(Type.FREEDOM, FlagType.CANADA, rarity, 35); - addFlag(Type.FREEDOM, FlagType.USA, rarity, 35); - - // Omega items - addPetReward(Type.OMEGA, PetType.VILLAGER, rarity, 1); - addPetReward(Type.OMEGA, PetType.ZOMBIE, rarity, 10); - addPetReward(Type.OMEGA, PetType.PIG_ZOMBIE, rarity, 1); - addPetReward(Type.OMEGA, PetType.BLAZE, rarity, 2); - addPetReward(Type.OMEGA, PetType.RABBIT, rarity, 10); - addPetReward(Type.OMEGA, PetType.KILLER_BUNNY, rarity, 3); - addPetReward(Type.OMEGA, PetType.CUPID_PET, rarity, 40); - addPetReward(Type.OMEGA, PetType.LEPRECHAUN, rarity, 8); - - addGadget(Type.OMEGA, getGadget(MorphBunny.class), rarity, 1); - addGadget(Type.OMEGA, getGadget(MorphUncleSam.class), rarity, 5); - addGadget(Type.OMEGA, getGadget(MorphPumpkinKing.class), rarity, 1); - addGadget(Type.OMEGA, getGadget(MorphBat.class), rarity, 25); - addGadget(Type.OMEGA, getGadget(MorphSlime.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(MorphBlock.class), rarity, 20); - addGadget(Type.OMEGA, getGadget(MorphSnowman.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(MorphGrimReaper.class), rarity, 25); - addGadget(Type.OMEGA, getGadget(MorphAwkwardRabbit.class), rarity, 30); - addGadget(Type.OMEGA, getGadget(MorphLoveDoctor.class), rarity, 40); - - addGadget(Type.OMEGA, getGadget(ParticleFreedom.class), rarity, 15); - addGadget(Type.OMEGA, getGadget(ParticleWingsAngel.class), rarity, 15); - addGadget(Type.OMEGA, getGadget(ParticleBlood.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(ParticleWingsDemons.class), rarity, 15); - addGadget(Type.OMEGA, getGadget(ParticleEnchant.class), rarity, 25); - addGadget(Type.OMEGA, getGadget(ParticleFairy.class), rarity, 4); - addGadget(Type.OMEGA, getGadget(ParticleFireRings.class), rarity, 17); - addGadget(Type.OMEGA, getGadget(ParticleEmerald.class), rarity, 8); - addGadget(Type.OMEGA, getGadget(ParticleHeart.class), rarity, 2); - addGadget(Type.OMEGA, getGadget(ParticleWingsInfernal.class), rarity, 4); - addGadget(Type.OMEGA, getGadget(ParticleMusic.class), rarity, 15); - addGadget(Type.OMEGA, getGadget(ParticleWingsPixie.class), rarity, 4); - addGadget(Type.OMEGA, getGadget(ParticleRain.class), rarity, 13); - addGadget(Type.OMEGA, getGadget(ParticleFoot.class), rarity, 33); - addGadget(Type.OMEGA, getGadget(ParticleYinYang.class), rarity, 20); - addGadget(Type.OMEGA, getGadget(ParticleCoalFumes.class), rarity, 1); - addGadget(Type.OMEGA, getGadget(ParticleFrostLord.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(ParticlePartyTime.class), rarity, 25); - addGadget(Type.OMEGA, getGadget(ParticleSpringHalo.class), rarity, 8); - addGadget(Type.OMEGA, getGadget(ParticleWingsLove.class), rarity, 10); - addGadget(Type.OMEGA,getGadget(ParticleFreedomFireworks.class),rarity,24); - addGadget(Type.OMEGA, getGadget(ParticleAuraNiceness.class), rarity, 4); - addGadget(Type.OMEGA, getGadget(ParticleCanadian.class), rarity, 1); - addGadget(Type.OMEGA, getGadget(ParticleStarSpangled.class), rarity, 1); - - addMount(Type.OMEGA, getGadget(MountFreedomHorse.class), rarity, 5); - addMount(Type.OMEGA, getGadget(MountZombie.class), rarity, 1); - addMount(Type.OMEGA, getGadget(MountSpider.class), rarity, 1); - addMount(Type.OMEGA, getGadget(MountUndead.class), rarity, 1); - addMount(Type.OMEGA, getGadget(MountValentinesSheep.class), rarity, 20); - addMount(Type.OMEGA, getGadget(MountBabyReindeer.class), rarity, 1); - addMount(Type.OMEGA, getGadget(MountNightmareSteed.class), rarity, 10); - addMount(Type.OMEGA, getGadget(MountChicken.class), rarity, 5); - addMount(Type.OMEGA, getGadget(MountCake.class), rarity, 10); - addMount(Type.OMEGA, getGadget(MountStPatricksHorse.class), rarity, 3); - - addGadget(Type.OMEGA, getGadget(WinEffectBabyChicken.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(WinEffectLavaTrap.class), rarity, 20); - addGadget(Type.OMEGA, getGadget(WinEffectRiseOfTheElderGuardian.class), rarity, 4); - addGadget(Type.OMEGA, getGadget(WinEffectLightningStrike.class), rarity, 20); - addGadget(Type.OMEGA, getGadget(WinEffectMrPunchMan.class), rarity, 33); - addGadget(Type.OMEGA, getGadget(WinEffectHalloween.class), rarity, 75); - - addGadget(Type.OMEGA, getGadget(DeathEnchant.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(DeathCupidsBrokenHeart.class), rarity, 25); - addGadget(Type.OMEGA, getGadget(DeathFrostLord.class), rarity, 15); - addGadget(Type.OMEGA, getGadget(DeathPresentDanger.class), rarity, 27); - - addGadget(Type.OMEGA, getGadget(DoubleJumpEnchant.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(DoubleJumpCupidsWings.class), rarity, 5); - addGadget(Type.OMEGA, getGadget(DoubleJumpFrostLord.class), rarity, 10); - - addGadget(Type.OMEGA, getGadget(ArrowTrailEnchant.class), rarity, 10); - addGadget(Type.OMEGA, getGadget(ArrowTrailFrostLord.class), rarity, 20); - addGadget(Type.OMEGA, getGadget(ArrowTrailCupid.class), rarity, 15); - - addHat(Type.OMEGA, HatType.GRINCH, rarity, 25); - - addGadget(Type.OMEGA, getGadget(OutfitStPatricksHat.class), rarity, 5); - addGadget(Type.OMEGA, getGadget(OutfitFreezeSuitHelmet.class), rarity, 2); - - addBalloon(Type.OMEGA, BalloonType.SQUID, rarity, 10, 5000); - addBalloon(Type.OMEGA, BalloonType.SILVERFISH, rarity, 30, 5000); - addBalloon(Type.OMEGA, BalloonType.GUARDIAN, rarity, 30, 5000); - /*addBalloon(Type.OMEGA, BalloonType.DRAGON_EGG, rarity, 10, 5000); - addBalloon(Type.OMEGA, BalloonType.DIAMOND_BLOCK, rarity, 10, 5000); - addBalloon(Type.OMEGA, BalloonType.IRON_BLOCK, rarity, 20, 5000); - addBalloon(Type.OMEGA, BalloonType.GOLD_BLOCK, rarity, 30, 5000);*/ - addBalloon(Type.OMEGA, BalloonType.EMERALD_BLOCK, rarity, 15, 5000); - - // Balloon - addBalloon(Type.NORMAL, BalloonType.SQUID, rarity, 10, 5000); - addBalloon(Type.NORMAL, BalloonType.SILVERFISH, rarity, 30, 5000); - addBalloon(Type.NORMAL, BalloonType.GUARDIAN, rarity, 30, 5000); - /*addBalloon(Type.NORMAL, BalloonType.DRAGON_EGG, rarity, 10, 5000); - addBalloon(Type.NORMAL, BalloonType.DIAMOND_BLOCK, rarity, 10, 5000); - addBalloon(Type.NORMAL, BalloonType.IRON_BLOCK, rarity, 20, 5000); - addBalloon(Type.NORMAL, BalloonType.GOLD_BLOCK, rarity, 30, 5000);*/ - addBalloon(Type.NORMAL, BalloonType.EMERALD_BLOCK, rarity, 15, 5000); - - addGadget(Type.OMEGA, getGadget(BlowAKissTaunt.class), rarity, 7); - addGadget(Type.OMEGA, getGadget(RainbowTaunt.class), rarity, 1); - - - // HAUNTED - addPetReward(Type.HAUNTED, PetType.RABBIT, rarity, 100); - addGadget(Type.HAUNTED, getGadget(MorphGrimReaper.class), rarity, 25); - addGadget(Type.HAUNTED, getGadget(WinEffectHalloween.class), rarity, 50); - addMount(Type.HAUNTED, getGadget(MountNightmareSteed.class), rarity, 60); - - // TRICK OR TREAT - addReward(Type.TRICK_OR_TREAT, new ChestReward(_inventoryManager, TreasureType.MYTHICAL, 1, 3, rarity, 50, 0)); - addReward(Type.TRICK_OR_TREAT, new ChestReward(_inventoryManager, TreasureType.ILLUMINATED, 1, 1, rarity, 30, 0)); - addMount(Type.TRICK_OR_TREAT, getGadget(MountZombie.class), rarity, 25); - addPetReward(Type.TRICK_OR_TREAT, PetType.ZOMBIE, rarity, 10); - addGadget(Type.TRICK_OR_TREAT, getGadget(MorphPumpkinKing.class), rarity, 5); - - - // INFUSED CHESTS - addGadget(Type.INFUSED_CHESTS, getGadget(ArrowTrailCupid.class), rarity, 100, 5000); - addGadget(Type.INFUSED_CHESTS, getGadget(DeathCupidsBrokenHeart.class), rarity, 100, 5000); - addGadget(Type.INFUSED_CHESTS, getGadget(ParticleHeart.class), rarity, 100, 5000); - addGadget(Type.INFUSED_CHESTS, getGadget(DoubleJumpCupidsWings.class), rarity, 100, 5000); - - // THANKFUL - addReward(Type.THANKFUL, new ChestReward(_inventoryManager, TreasureType.MYTHICAL, 1, 3, rarity, 50, 0)); - addReward(Type.THANKFUL, new ChestReward(_inventoryManager, TreasureType.ILLUMINATED, 1, 1, rarity, 30, 0)); - addReward(Type.THANKFUL, new ChestReward(_inventoryManager, TreasureType.ILLUMINATED, 1, 1, rarity, 30, 0)); - addMount(Type.THANKFUL, getGadget(MountChicken.class), rarity, 5); - addMount(Type.THANKFUL, getGadget(MountCake.class), rarity, 10); - addPetReward(Type.THANKFUL, PetType.VILLAGER, rarity, 10); - addPetReward(Type.THANKFUL, PetType.PIG_ZOMBIE, rarity, 10); - - // GINGERBREAD - addGadget(Type.GINGERBREAD, getGadget(DeathPresentDanger.class), rarity, 25); - addGadget(Type.GINGERBREAD, getGadget(WinEffectWinterWarfare.class), rarity, 25); - addGadget(Type.GINGERBREAD, getGadget(OutfitFreezeSuitHelmet.class), rarity, 1); - addPetReward(Type.GINGERBREAD, PetType.GINGERBREAD_MAN, rarity, 10); - - // LOVE CHEST - addGadget(Type.LOVECHEST, getGadget(MorphLoveDoctor.class), rarity, 30, 5000); - addGadget(Type.LOVECHEST, getGadget(BlowAKissTaunt.class), rarity, 50, 5000); - addGadget(Type.LOVECHEST, getGadget(ParticleWingsLove.class), rarity, 10, 5000); - - // ST PATRICKS - addGadget(Type.STPATRICKS, getGadget(RainbowTaunt.class), rarity, 30); - addGadget(Type.STPATRICKS, getGadget(OutfitStPatricksHat.class), rarity, 15); - - addPetReward(Type.STPATRICKS, PetType.LEPRECHAUN, rarity, 30); - - addMount(Type.STPATRICKS, getGadget(MountStPatricksHorse.class), rarity, 30); - - // SPRING - addGadget(Type.SPRING, getGadget(ParticleSpringHalo.class), rarity, 100); - addGadget(Type.SPRING, getGadget(MorphAwkwardRabbit.class), rarity, 25); - - addPetReward(Type.SPRING, PetType.KILLER_BUNNY, rarity, 50); - - // KIT SELECTORS - addGadget(Type.OMEGA, getGadget(RainCloudKitSelector.class), rarity, 100); - addGadget(Type.ILLUMINATED, getGadget(RainCloudKitSelector.class), rarity, 100); - addGadget(Type.MYTHICAL, getGadget(RainCloudKitSelector.class), rarity, 100); - - addGadget(Type.OMEGA, getGadget(WaterWingsKitSelector.class), rarity, 50); - addGadget(Type.ILLUMINATED, getGadget(WaterWingsKitSelector.class), rarity, 50); - addGadget(Type.MYTHICAL, getGadget(WaterWingsKitSelector.class), rarity, 50); - - addGadget(Type.OMEGA, getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors.EMBER), rarity, 100); - addGadget(Type.ILLUMINATED, getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors.EMBER), rarity, 100); - addGadget(Type.MYTHICAL, getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors.EMBER), rarity, 100); - - addGadget(Type.OMEGA, getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors.LOVE), rarity, 100); - addGadget(Type.ILLUMINATED, getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors.LOVE), rarity, 100); - addGadget(Type.MYTHICAL, getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors.LOVE), rarity, 100); - - addGadget(Type.MOBA, getGadget(MorphHattori.class), rarity, 1); - addGadget(Type.MOBA, getGadget(MorphDevon.class), rarity, 1); - addGadget(Type.MOBA, getGadget(MorphAnath.class), rarity, 1); - addGadget(Type.MOBA, getGadget(MorphDana.class), rarity, 1); - addGadget(Type.MOBA, getGadget(MorphBardolf.class), rarity, 1); - addGadget(Type.MOBA, getGadget(MorphRowena.class), rarity, 1); - addGadget(Type.MOBA, getGadget(MorphLarissa.class), rarity, 1); - addGadget(Type.MOBA, getGadget(MorphBiff.class), rarity, 1); - addGadget(Type.MOBA, getGadget(MorphIvy.class), rarity, 1); - - addAllMOBASkins(rarity); - } - - public UnknownPackageReward addMount(Type type, Mount mount, RewardRarity rarity, int weight) - { - return addMount(type, mount, rarity, weight, getShards(rarity)); - } - - public UnknownPackageReward addMount(Type type, Mount mount, RewardRarity rarity, int weight, int shards) - { - UnknownPackageReward reward = new UnknownPackageReward(_donationManager, _inventoryManager, "Mount", mount.getDisplayName(), mount.getName(), - new ItemStack(mount.getDisplayMaterial(), 1, (short) 0, (byte) mount.getDisplayData()), rarity, weight, shards); - addReward(type, reward); - return reward; - } - - public UnknownPackageReward addMusicReward(Type type, String musicDisk, RewardRarity rarity, int weight) - { - return addMusicReward(type, musicDisk, rarity, weight, getShards(rarity)); - } - - public UnknownPackageReward addMusicReward(Type type, String musicDisk, RewardRarity rarity, int weight, int shards) - { - for(Gadget gadget : _gadgetManager.getGadgets(GadgetType.MUSIC_DISC)) - { - if(gadget.getName().equals(musicDisk) || gadget.getName().equals(musicDisk + " Disc")) - { - return addGadget(type, gadget, rarity, weight, shards); - } - } - return null; - } - - public UnknownPackageReward addHatReward(RewardPool.Type type, HatGadget gadget, RewardRarity rarity, int weight) - { - UnknownPackageReward reward = - new UnknownPackageReward(_donationManager, _inventoryManager, gadget.getGadgetType().getCategoryType(), gadget.getDisplayName(), - gadget.getName(), gadget.getHelmetItem(), rarity, weight, getShards(rarity)); - addReward(type, reward); - return reward; - } - - public UnknownPackageReward addGadget(RewardPool.Type type, Gadget gadget, RewardRarity rarity, int weight) - { - return addGadget(type, gadget, rarity, weight, getShards(rarity)); - } - - public UnknownPackageReward addGadget(RewardPool.Type type, Gadget gadget, String displayName, RewardRarity rarity, int weight, - int shards) - { - ItemStack display = new ItemStack(gadget.getDisplayMaterial(), 1, (short) 0, gadget.getDisplayData()); - if (type == Type.FREEDOM) - { - if (!displayName.contains("Uncle Sam")) - { - display = CountryFlag.USA.getBanner(); - } - } - if (gadget.hasDisplayItem()) - { - display = gadget.getDisplayItem(); - } - UnknownPackageReward reward = - new UnknownPackageReward(_donationManager, _inventoryManager, gadget.getGadgetType().getCategoryType(), displayName, - gadget.getName(), display, rarity, - weight, shards, gadget.getAlternativePackageNames()); - addReward(type, reward); - return reward; - } - - public UnknownPackageReward addGadget(RewardPool.Type type, Gadget gadget, RewardRarity rarity, int weight, int shards) - { - return addGadget(type, gadget, gadget.getDisplayName(), rarity, weight, shards); - } - - public UnknownPackageReward addMineStrikeSkin(Type type, MineStrikeSkin skin, RewardRarity rarity, int weight) - { - return addMineStrikeSkin(type, skin, rarity, weight, getShards(rarity)); - } - - public UnknownPackageReward addMineStrikeSkin(Type type, MineStrikeSkin skin, RewardRarity rarity, int weight, int shards) - { - Gadget gadget = _gadgetManager.getGameCosmeticManager().getGadgetFrom(skin.getSkinName()); - return addGadget(type, gadget, gadget.getDisplayName() + " (Minestrike Weapon Skin)", rarity, weight, shards); - } - - private void addAllMOBASkins(RewardRarity rarity) - { - HeroSkinGadget.getSkins().forEach((name, dataList) -> - { - if (name.equals("Bardolf-Werewolf")) - { - return; - } - - dataList.forEach(data -> - { - if (data.getRarity() != rarity) - { - return; - } - - addMOBASkin(Type.MOBA, data.getGadget(), rarity, 1); - }); - }); - } - - public UnknownPackageReward addMOBASkin(Type type, HeroSkinGadget gadget, RewardRarity rarity, int weight) - { - return addMOBASkin(type, gadget, rarity, weight, getShards(rarity)); - } - - public UnknownPackageReward addMOBASkin(Type type, HeroSkinGadget gadget, RewardRarity rarity, int weight, int shards) - { - return addGadget(type, gadget, gadget.getDisplayName() + " (HOG Hero Skin)", rarity, weight, shards); - } - - public UnknownPackageReward addMOBAShopSkin(Type type, ShopMorphType morphType, RewardRarity rarity, int weight) - { - return addMOBAShopSkin(type, morphType, rarity, weight, getShards(rarity)); - } - - public UnknownPackageReward addMOBAShopSkin(Type type, ShopMorphType morphType, RewardRarity rarity, int weight, int shards) - { - Gadget gadget = _gadgetManager.getGameCosmeticManager().getGadgetFrom(morphType.getName()); - return addGadget(type, gadget, gadget.getDisplayName() + " (HOG Shop Skin)", rarity, weight, shards); - } - - public void addTitle(Type type, String trackName, RewardRarity rarity, int weight, int shards) - { - addReward(type, new TitleReward(_trackManager.getTrackById(trackName), rarity, weight, shards)); - } - - public UnknownPackageReward addHat(Type type, HatType hatType, RewardRarity rarity, int weight) - { - return addHat(type, hatType, rarity, weight, getShards(rarity)); - } - - public UnknownPackageReward addHat(Type type, HatType hatType, RewardRarity rarity, int weight, int shards) - { - Gadget gadget = _gadgetManager.getHatGadget(hatType); - return addGadget(type, gadget, gadget.getDisplayName(), rarity, weight, shards); - } - - public UnknownPackageReward addFlag(Type type, FlagType flagType, RewardRarity rarity, int weight) - { - return addFlag(type, flagType, rarity, weight, getShards(rarity)); - } - - public UnknownPackageReward addFlag(Type type, FlagType flagType, RewardRarity rarity, int weight, int shards) - { - Gadget gadget = _gadgetManager.getFlagGadget(flagType); - return addGadget(type, gadget, gadget.getDisplayName(), rarity, weight, shards); - } - - public UnknownPackageReward addBalloon(Type type, BalloonType balloonType, RewardRarity rarity, int weight) - { - return addBalloon(type, balloonType, rarity, weight, getShards(rarity)); - } - - public UnknownPackageReward addBalloon(Type type, BalloonType balloonType, RewardRarity rarity, int weight, int shards) - { - Gadget gadget = _gadgetManager.getBalloonGadget(balloonType); - return addGadget(type, gadget, gadget.getDisplayName(), rarity, weight, shards); - } - - public InventoryReward addInventoryReward(RewardPool.Type type, ItemGadget gadget, RewardRarity rarity, int weight) - { - return addInventoryReward(type, gadget, rarity, weight, getShards(rarity), getAmmoMin(rarity), getAmmoMax(rarity)); - } - - public InventoryReward addInventoryReward(RewardPool.Type type, ItemGadget gadget, RewardRarity rarity, int weight, int shards) - { - return addInventoryReward(type, gadget, rarity, weight, shards, getAmmoMin(rarity), getAmmoMax(rarity)); - } - - public InventoryReward addInventoryReward(RewardPool.Type type, ItemGadget gadget, RewardRarity rarity, int weight, int shards, - int minAmmo, int maxAmmo) - { - InventoryReward reward = new InventoryReward(_inventoryManager, gadget.getDisplayName(), - gadget.getName(), minAmmo, maxAmmo, - new ItemStack(gadget.getDisplayMaterial(), 1, (short) 0, gadget.getDisplayData()), rarity, weight, shards); - addReward(type, reward); - return reward; - } - - public PetReward addPetReward(Type type, PetType petType, RewardRarity rarity, int weight) - { - return addPetReward(type, petType, rarity, weight, getShards(rarity)); - } - - public PetReward addPetReward(Type type, PetType petType, RewardRarity rarity, int weight, int shards) - { - PetReward reward = new PetReward(_petManager, _inventoryManager, _donationManager, - petType.getName() + " Pet", petType.getName(), petType, rarity, weight, shards); - addReward(type, reward); - return reward; - } - - private T getGadget(Class gadget) - { - return _gadgetManager.getGadget(gadget); - } - - public int getShards(RewardRarity rarity) - { - switch (rarity) - { - case LEGENDARY: - return _legendaryShards; - case UNCOMMON: - return _uncommonShards; - case RARE: - return _rareShards; - default: - return 0; - } - } - - private SingleParticleKitSelector getSingleParticleKitSelector(SingleParticleKitSelector.SingleParticleSelectors singleParticleSelectors) - { - return _gadgetManager.getSingleParticleKitSelector(singleParticleSelectors); - } - - public int getAmmoMin(RewardRarity rarity) - { - switch (rarity) - { - case LEGENDARY: - return _legendAmmoMin; - case RARE: - return _rareAmmoMin; - case UNCOMMON: - return _uncommonAmmoMin; - case COMMON: - default: - return _commonAmmoMin; - } - } - - public int getAmmoMax(RewardRarity rarity) - { - switch (rarity) - { - case LEGENDARY: - return _legendAmmoMax; - case RARE: - return _rareAmmoMax; - case UNCOMMON: - return _uncommonAmmoMax; - case COMMON: - default: - return _commonAmmoMax; - } - } - - public void addReward(Reward reward) - { - addReward(RewardPool.Type.NORMAL, reward); - } - - public void addReward(RewardPool.Type pool, Reward reward) - { - if (pool == Type.NORMAL) - { - _rewardPools.get(Type.CARL_SPINNER).add(reward); - _rewardPools.get(Type.MYTHICAL).add(reward); - - if (!(reward instanceof InventoryReward)) - { - _rewardPools.get(Type.ILLUMINATED).add(reward); - } - } - if (pool != Type.INFUSED_CHESTS && pool != Type.INFUSED_GADGETS) - { - _rewardPools.get(pool).add(reward); - } - else - { - if (pool != Type.INFUSED_GADGETS) - _rewardPools.get(Type.ILLUMINATED).add(reward); - _rewardPools.get(Type.MYTHICAL).add(reward); - } - } - - public Reward[] getRewards(Player player, RewardPool.Type pool, RewardType type) - { - int amount = pool.getChestAmount(); - - int currentReward = 0; - Reward[] rewards = new Reward[amount]; - boolean hasUncommon = false; - boolean canGiveMythical = true; - - int tries = 0; - - boolean first = true; - - while (currentReward < amount && tries++ < amount*100) - { - Reward reward = nextReward(player, pool, rewards, currentReward == amount-1 && !hasUncommon, type, canGiveMythical, pool.getUseDuplicates() || !first); - - if (reward == null) - { - continue; - } - - if (reward.getRarity().ordinal() >= RewardRarity.UNCOMMON.ordinal()) - { - hasUncommon = true; - } - - //Only allow 1 Mythical - if (reward.getRarity().ordinal() >= RewardRarity.MYTHICAL.ordinal()) - { - canGiveMythical = false; - } - - rewards[currentReward] = reward; - currentReward++; - - if(first && tries == 99) - { - first = false; - tries = 0; - } - } - - if(amount >= 4) - { - // Swap the last reward with another one, this makes the uncommon added at the end of some chests seem more random - int slotToSwitch = _random.nextInt(4); - if (slotToSwitch != 3) - { - Reward thirdReward = rewards[3]; - Reward otherReward = rewards[slotToSwitch]; - - rewards[3] = otherReward; - rewards[slotToSwitch] = thirdReward; - } - } - - return rewards; - } - -// private Reward nextReward(Player player, Reward[] excludedRewards) -// { -// return nextReward(player, excludedRewards, false, isChestOpening); -// } - - public Reward nextReward(Player player, Reward[] excludedRewards, boolean requiresUncommon, RewardType type, boolean canGiveMythical) - { - return nextReward(player, RewardPool.Type.NORMAL, excludedRewards, requiresUncommon, type, canGiveMythical, true); - } - - public Reward nextReward(Player player, RewardPool.Type pool, Reward[] excludedRewards, boolean requiresUncommon, RewardType type, boolean canGiveMythical) - { - return nextReward(player, pool, excludedRewards, requiresUncommon, type, canGiveMythical, true); - } - - public Reward nextReward(Player player, RewardPool.Type pool, Reward[] excludedRewards, boolean requiresUncommon, RewardType type, boolean canGiveMythical, boolean duplicateReturnShards) - { - RewardRarity rarity = type.generateRarity(requiresUncommon); - - //Dont give Rank Upgrade if already has Titan - if (rarity == RewardRarity.MYTHICAL) - { - PowerPlayReward rew = new PowerPlayReward(_clientManager, SubscriptionDuration.MONTH, rarity, 0, 0); - if (canGiveMythical && (type == RewardType.MYTHICAL_CHEST || type == RewardType.TRICK_OR_TREAT_CHEST || type == RewardType.THANKFUL_CHEST) && !_clientManager.Get(player).getPrimaryGroup().inheritsFrom(PermissionGroup.TITAN)) - { - return new RankReward(_clientManager, 0, 0, rarity); - } - else if (canGiveMythical && (type == RewardType.THANKFUL_CHEST) && rew.canGiveReward(player)) - { - return rew; - } - else if (!canGiveMythical || _clientManager.Get(player).getPrimaryGroup().inheritsFrom(PermissionGroup.LEGEND)) - { - rarity = RewardRarity.LEGENDARY; - } - else - { - return new RankReward(_clientManager, 0, 0, rarity); - } - } - - List treasureList = _rewardPools.get(pool).getRewards(rarity); - - int totalWeight = 0; - List possibleRewards = new ArrayList<>(); - for (Reward treasure : treasureList) - { - boolean isExcluded = false; - - if (excludedRewards != null) - { - for (int i = 0; i < excludedRewards.length && !isExcluded; i++) - { - if (excludedRewards[i] != null && excludedRewards[i].equals(treasure)) - { - isExcluded = true; - } - } - } - - if (!isExcluded && pool.canGive(player, treasure) && (pool.getUseDuplicates() || treasure.canGiveReward(player))) - { - possibleRewards.add(treasure); - totalWeight += treasure.getWeight(); - } - } - - if (possibleRewards.size() == 0) - { - totalWeight = 0; - - // go again, ignore excluded - for (Reward treasure : treasureList) - { - possibleRewards.add(treasure); - totalWeight += treasure.getWeight(); - } - } - - if (totalWeight > 0) - { - int weight = _random.nextInt(totalWeight); - int currentWeight = 0; - - for (Reward reward : possibleRewards) - { - currentWeight += reward.getWeight(); - - if (weight <= currentWeight) - { - if (reward.canGiveReward(player)) - { - return reward; - } - else if (duplicateReturnShards) - { - return new TreasureShardReward(_clientManager, _donationManager, reward, 1, reward.getRarity()); - } - } - } - } - - return null; - } - - public boolean hasItemsToGivePlayer(RewardPool.Type pool, Player player) - { - for (RewardRarity rarity : new RewardRarity[] - { - RewardRarity.COMMON, RewardRarity.MYTHICAL, RewardRarity.LEGENDARY, RewardRarity.RARE, RewardRarity.UNCOMMON - }) - { - if (_rewardPools.get(pool).hasItemsToGive(rarity, player)) - { - return true; - } - } - return false; - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardPool.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardPool.java deleted file mode 100644 index c8b485590..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardPool.java +++ /dev/null @@ -1,124 +0,0 @@ -package mineplex.core.reward; - -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.List; - -import org.bukkit.entity.Player; - -import mineplex.core.reward.rewards.InventoryReward; -import mineplex.core.reward.rewards.TreasureShardReward; -import mineplex.core.reward.rewards.UnknownPackageReward; - -/** - * Used to separate different "Reward Pools". This allows us to have treasure chests with different loot. - * - */ -public class RewardPool -{ - private EnumMap> _rewardMap; - - public RewardPool() - { - _rewardMap = new EnumMap>(RewardRarity.class); - - for (RewardRarity rarity : RewardRarity.values()) - { - _rewardMap.put(rarity, new ArrayList()); - } - } - - public void add(Reward reward) - { - _rewardMap.get(reward.getRarity()).add(reward); - } - - public List getRewards(RewardRarity rarity) - { - return _rewardMap.get(rarity); - } - - public boolean hasItemsToGive(RewardRarity rarity, Player player) - { - for(Reward r : getRewards(rarity)) - { - if(r.canGiveReward(player)) return true; - } - return false; - } - - public static enum Type - { - NORMAL(true), - WINTER_HOLIDAY(true), - VALENTINES_GIFT(false), - ILLUMINATED(false, 1), - FREEDOM(false, 1), - OMEGA(false, 1), - HAUNTED(false, 1), - TRICK_OR_TREAT(false), - INFUSED_CHESTS(false), - INFUSED_GADGETS(true), - MYTHICAL(true), - THANKFUL(false), - GINGERBREAD(false, 1), - MINESTRIKE(true, 2), - LOVECHEST(false, 1), - STPATRICKS(false, 1), - SPRING(false, 1), - MOBA(true), - CARL_SPINNER(true); - - private boolean _useDuplicates; - private int _chestAmount; - - Type(boolean useDuplicates, int amount) - { - _useDuplicates = useDuplicates; - _chestAmount = amount; - } - - Type(boolean useDuplicates) - { - this(useDuplicates, 4); - } - - public boolean getUseDuplicates() - { - return _useDuplicates; - } - - public int getChestAmount() - { - return _chestAmount; - } - - public boolean canGive(Player player, Reward reward) - { - if(this == Type.ILLUMINATED) - { - if(reward instanceof InventoryReward) - { - return false; - } - } - if (this == OMEGA) - { - if (reward instanceof InventoryReward || reward instanceof TreasureShardReward) - { - return false; - } - else if (reward instanceof UnknownPackageReward) - { - UnknownPackageReward unknownPackageReward = (UnknownPackageReward) reward; - if (unknownPackageReward.getHeader().equalsIgnoreCase("Game Modifiers")) - { - return false; - } - } - } - - return true; - } - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRarity.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRarity.java deleted file mode 100644 index eff019430..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRarity.java +++ /dev/null @@ -1,77 +0,0 @@ -package mineplex.core.reward; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import mineplex.core.common.util.C; -import static mineplex.core.common.util.C.*; - -public enum RewardRarity -{ - /** - * This will probably be used to figure out what effects are shown when the chest is opened - * - * (Fireworks, sounds, etc) - */ - - OTHER("Other", cWhite, C.cGray, Material.STAINED_GLASS_PANE, (byte) 0), - COMMON("Common", cWhite, C.cGray, Material.STAINED_GLASS_PANE, (byte) 0), - GAME("Game", cYellow, C.cYellow, Material.STAINED_GLASS_PANE, (byte) 4), - UNCOMMON("Uncommon", cAqua, C.cDAqua, Material.STAINED_GLASS_PANE, (byte) 3), - RARE("Rare", cPurple, C.cDPurple, Material.STAINED_GLASS_PANE, (byte) 10), - LEGENDARY("Legendary", cGreen, C.cDGreen, Material.STAINED_GLASS_PANE, (byte) 5), - MYTHICAL("Mythical", cRed, C.cDRed, Material.STAINED_GLASS_PANE, (byte) 14); - - private String _name; - private String _color; - private String _darkColor; - private Material _material; - private byte _data; - private ItemStack _stack; - - RewardRarity(String name, String color, String darkColor, Material material, byte data) - { - _name = name; - _color = color; - _darkColor = darkColor; - _material = material; - _data = data; - - _stack = new ItemStack(getMaterial(), 1, (short) 0, getData()); - ItemMeta meta = _stack.getItemMeta(); - meta.setDisplayName(_color + _name); - _stack.setItemMeta(meta); - } - - public String getColor() - { - return _color; - } - - public String getDarkColor() - { - return _darkColor; - } - - public String getName() - { - return _name; - } - - public Material getMaterial() - { - return _material; - } - - public byte getData() - { - return _data; - } - - public ItemStack getItemStack() - { - return _stack; - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java index c5be5341a..0167df383 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java @@ -1,96 +1,79 @@ package mineplex.core.reward; -import java.util.ArrayList; +import mineplex.core.treasure.reward.RewardRarity; public enum RewardType { - //% Chances Mythic Legend Rare Uncommon - GAME_LOOT( 0.000001, 0.00001, 0.0001, 3), + //% Chances Mythic Legend Rare Uncommon Common + GAME_LOOT( 0.000001, 0.00001, 0.0001, 3, 0), - OLD_CHEST( 0, 0.06, 0.8, 16), - ANCIENT_CHEST( 0, 2, 8, 32), - MYTHICAL_CHEST( 0.1, 4, 16, 72), - WINTER_CHEST( 0, 5, 18, 32), - ILLUMINATED_CHEST( 0, 2, 16, 72), - FREEDOM_CHEST( 0, 5, 18, 0), - HAUNTED_CHEST( 0, 5, 18, 0), - OMEGA_CHEST( 0, 32, 16, 2), - TRICK_OR_TREAT_CHEST(0.1, 2, 16, 0), - THANKFUL_CHEST( 0.1, 2, 16, 0), - GINGERBREAD_CHEST( 0, 2, 16, 0), - MINESTRIKE_CHEST( 0, 2, 16, 0), - LOVE_CHEST( 0, 6, 18, 0), - VALENTINES_GIFT( 0, 7, 20, 20), - ST_PATRICKS( 0, 6, 18, 0), - SPRING( 0, 6, 18, 0), - MOBA( 0, 5, 20, 30), - - SPINNER_FILLER( 0.1, 1, 4, 20), - SPINNER_REAL( 0.000001, 0.05, 0.4, 5); + OLD_CHEST( 20, 0.06, 0.8, 16, 40), + ANCIENT_CHEST( 0, 2, 8, 32, 0), + MYTHICAL_CHEST( 0.1, 4, 16, 72, 0), + WINTER_CHEST( 0, 5, 18, 32, 0), + ILLUMINATED_CHEST( 0, 2, 16, 72, 0), + FREEDOM_CHEST( 0, 5, 18, 0, 0), + HAUNTED_CHEST( 0, 5, 18, 0, 0), + OMEGA_CHEST( 0, 32, 16, 2, 0), + TRICK_OR_TREAT_CHEST(0, 2, 16, 2, 0), + THANKFUL_CHEST( 0.1, 2, 16, 0, 0), + GINGERBREAD_CHEST( 0, 2, 16, 0, 0), + MINESTRIKE_CHEST( 0, 2, 16, 0, 0), + LOVE_CHEST( 0, 6, 18, 0, 0), + VALENTINES_GIFT( 0, 7, 20, 20, 0), + ST_PATRICKS( 0, 6, 18, 0, 0), + SPRING( 0, 6, 18, 0, 0), + MOBA( 0, 5, 20, 30, 0), - private double _mythicalChance; - private double _legendaryChance; - private double _rareChance; - private double _uncommonChance; + SPINNER_FILLER( 0.1, 1, 4, 20, 30), + SPINNER_REAL( 0.000001, 0.05, 0.4, 5, 20); - RewardType(double mythical, double legend, double rare, double uncommon) + private final Rarity[] _rarities; + + RewardType(double mythical, double legend, double rare, double uncommon, double common) { - _mythicalChance = (mythical / 100d); - _legendaryChance = _mythicalChance + (legend / 100d); //Add previous chance to prep for generateRarity random values. - _rareChance = _legendaryChance + (rare / 100d); - _uncommonChance = _rareChance + (uncommon / 100d); + _rarities = new Rarity[] + { + new Rarity(RewardRarity.MYTHICAL, mythical), + new Rarity(RewardRarity.LEGENDARY, legend), + new Rarity(RewardRarity.RARE, rare), + new Rarity(RewardRarity.UNCOMMON, uncommon), + new Rarity(RewardRarity.COMMON, common) + }; } - public RewardRarity generateRarity(boolean requiresUncommon) + public RewardRarity generateRarity() { - double rand = Math.random(); + double totalRoll = 0; - RewardRarity rarity = RewardRarity.COMMON; + for (Rarity rarity : _rarities) + { + totalRoll += rarity.Chance; + } - if (rand <= _mythicalChance) rarity = RewardRarity.MYTHICAL; - else if (rand <= _legendaryChance) rarity = RewardRarity.LEGENDARY; - else if (rand <= _rareChance) rarity = RewardRarity.RARE; - else if (rand <= _uncommonChance || requiresUncommon) rarity = RewardRarity.UNCOMMON; - - return rarity; + double roll = Math.random() * totalRoll; + + for (Rarity rarity : _rarities) + { + if ((roll -= rarity.Chance) < 0) + { + return rarity.RewardRarity; + } + } + + return null; } - public static void main(String[] args) + private class Rarity { - int maxCount = Integer.MAX_VALUE; - int openCount = 0; - RewardType type = RewardType.MYTHICAL_CHEST; - ArrayList data = new ArrayList(); - for (RewardRarity rarity : RewardRarity.values()) + RewardRarity RewardRarity; + double Chance; + + Rarity(RewardRarity rewardRarity, double chance) { - data.add(rarity.ordinal(), new RewardTest(rarity)); - } - - for (int i = 0; i < maxCount; i++) - { - RewardRarity rarity = type.generateRarity(false); - data.get(rarity.ordinal()).Count++; - openCount++; - if (rarity == RewardRarity.MYTHICAL) break; - } - - System.out.printf("Opened %10d rewards using type " + type.name() + "\n", openCount); - for (RewardTest test : data) - { - System.out.printf("Opened %10d of reward type %10s", test.Count, test.Rarity.name()); - System.out.println(); - } - } - - private static class RewardTest - { - public final RewardRarity Rarity; - public int Count; - - public RewardTest(RewardRarity rare) - { - Rarity = rare; + RewardRarity = rewardRarity; + Chance = chance; } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ChestReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ChestReward.java index f39f034b8..b796c5452 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ChestReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ChestReward.java @@ -1,86 +1,24 @@ package mineplex.core.reward.rewards; -import java.util.Random; +import mineplex.core.treasure.reward.RewardRarity; +import mineplex.core.treasure.types.Treasure; +import mineplex.core.treasure.types.TreasureType; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import mineplex.core.inventory.InventoryManager; -import mineplex.core.reward.Reward; -import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; -import mineplex.core.treasure.TreasureType; - -public class ChestReward extends Reward +public class ChestReward extends InventoryReward { - private Random _random; - private InventoryManager _inventoryManager; - private int _max, _min; - private TreasureType _type; - - public ChestReward(InventoryManager inventoryManager, TreasureType type, int min, int max, RewardRarity rarity, int weight, int shardValue) + public ChestReward(TreasureType type, RewardRarity rarity, int shardValue) { - this(RANDOM, inventoryManager, type, min, max, rarity, weight, shardValue); + this(type, 1, rarity, shardValue); } - public ChestReward(Random random, InventoryManager inventoryManager, TreasureType type, int min, int max, RewardRarity rarity, int weight, int shardValue) + public ChestReward(TreasureType type, int amount, RewardRarity rarity, int shardValue) { - super(rarity, weight, shardValue); - - _random = random; - _inventoryManager = inventoryManager; - _max = max; - _min = min; - _type = type; + this(type, amount, amount, rarity, shardValue); } - @Override - public RewardData giveRewardCustom(Player player, RewardType rewardType) + public ChestReward(TreasureType type, int min, int max, RewardRarity rarity, int shardValue) { - int amountToGive; - - if (_min != _max) - { - amountToGive = _random.nextInt(_max - _min) + _min; - } - else - { - amountToGive = _min; - } - - _inventoryManager.addItemToInventory(player, _type.getItemName(), amountToGive); - - return new RewardData(getRarity().getDarkColor() + "Treasure Chest", getRarity().getColor() + amountToGive + " " + ChatColor.stripColor(_type.getName()), new ItemStack(_type.getMaterial()), getRarity()); + super(type.getName(), type.getItemName(), "Treasure Chest", min, max, type.getItemStack(), rarity, shardValue); } - - @Override - public RewardData getFakeRewardData(Player player) - { - return new RewardData(getRarity().getDarkColor() + "Treasure Chest", getRarity().getColor() + ChatColor.stripColor(_type.getName()), new ItemStack(_type.getMaterial()), getRarity()); - } - - @Override - public boolean canGiveReward(Player player) - { - return true; - } - - @Override - public boolean equals(Object obj) - { - if (obj instanceof ChestReward) - { - return ((ChestReward) obj)._type.getName().equals(_type.getName()); - } - return false; - } - - @Override - public int hashCode() - { - return _type.getName().hashCode(); - } -} \ No newline at end of file +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ExperienceReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ExperienceReward.java index b40171381..b4a50bf3b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ExperienceReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ExperienceReward.java @@ -6,43 +6,46 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import mineplex.core.Managers; +import mineplex.core.achievement.Achievement; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; import mineplex.core.stats.StatsManager; +import mineplex.core.treasure.reward.RewardRarity; public class ExperienceReward extends Reward { - private StatsManager _statsManager; + + private static final StatsManager STATS_MANAGER = Managers.require(StatsManager.class); + private static final ItemStack ITEM_STACK = new ItemStack(Material.EXP_BOTTLE); + private Random _random; private int _minExperience; private int _maxExperience; - public ExperienceReward(StatsManager statsManager, int minExperience, int maxExperience, int weight, int shardValue, RewardRarity rarity) + public ExperienceReward(int minExperience, int maxExperience, int shardValue, RewardRarity rarity) { - super(rarity, weight, shardValue); + super(rarity, shardValue); - _statsManager = statsManager; _random = new Random(); _minExperience = minExperience; _maxExperience = maxExperience; } @Override - protected RewardData giveRewardCustom(Player player, RewardType rewardType) + protected RewardData giveRewardCustom(Player player) { int experience = _random.nextInt(_maxExperience - _minExperience) + _minExperience; - _statsManager.incrementStat(player, "Global.ExpEarned", experience); + STATS_MANAGER.incrementStat(player, Achievement.GLOBAL_MINEPLEX_LEVEL.getStats()[0], experience); - return new RewardData(null, getRarity().getColor() + experience + " Experience", new ItemStack(Material.EXP_BOTTLE), getRarity()); + return new RewardData(null, getRarity().getColor() + experience + " Experience", ITEM_STACK, getRarity()); } @Override public RewardData getFakeRewardData(Player player) { - return new RewardData(null, getRarity().getColor() + "Experience", new ItemStack(Material.EXP_BOTTLE), getRarity()); + return new RewardData(null, getRarity().getColor() + "Experience", ITEM_STACK, getRarity()); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GadgetReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GadgetReward.java new file mode 100644 index 000000000..ad2f0141d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GadgetReward.java @@ -0,0 +1,55 @@ +package mineplex.core.reward.rewards; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.gadget.types.Gadget; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardData; +import mineplex.core.treasure.reward.RewardRarity; + +public class GadgetReward extends Reward +{ + + private final Gadget _gadget; + private final ItemStack _itemStack; + + public GadgetReward(Gadget gadget, RewardRarity rarity, int shardValue) + { + super(rarity, shardValue); + + _gadget = gadget; + + if (_gadget.hasDisplayItem()) + { + _itemStack = _gadget.getDisplayItem(); + } + else + { + _itemStack = new ItemBuilder(_gadget.getDisplayMaterial(), _gadget.getDisplayData()) + .build(); + } + } + + @Override + protected RewardData giveRewardCustom(Player player) + { + DONATION_MANAGER.purchaseUnknownSalesPackage(player, _gadget.getName(), GlobalCurrency.TREASURE_SHARD, 0, true, null); + + return getFakeRewardData(player); + } + + @Override + public RewardData getFakeRewardData(Player player) + { + return new RewardData(getRarity().getDarkColor() + _gadget.getGadgetType().getCategoryType(), getRarity().getColor() + _gadget.getName(), _itemStack, getRarity()); + } + + @Override + public boolean canGiveReward(Player player) + { + return !_gadget.ownsGadget(player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GameAmplifierReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GameAmplifierReward.java index 9673ab1bc..2267bc11b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GameAmplifierReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GameAmplifierReward.java @@ -1,84 +1,29 @@ package mineplex.core.reward.rewards; -import java.util.Random; - import org.bukkit.Material; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import mineplex.core.boosters.BoosterManager; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.reward.Reward; -import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; +import mineplex.core.treasure.reward.RewardRarity; -public class GameAmplifierReward extends Reward +public class GameAmplifierReward extends InventoryReward { - private Random _random; - private InventoryManager _inventoryManager; - private int _max, _min; + private static final ItemStack ITEM_STACK = new ItemStack(Material.EMERALD); - public GameAmplifierReward(InventoryManager inventoryManager, int min, int max, RewardRarity rarity, int weight, int shardValue) + public GameAmplifierReward(RewardRarity rarity, int shardValue) { - this(RANDOM, inventoryManager, min, max, rarity, weight, shardValue); + this(1, rarity, shardValue); } - public GameAmplifierReward(Random random, InventoryManager inventoryManager, int min, int max, RewardRarity rarity, int weight, int shardValue) + public GameAmplifierReward(int amount, RewardRarity rarity, int shardValue) { - super(rarity, weight, shardValue); - - _random = random; - _inventoryManager = inventoryManager; - _max = max; - _min = min; + this(amount, amount, rarity, shardValue); } - @Override - public RewardData giveRewardCustom(Player player, RewardType rewardType) + public GameAmplifierReward(int min, int max, RewardRarity rarity, int shardValue) { - int amountToGive; - - if (_min != _max) - { - amountToGive = _random.nextInt(_max - _min) + _min; - } - else - { - amountToGive = _min; - } - - _inventoryManager.addItemToInventory(player, BoosterManager.BOOSTER_ITEM, amountToGive); - - return new RewardData(getRarity().getDarkColor() + "Game Amplifier", getRarity().getColor() + amountToGive + " Game Amplifier", new ItemStack(Material.EMERALD), getRarity()); + super("Game Amplifier", BoosterManager.BOOSTER_ITEM, "Game Amplifier", min, max, ITEM_STACK, rarity, shardValue); } - @Override - public RewardData getFakeRewardData(Player player) - { - return new RewardData(getRarity().getDarkColor() + "Game Amplifier", getRarity().getColor() + "Game Amplifier", new ItemStack(Material.EMERALD), getRarity()); - } - - @Override - public boolean canGiveReward(Player player) - { - return true; - } - - @Override - public boolean equals(Object obj) - { - if (obj instanceof GameAmplifierReward) - { - return true; - } - return false; - } - - @Override - public int hashCode() - { - return getClass().hashCode(); - } -} \ No newline at end of file +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GemReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GemReward.java index d4f062609..d2d332437 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GemReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GemReward.java @@ -1,48 +1,37 @@ package mineplex.core.reward.rewards; -import java.util.Random; - import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.donation.DonationManager; +import mineplex.core.treasure.reward.RewardRarity; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; import mineplex.core.reward.RewardType; public class GemReward extends Reward { - private DonationManager _donationManager; - private Random _random; + private int _minGemCount; private int _maxGemCount; - public GemReward(DonationManager donationManager, int minGemCount, int maxGemCount, int weight, int shardValue, RewardRarity rarity) + public GemReward(int minGemCount, int maxGemCount, int shardValue, RewardRarity rarity) { - this(donationManager, minGemCount, maxGemCount, weight, shardValue, rarity, RANDOM); - } + super(rarity, shardValue); - public GemReward(DonationManager donationManager, int minGemCount, int maxGemCount, int weight, int shardValue, RewardRarity rarity, Random random) - { - super(rarity, weight, shardValue); - _donationManager = donationManager; _minGemCount = minGemCount; _maxGemCount = maxGemCount; - - _random = random; } @Override - public RewardData giveRewardCustom(Player player, RewardType rewardType) + public RewardData giveRewardCustom(Player player) { - int GemsToReward = _random.nextInt(_maxGemCount - _minGemCount) + _minGemCount; + int gemsToReward = RANDOM.nextInt(_maxGemCount - _minGemCount) + _minGemCount; - _donationManager.rewardCurrency(GlobalCurrency.GEM, player, "Treasure Chest", GemsToReward); + DONATION_MANAGER.rewardCurrency(GlobalCurrency.GEM, player, "Treasure Chest", gemsToReward); - return new RewardData(null, getRarity().getColor() + GemsToReward + " Gems", new ItemStack(Material.EMERALD), getRarity()); + return new RewardData(null, getRarity().getColor() + gemsToReward + " Gems", new ItemStack(Material.EMERALD), getRarity()); } @Override @@ -60,15 +49,6 @@ public class GemReward extends Reward @Override public boolean equals(Object obj) { - if (obj instanceof GemReward) - return true; - - return false; + return obj instanceof GemReward; } - - @Override - public int hashCode() - { - return getClass().hashCode(); - } -} \ No newline at end of file +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/InventoryReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/InventoryReward.java index 00e796776..d4ef9fc37 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/InventoryReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/InventoryReward.java @@ -1,68 +1,72 @@ package mineplex.core.reward.rewards; -import java.util.Random; - import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import mineplex.core.inventory.InventoryManager; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; +import mineplex.core.treasure.reward.RewardRarity; public class InventoryReward extends Reward { - private Random _random; - private InventoryManager _inventoryManager; private ItemStack _itemStack; private String _name; private String _packageName; + private String _header; private int _minAmount; private int _maxAmount; - public InventoryReward(InventoryManager inventoryManager, String name, String packageName, int minAmount, int maxAmount, ItemStack itemStack, RewardRarity rarity, int weight, int shardValue) + public InventoryReward(String name, String packageName, String header, ItemStack itemStack, RewardRarity rarity, int shardValue) { - this(RANDOM, inventoryManager, name, packageName, minAmount, maxAmount, itemStack, rarity, weight, shardValue); + this(name, packageName, header, 1, itemStack, rarity, shardValue); } - public InventoryReward(Random random, InventoryManager inventoryManager, String name, String packageName, int minAmount, int maxAmount, ItemStack itemStack, RewardRarity rarity, int weight, int shardValue) + public InventoryReward(String name, String packageName, String header, int amount, ItemStack itemStack, RewardRarity rarity, int shardValue) { - super(rarity, weight, shardValue); + this(name, packageName, header, amount, amount, itemStack, rarity, shardValue); + } + + public InventoryReward(String name, String packageName, String header, int minAmount, int maxAmount, ItemStack itemStack, RewardRarity rarity, int shardValue) + { + super(rarity, shardValue); - _random = random; _name = name; _packageName = packageName; + _header = header; _minAmount = minAmount; _maxAmount = maxAmount; _itemStack = itemStack; - _inventoryManager = inventoryManager; } @Override - public RewardData giveRewardCustom(Player player, RewardType rewardType) + public RewardData giveRewardCustom(Player player) { int amountToGive; if (_minAmount != _maxAmount) { - amountToGive = _random.nextInt(_maxAmount - _minAmount) + _minAmount; + amountToGive = RANDOM.nextInt(_maxAmount - _minAmount) + _minAmount; } else { amountToGive = _minAmount; } - _inventoryManager.addItemToInventory(player, _packageName, amountToGive); + INVENTORY_MANAGER.addItemToInventory(player, _packageName, amountToGive); - return new RewardData(getRarity().getDarkColor() + "Gadget", getRarity().getColor() + amountToGive + " " + _name, _itemStack, getRarity()); + if (amountToGive == 1) + { + return getFakeRewardData(player); + } + + return new RewardData(getRarity().getDarkColor() + _header, getRarity().getColor() + amountToGive + " " + _name, _itemStack, getRarity()); } @Override public RewardData getFakeRewardData(Player player) { - return new RewardData(getRarity().getDarkColor() + "Gadget", getRarity().getColor() + _name, _itemStack, getRarity()); + return new RewardData(getRarity().getDarkColor() + _header, getRarity().getColor() + _name, _itemStack, getRarity()); } @Override @@ -79,11 +83,7 @@ public class InventoryReward extends Reward @Override public boolean equals(Object obj) { - if (obj instanceof InventoryReward) - { - return ((InventoryReward) obj).getPackageName().equals(_packageName); - } - return false; + return obj instanceof InventoryReward && ((InventoryReward) obj).getPackageName().equals(_packageName); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PetReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PetReward.java index 0f6839279..8d5d22fc0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PetReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PetReward.java @@ -5,68 +5,77 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import mineplex.cache.player.PlayerCache; -import mineplex.core.donation.DonationManager; -import mineplex.core.inventory.InventoryManager; +import mineplex.core.Managers; import mineplex.core.pet.PetManager; import mineplex.core.pet.PetType; import mineplex.core.pet.repository.token.PetChangeToken; import mineplex.core.pet.repository.token.PetToken; +import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; +import mineplex.core.treasure.reward.RewardRarity; -/** - * Created by shaun on 14-09-18. - */ -public class PetReward extends UnknownPackageReward +public class PetReward extends Reward { - private InventoryManager _inventoryManager; - private PetManager _petManager; + + private static final PetManager PET_MANAGER = Managers.require(PetManager.class); + + private String _packageName; + private ItemStack _itemStack; private PetType _petType; - public PetReward(PetManager petManager, InventoryManager inventoryManager, DonationManager donationManager, String name, String packageName, PetType petType, RewardRarity rarity, int weight, int shardValue) + public PetReward(String packageName, PetType petType, RewardRarity rarity, int shardValue) { - super(donationManager, inventoryManager, "Pet", name, packageName, new ItemStack(Material.MONSTER_EGG, 1, petType.getEntityType().getTypeId()), rarity, weight, shardValue); - - _petManager = petManager; - _inventoryManager = inventoryManager; + super(rarity, shardValue); + + _packageName = packageName; + _itemStack = new ItemStack(Material.MONSTER_EGG, 1, petType.getEntityType().getTypeId()); _petType = petType; } @Override - protected RewardData giveRewardCustom(Player player, RewardType rewardType) + protected RewardData giveRewardCustom(Player player) { PetChangeToken token = new PetChangeToken(); - - if (_inventoryManager.getClientManager().Get(player) != null) - token.AccountId = _inventoryManager.getClientManager().Get(player).getAccountId(); + + if (INVENTORY_MANAGER.getClientManager().Get(player) != null) + { + token.AccountId = INVENTORY_MANAGER.getClientManager().Get(player).getAccountId(); + } else + { token.AccountId = PlayerCache.getInstance().getAccountId(player.getUniqueId()); - + } + token.Name = player.getName(); token.PetType = _petType.toString(); - token.PetName = getPackageName(); + token.PetName = _packageName; PetToken petToken = new PetToken(); petToken.PetType = token.PetType; - _petManager.getRepository().AddPet(token); - _petManager.Get(player).getPets().put(_petType, token.PetName); + PET_MANAGER.getRepository().AddPet(token); + PET_MANAGER.Get(player).getPets().put(_petType, token.PetName); - _inventoryManager.addItemToInventory(player, _petType.toString(), 1); + INVENTORY_MANAGER.addItemToInventory(player, _petType.toString(), 1); return getFakeRewardData(player); } - + + @Override + public RewardData getFakeRewardData(Player player) + { + return new RewardData(getRarity().getDarkColor() + "Pet", getRarity().getColor() + _petType.getName(), _itemStack, getRarity()); + } + @Override public boolean canGiveReward(Player player) { - if (_donationManager.Get(player) == null) + if (DONATION_MANAGER.Get(player) == null) { - System.out.println("Could not give reward " + getPackageName() + " to Offline Player: " + player.getName()); + System.out.println("Could not give reward " + _packageName + " to Offline Player: " + player.getName()); return false; } - - return !_petManager.Get(player).getPets().containsKey(_petType); + + return !PET_MANAGER.Get(player).getPets().containsKey(_petType); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PowerPlayReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PowerPlayReward.java index 280503902..9948fc990 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PowerPlayReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PowerPlayReward.java @@ -14,24 +14,23 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.powerplayclub.PowerPlayData.SubscriptionDuration; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; +import mineplex.core.treasure.reward.RewardRarity; public class PowerPlayReward extends Reward { private CoreClientManager _clientManager; private SubscriptionDuration _duration; - public PowerPlayReward(CoreClientManager clientManager, SubscriptionDuration duration, RewardRarity rarity, int weight, int shardValue) + public PowerPlayReward(CoreClientManager clientManager, SubscriptionDuration duration, RewardRarity rarity, int shardValue) { - super(rarity, weight, shardValue); + super(rarity, shardValue); _clientManager = clientManager; _duration = duration; } @Override - public RewardData giveRewardCustom(Player player, RewardType rewardType) + public RewardData giveRewardCustom(Player player) { if (_clientManager.getAccountId(player) == -1) { @@ -59,16 +58,6 @@ public class PowerPlayReward extends Reward @Override public boolean equals(Object obj) { - if (obj instanceof PowerPlayReward) - { - return true; - } - return false; + return obj instanceof PowerPlayReward; } - - @Override - public int hashCode() - { - return getClass().hashCode(); - } -} \ No newline at end of file +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RankReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RankReward.java index 55e20e436..938fab9e0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RankReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RankReward.java @@ -1,33 +1,31 @@ package mineplex.core.reward.rewards; -import java.util.Random; - import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import mineplex.core.account.CoreClientManager; import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.reward.RankRewardData; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; +import mineplex.core.treasure.reward.RewardRarity; public class RankReward extends Reward { - private Random _random; - private CoreClientManager _clientManager; - public RankReward(CoreClientManager clientManager, int weight, int shardValue, RewardRarity rarity) + private static final ItemStack ITEM_STACK = new ItemStack(Material.NETHER_STAR); + private static final ItemStack ITEM_STACK_FAILED = new ItemStack(Material.PAPER); + + private final boolean _canPassLegend; + + public RankReward(RewardRarity rarity, int shardValue, boolean canPassLegend) { - super(rarity, weight, shardValue); - - _clientManager = clientManager; - _random = new Random(); + super(rarity, shardValue); + + _canPassLegend = canPassLegend; } - - private PermissionGroup getNext(PermissionGroup current, boolean canPassLegend) + + private PermissionGroup getNext(PermissionGroup current) { PermissionGroup newGroup = null; @@ -43,16 +41,10 @@ public class RankReward extends Reward newGroup = PermissionGroup.LEGEND; break; case LEGEND: - if (canPassLegend) - { - newGroup = PermissionGroup.TITAN; - } + newGroup = PermissionGroup.TITAN; break; case TITAN: - if (canPassLegend) - { - newGroup = PermissionGroup.ETERNAL; - } + newGroup = PermissionGroup.ETERNAL; break; default: break; @@ -62,58 +54,42 @@ public class RankReward extends Reward } @Override - public RewardData giveRewardCustom(Player player, RewardType rewardType) + public RewardData giveRewardCustom(Player player) { - PermissionGroup group = getNext(_clientManager.Get(player).getPrimaryGroup(), rewardType == RewardType.MYTHICAL_CHEST || rewardType == RewardType.TRICK_OR_TREAT_CHEST || rewardType == RewardType.THANKFUL_CHEST); - - if (rewardType == RewardType.MYTHICAL_CHEST && _random.nextDouble() < 0.01) // 1 Percent - { - group = PermissionGroup.ETERNAL; - } + PermissionGroup group = getNext(CLIENT_MANAGER.Get(player).getPrimaryGroup()); if (group == null) { - return new RewardData(null, getRarity().getColor() + "Rank Upgrade Error", new ItemStack(Material.PAPER), getRarity()); + return new RewardData(null, getRarity().getColor() + "Rank Upgrade Error", ITEM_STACK_FAILED, getRarity()); } + + CLIENT_MANAGER.setPrimaryGroup(player, group, () -> {}); - _clientManager.setPrimaryGroup(player, group, () -> {}); - - return new RankRewardData(getRarity().getColor() + group.getDisplay(false, false, false, true) + " Rank", new ItemStack(Material.NETHER_STAR), getRarity(), group); + return new RankRewardData(getRarity().getColor() + group.getDisplay(false, false, false, true) + " Rank", ITEM_STACK, getRarity(), group); } @Override public RewardData getFakeRewardData(Player player) { - PermissionGroup group = getNext(_clientManager.Get(player).getPrimaryGroup(), true); + PermissionGroup group = getNext(CLIENT_MANAGER.Get(player).getPrimaryGroup()); if (group == null) { - return new RewardData(null, getRarity().getColor() + "Rank Upgrade Error", new ItemStack(Material.PAPER), getRarity()); + return new RewardData(null, getRarity().getColor() + "Rank Upgrade Error", ITEM_STACK_FAILED, getRarity()); } - return new RankRewardData(getRarity().getColor() + group.getDisplay(false, false, false, true) + " Rank", new ItemStack(Material.NETHER_STAR), getRarity(), group); + return new RankRewardData(getRarity().getColor() + group.getDisplay(false, false, false, true) + " Rank", ITEM_STACK, getRarity(), group); } @Override public boolean canGiveReward(Player player) { - return !_clientManager.Get(player).getPrimaryGroup().inheritsFrom(PermissionGroup.ETERNAL); + return !CLIENT_MANAGER.Get(player).getPrimaryGroup().inheritsFrom(_canPassLegend ? PermissionGroup.ETERNAL : PermissionGroup.LEGEND); } @Override public boolean equals(Object obj) { - if (obj instanceof RankReward) - { - return true; - } - - return false; + return obj instanceof RankReward; } - - @Override - public int hashCode() - { - return getClass().hashCode(); - } -} \ No newline at end of file +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RuneAmplifierReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RuneAmplifierReward.java index f632be193..81cc9ff87 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RuneAmplifierReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RuneAmplifierReward.java @@ -1,63 +1,40 @@ package mineplex.core.reward.rewards; -import java.util.Random; - import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.reward.Reward; +import mineplex.core.treasure.reward.RewardRarity; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; -public class RuneAmplifierReward extends Reward +public class RuneAmplifierReward extends InventoryReward { - private Random _random; - private InventoryManager _inventoryManager; - private int _max, _min, _minutes; + private static final ItemStack ITEM_STACK = new ItemStack(Material.NETHER_STAR); - public RuneAmplifierReward(InventoryManager inventoryManager, int minutes, int min, int max, RewardRarity rarity, int weight, int shardValue) + private final int _minutes; + + public RuneAmplifierReward(int minutes, RewardRarity rarity, int shardValue) { - this(RANDOM, inventoryManager, minutes, min, max, rarity, weight, shardValue); + this(minutes, 1, rarity, shardValue); } - public RuneAmplifierReward(Random random, InventoryManager inventoryManager, int minutes, int min, int max, RewardRarity rarity, int weight, int shardValue) + public RuneAmplifierReward(int minutes, int amount, RewardRarity rarity, int shardValue) { - super(rarity, weight, shardValue); + this(minutes, amount, amount, rarity, shardValue); + } + + public RuneAmplifierReward(int minutes, int min, int max, RewardRarity rarity, int shardValue) + { + super("Clans Amplifier", "Rune Amplifier " + minutes, "Clans Amplifier", min, max, ITEM_STACK, rarity, shardValue); - _random = random; - _inventoryManager = inventoryManager; - _max = max; - _min = min; _minutes = minutes; } - @Override - public RewardData giveRewardCustom(Player player, RewardType rewardType) - { - int amountToGive; - - if (_min != _max) - { - amountToGive = _random.nextInt(_max - _min) + _min; - } - else - { - amountToGive = _min; - } - - _inventoryManager.addItemToInventory(player, "Rune Amplifier " + _minutes, amountToGive); - - return new RewardData(getRarity().getDarkColor() + "Clans Amplifier", getRarity().getColor() + amountToGive + " " + _minutes + " minute Clans Amplifier", new ItemStack(Material.NETHER_STAR), getRarity()); - } - @Override public RewardData getFakeRewardData(Player player) { - return new RewardData(getRarity().getDarkColor() + "Clans Amplifier", getRarity().getColor() + _minutes + " minute Clans Amplifier", new ItemStack(Material.NETHER_STAR), getRarity()); + return new RewardData(getRarity().getDarkColor() + "Clans Amplifier", getRarity().getColor() + _minutes + " minute Clans Amplifier", ITEM_STACK, getRarity()); } @Override @@ -65,15 +42,11 @@ public class RuneAmplifierReward extends Reward { return true; } - + @Override public boolean equals(Object obj) { - if (obj instanceof RuneAmplifierReward) - { - return ((RuneAmplifierReward) obj)._minutes == _minutes; - } - return false; + return obj instanceof RuneAmplifierReward && ((RuneAmplifierReward) obj)._minutes == _minutes; } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/SpinTicketReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/SpinTicketReward.java index 505af62dd..c09ceae96 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/SpinTicketReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/SpinTicketReward.java @@ -3,48 +3,38 @@ package mineplex.core.reward.rewards; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; -import java.util.Random; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import mineplex.core.Managers; -import mineplex.core.account.CoreClientManager; import mineplex.core.bonuses.BonusManager; import mineplex.core.common.util.Callback; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; +import mineplex.core.treasure.reward.RewardRarity; import mineplex.serverdata.database.DBPool; public class SpinTicketReward extends Reward { - private Random _random; - private CoreClientManager _clientManager; + private static final ItemStack ITEM_STACK = new ItemStack(Material.PAPER); + private int _max, _min; - public SpinTicketReward(CoreClientManager clientManager, int min, int max, RewardRarity rarity, int weight, int shardValue) + public SpinTicketReward(int min, int max, RewardRarity rarity, int shardValue) { - this(RANDOM, clientManager, min, max, rarity, weight, shardValue); - } + super(rarity, shardValue); - public SpinTicketReward(Random random, CoreClientManager clientManager, int min, int max, RewardRarity rarity, int weight, int shardValue) - { - super(rarity, weight, shardValue); - - _random = random; - _clientManager = clientManager; _max = max; _min = min; } @Override - public RewardData giveRewardCustom(Player player, RewardType rewardType) + public RewardData giveRewardCustom(Player player) { - if (_clientManager.getAccountId(player) == -1) + if (CLIENT_MANAGER.getAccountId(player) == -1) { return getFakeRewardData(player); } @@ -53,22 +43,16 @@ public class SpinTicketReward extends Reward if (_min != _max) { - amountToGive = _random.nextInt(_max - _min) + _min; + amountToGive = RANDOM.nextInt(_max - _min) + _min; } else { amountToGive = _min; } - final int accountId = _clientManager.getAccountId(player); - final Callback ticketCallback = new Callback() - { - public void run(Integer newTickets) - { - Managers.get(BonusManager.class).Get(player).setTickets(newTickets); - } - }; - _clientManager.runAsync(() -> + final int accountId = CLIENT_MANAGER.getAccountId(player); + final Callback ticketCallback = newTickets -> Managers.get(BonusManager.class).Get(player).setTickets(newTickets); + CLIENT_MANAGER.runAsync(() -> { try (Connection c = DBPool.getAccount().getConnection(); Statement statement = c.createStatement()) { @@ -82,10 +66,7 @@ public class SpinTicketReward extends Reward if (rs.next()) { final int newTickets = rs.getInt(1); - _clientManager.runSync(() -> - { - ticketCallback.run(newTickets); - }); + CLIENT_MANAGER.runSync(() -> ticketCallback.run(newTickets)); } } catch (Exception e) @@ -95,13 +76,13 @@ public class SpinTicketReward extends Reward } }); - return new RewardData(getRarity().getDarkColor() + "Carl Spin Ticket", getRarity().getColor() + amountToGive + " Carl Spin Ticket", new ItemStack(Material.PAPER), getRarity()); + return new RewardData(getRarity().getDarkColor() + "Carl Spin Ticket", getRarity().getColor() + amountToGive + " Carl Spin Ticket", ITEM_STACK, getRarity()); } @Override public RewardData getFakeRewardData(Player player) { - return new RewardData(getRarity().getDarkColor() + "Carl Spin Ticket", getRarity().getColor() + "Carl Spin ticket", new ItemStack(Material.PAPER), getRarity()); + return new RewardData(getRarity().getDarkColor() + "Carl Spin Ticket", getRarity().getColor() + "Carl Spin ticket", ITEM_STACK, getRarity()); } @Override @@ -113,11 +94,7 @@ public class SpinTicketReward extends Reward @Override public boolean equals(Object obj) { - if (obj instanceof SpinTicketReward) - { - return true; - } - return false; + return obj instanceof SpinTicketReward; } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TitleReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TitleReward.java index 39b04375e..322d6d142 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TitleReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TitleReward.java @@ -7,29 +7,31 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.Managers; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; import mineplex.core.titles.tracks.Track; import mineplex.core.titles.tracks.TrackManager; +import mineplex.core.treasure.reward.RewardRarity; public class TitleReward extends Reward { + private final ItemStack ITEM_STACK = new ItemStack(Material.BOOK); private final TrackManager _trackManager = Managers.require(TrackManager.class); private final Track _track; - public TitleReward(Track track, RewardRarity rarity, int weight, int shardValue) + public TitleReward(Track track, RewardRarity rarity, int shardValue) { - super(rarity, weight, shardValue); + super(rarity, shardValue); + if (track == null) { throw new IllegalStateException(); } + _track = track; } @Override - protected RewardData giveRewardCustom(Player player, RewardType rewardType) + protected RewardData giveRewardCustom(Player player) { _trackManager.unlockTrack(player, _track); return getFakeRewardData(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TreasureShardReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TreasureShardReward.java index 92422be6a..922d86bba 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TreasureShardReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TreasureShardReward.java @@ -1,53 +1,46 @@ package mineplex.core.reward.rewards; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import mineplex.core.account.CoreClient; -import mineplex.core.account.CoreClientManager; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.UtilMath; -import mineplex.core.donation.DonationManager; +import mineplex.core.common.util.UtilServer; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; +import mineplex.core.treasure.reward.RewardRarity; public class TreasureShardReward extends Reward { - private CoreClientManager _clientManager; - private DonationManager _donationManager; + + private static final ItemStack ITEM_STACK = new ItemStack(Material.PRISMARINE_SHARD); + private Reward _otherReward; private int _shardsMin = 0; private int _shardsMax = 0; - public TreasureShardReward(CoreClientManager clientManager, DonationManager donationManager, Reward otherReward, int weight, RewardRarity rarity) + public TreasureShardReward(Reward otherReward, RewardRarity rarity) { - super(rarity, weight, 0); + super(rarity, 0); - _clientManager = clientManager; - _donationManager = donationManager; _otherReward = otherReward; _shardsMin = (int) (otherReward.getShardValue() + (Math.random() * otherReward.getShardValue() / 2.0)); _shardsMax = _shardsMin; } - public TreasureShardReward(CoreClientManager clientManager, DonationManager donationManager, int min, int max, int weight, RewardRarity rarity) + public TreasureShardReward(int min, int max, RewardRarity rarity) { - super(rarity, weight, 0); - - _clientManager = clientManager; - _donationManager = donationManager; + super(rarity, 0); _shardsMin = min; _shardsMax = max; } @Override - public RewardData giveRewardCustom(Player player, RewardType rewardType) + public RewardData giveRewardCustom(Player player) { RewardData rewardData; final int shards = UtilMath.rRange(_shardsMin, _shardsMax); @@ -59,20 +52,13 @@ public class TreasureShardReward extends Reward } else { - rewardData = new RewardData(null, getRarity().getColor() + shards + " Treasure Shards", new ItemStack(Material.PRISMARINE_SHARD), getRarity()); + rewardData = new RewardData(null, getRarity().getColor() + shards + " Treasure Shards", ITEM_STACK, getRarity()); } - CoreClient client = _clientManager.Get(player); + CoreClient client = CLIENT_MANAGER.Get(player); // Give shards 5 seconds later for better effect - Bukkit.getScheduler().runTaskLater(_donationManager.getPlugin(), new Runnable() - { - @Override - public void run() - { - _donationManager.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, client, "Treasure", shards); - } - }, 100); + UtilServer.runSyncLater(() -> DONATION_MANAGER.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, client, "Treasure", shards), 100); return rewardData; } @@ -80,7 +66,7 @@ public class TreasureShardReward extends Reward @Override public RewardData getFakeRewardData(Player player) { - return new RewardData(null, getRarity().getColor() + "Treasure Shards", new ItemStack(Material.PRISMARINE_SHARD), getRarity()); + return new RewardData(null, getRarity().getColor() + "Treasure Shards", ITEM_STACK, getRarity()); } @Override @@ -92,15 +78,7 @@ public class TreasureShardReward extends Reward @Override public boolean equals(Object obj) { - if (obj instanceof TreasureShardReward) - return true; + return obj instanceof TreasureShardReward; + } +} - return false; - } - - @Override - public int hashCode() - { - return getClass().hashCode(); - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java deleted file mode 100644 index 3a499e89e..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java +++ /dev/null @@ -1,129 +0,0 @@ -package mineplex.core.reward.rewards; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.donation.DonationManager; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.reward.Reward; -import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; - -/** - * Created by shaun on 14-09-12. - */ -public class UnknownPackageReward extends Reward -{ - protected DonationManager _donationManager; - protected InventoryManager _inventoryManager; - private ItemStack _itemStack; - private String _header; - private String _name; - private String _packageName; - private String[] _alternativeNames; - - public UnknownPackageReward(DonationManager donationManager, InventoryManager inventoryManager, String header, String name, String packageName, ItemStack itemStack, RewardRarity rarity, int weight, int shardValue) - { - super(rarity, weight, shardValue); - _donationManager = donationManager; - _inventoryManager = inventoryManager; - _header = header; - _name = name; - _packageName = packageName; - _itemStack = itemStack; - _alternativeNames = new String[]{}; - } - - public UnknownPackageReward(DonationManager donationManager, InventoryManager inventoryManager, String header, String name, String packageName, ItemStack itemStack, RewardRarity rarity, int weight, int shardValue, String... alternativeNames) - { - super(rarity, weight, shardValue); - _donationManager = donationManager; - _inventoryManager = inventoryManager; - _header = header; - _name = name; - _packageName = packageName; - _itemStack = itemStack; - _alternativeNames = alternativeNames; - } - - @Override - protected RewardData giveRewardCustom(Player player, RewardType type) - { - _donationManager.purchaseUnknownSalesPackage(player, _packageName, GlobalCurrency.TREASURE_SHARD, 0, true, null); - - return new RewardData(getRarity().getDarkColor() + _header, getRarity().getColor() + _name, _itemStack, getRarity()); - } - - @Override - public boolean canGiveReward(Player player) - { - if (_donationManager.Get(player) == null) - { - System.out.println("Could not give reward " + _packageName + " to Offline Player: " + player.getName()); - return false; - } - boolean hasItem = false; - if (_donationManager.Get(player).ownsUnknownSalesPackage(_packageName)) - { - hasItem = true; - } - else if (_inventoryManager.Get(player).getItemCount(_packageName) > 0) - { - hasItem = true; - } - else - { - for (String altName : _alternativeNames) - { - if (_donationManager.Get(player).ownsUnknownSalesPackage(altName)) - { - hasItem = true; - } - if (_inventoryManager.Get(player).getItemCount(altName) > 0) - { - hasItem = true; - } - } - } - return !hasItem; - } - - @Override - public RewardData getFakeRewardData(Player player) - { - return new RewardData(getRarity().getDarkColor() + _header, getRarity().getColor() + _name, _itemStack, getRarity()); - } - - protected String getPackageName() - { - return _packageName; - } - - protected String getFriendlyName() - { - return _name; - } - - @Override - public boolean equals(Object obj) - { - if (obj instanceof UnknownPackageReward) - { - return ((UnknownPackageReward) obj).getPackageName().equals(_packageName); - } - return false; - } - - @Override - public int hashCode() - { - return _packageName.hashCode(); - } - - public String getHeader() - { - return _header; - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java b/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java index 7f91330ad..37c90429d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java @@ -4,6 +4,7 @@ import java.lang.reflect.Field; import net.minecraft.server.v1_8_R3.PlayerList; +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_8_R3.CraftServer; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerLoginEvent; @@ -14,6 +15,7 @@ import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.common.util.UtilServer; import mineplex.serverdata.Region; import mineplex.serverdata.data.ServerGroup; import mineplex.serverdata.servers.ServerManager; @@ -70,6 +72,11 @@ public class ServerConfiguration extends MiniPlugin @EventHandler public void onPlayerLogin(PlayerLoginEvent event) { + if (UtilServer.isTestServer() && !Bukkit.hasWhitelist()) + { + return; + } + if (_serverGroup.getStaffOnly() && !_clientManager.Get(event.getPlayer().getUniqueId()).hasPermission(Perm.JOIN_STAFF_SERVER)) { event.disallow(Result.KICK_OTHER, "This is a staff only server."); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/command/SetLevelCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/SetLevelCommand.java index 7e029ff1c..725d7b61f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/command/SetLevelCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/SetLevelCommand.java @@ -1,5 +1,7 @@ package mineplex.core.stats.command; +import mineplex.core.achievement.leveling.LevelingManager; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import mineplex.core.achievement.Achievement; @@ -43,13 +45,13 @@ public class SetLevelCommand extends CommandBase return; } - if (level < 0 || level > 100) + if (level < 0 || level > LevelingManager.getMaxLevel()) { UtilPlayer.message(caller, F.main("Stats", "That level is invalid")); return; } - int amountNeeded = 0; + long amountNeeded = 0; for (int i = 0; i < level; i++) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/titles/Titles.java b/Plugins/Mineplex.Core/src/mineplex/core/titles/Titles.java index 0f739111e..c2d57f8c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/titles/Titles.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/titles/Titles.java @@ -5,8 +5,10 @@ import java.sql.SQLException; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -51,10 +53,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -import mineplex.core.Managers; import mineplex.core.MiniDbClientPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.account.CoreClientManager; import mineplex.core.book.BookBuilder; import mineplex.core.common.DummyEntity; import mineplex.core.common.MinecraftVersion; @@ -72,7 +72,6 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.packethandler.IPacketHandler; import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketInfo; -import mineplex.core.titles.commands.GiveTrackCommand; import mineplex.core.titles.commands.TrackCommand; import mineplex.core.titles.tracks.Track; import mineplex.core.titles.tracks.TrackFormat; @@ -118,11 +117,14 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand .color(ChatColor.YELLOW) .create(); + private final Set _disabledPlayers; private boolean _disabled; private Titles() { - super("Titles", UtilServer.getPlugin(), Managers.require(CoreClientManager.class)); + super("Titles"); + + _disabledPlayers = new HashSet<>(); require(PacketHandler.class).addPacketHandler(this, PacketHandler.ListenerPriority.LOW, PacketPlayOutNamedEntitySpawn.class, PacketPlayOutEntityDestroy.class); } @@ -178,6 +180,7 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand { task.cancel(); } + _disabledPlayers.remove(event.getPlayer()); } @EventHandler @@ -222,7 +225,7 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand public void setOrToggleTrackForPlayer(Player player, Track track, boolean clickedBook) { - if (_disabled) + if (_disabled || _disabledPlayers.contains(player)) { UtilPlayer.message(player, F.main("Track", "Tracks are disabled right now!")); return; @@ -705,7 +708,7 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand private void updateTitle(Player player, Track track) { - if (_disabled) + if (_disabled || _disabledPlayers.contains(player)) return; if (track != null && track.getRequirements().getTier(player) != null) @@ -722,7 +725,7 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand private void updateTitle(Player player, String str) { - if (_disabled) + if (_disabled || _disabledPlayers.contains(player)) return; Map map = _armorStandIds.get(player.getEntityId()); @@ -753,12 +756,12 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand PacketPlayOutNamedEntitySpawn packet = (PacketPlayOutNamedEntitySpawn) packetInfo.getPacket(); Entity entity = UtilEnt.getEntityById(packet.a); - if (!(entity instanceof Player)) + if (!(entity instanceof Player) || _disabledPlayers.contains(entity)) { return; } - Player owner = (Player) UtilEnt.getEntityById(packet.a); + Player owner = (Player) entity; if (_gadgetManager.getActive(owner, GadgetType.MORPH) == null) { summonForEntity(packetInfo.getPlayer(), owner); @@ -962,7 +965,7 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand private void updateArmorStand(Player owner, Player receiver, String newName, int entityId) { - if (_disabled) + if (_disabled || _disabledPlayers.contains(owner)) return; switch (UtilPlayer.getVersion(receiver)) @@ -1063,15 +1066,9 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand { _disabled = false; - for (Player player : UtilServer.getPlayers()) + for (Player player : UtilServer.getPlayersCollection()) { - for (Player player1 : UtilServer.getPlayers()) - { - if (player != player1) - { - summonForEntity(player, player1); - } - } + forceEnable(player); } } } @@ -1084,13 +1081,39 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand for (Player player : UtilServer.getPlayers()) { - for (Player player1 : UtilServer.getPlayers()) + forceDisable(player); + } + } + } + + public void forceEnable(Player player) + { + if (_disabledPlayers.remove(player)) + { + for (Player other : UtilServer.getPlayersCollection()) + { + if (player.equals(other)) { - if (player != player1) - { - destroyForEntity(player, player1.getEntityId()); - } + continue; } + + summonForEntity(player, other); + } + } + } + + public void forceDisable(Player player) + { + if (_disabledPlayers.add(player)) + { + for (Player other : UtilServer.getPlayersCollection()) + { + if (player.equals(other)) + { + continue; + } + + destroyForEntity(player, other.getEntityId()); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/HolidayCheerTrack.java b/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/HolidayCheerTrack.java index 7a88cb9f4..297b857ac 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/HolidayCheerTrack.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/HolidayCheerTrack.java @@ -28,8 +28,8 @@ import mineplex.core.gadget.types.GadgetSet; import mineplex.core.titles.tracks.Track; import mineplex.core.titles.tracks.TrackFormat; import mineplex.core.titles.tracks.TrackTier; -import mineplex.core.treasure.TreasureType; import mineplex.core.treasure.event.TreasureStartEvent; +import mineplex.core.treasure.types.TreasureType; public class HolidayCheerTrack extends Track { @@ -45,15 +45,15 @@ public class HolidayCheerTrack extends Track POINTS.put(ItemFreezeCannon.class, 1); POINTS.put(ItemLovePotion.class, 10); - HOLIDAY_CHESTS.add(TreasureType.CHRISTMAS); - HOLIDAY_CHESTS.add(TreasureType.FREEDOM); - HOLIDAY_CHESTS.add(TreasureType.HAUNTED); - HOLIDAY_CHESTS.add(TreasureType.THANKFUL); - HOLIDAY_CHESTS.add(TreasureType.TRICK_OR_TREAT); - HOLIDAY_CHESTS.add(TreasureType.GINGERBREAD); - HOLIDAY_CHESTS.add(TreasureType.LOVE_CHEST); - HOLIDAY_CHESTS.add(TreasureType.ST_PATRICKS); - HOLIDAY_CHESTS.add(TreasureType.SPRING); +// HOLIDAY_CHESTS.add(TreasureType.CHRISTMAS); +// HOLIDAY_CHESTS.add(TreasureType.FREEDOM); +// HOLIDAY_CHESTS.add(TreasureType.HAUNTED); +// HOLIDAY_CHESTS.add(TreasureType.THANKFUL); +// HOLIDAY_CHESTS.add(TreasureType.TRICK_OR_TREAT); +// HOLIDAY_CHESTS.add(TreasureType.GINGERBREAD); +// HOLIDAY_CHESTS.add(TreasureType.LOVE_CHEST); +// HOLIDAY_CHESTS.add(TreasureType.ST_PATRICKS); +// HOLIDAY_CHESTS.add(TreasureType.SPRING); HOLIDAY_SETS.add(SetFreedom.class); HOLIDAY_SETS.add(SetCupidsLove.class); @@ -118,7 +118,7 @@ public class HolidayCheerTrack extends Track @EventHandler public void onUseCosmetic(TreasureStartEvent event) { - if (!HOLIDAY_CHESTS.contains(event.getTreasure().getTreasureType())) + if (!HOLIDAY_CHESTS.contains(event.getTreasureType())) return; int points = 100; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/LuckyTrack.java b/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/LuckyTrack.java index 9de427d99..1b8ad9dda 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/LuckyTrack.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/LuckyTrack.java @@ -13,12 +13,12 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import mineplex.core.reward.Reward; -import mineplex.core.reward.RewardRarity; import mineplex.core.titles.tracks.Track; import mineplex.core.titles.tracks.TrackFormat; import mineplex.core.titles.tracks.TrackTier; -import mineplex.core.treasure.TreasureType; import mineplex.core.treasure.event.TreasureStartEvent; +import mineplex.core.treasure.reward.RewardRarity; +import mineplex.core.treasure.types.TreasureType; public class LuckyTrack extends Track { @@ -33,14 +33,14 @@ public class LuckyTrack extends Track POINTS.put(RewardRarity.LEGENDARY, 5); POINTS.put(RewardRarity.MYTHICAL, 50); - MULTIPLIER.put(TreasureType.FREEDOM, 2); - MULTIPLIER.put(TreasureType.HAUNTED, 2); - MULTIPLIER.put(TreasureType.CHRISTMAS, 2); - MULTIPLIER.put(TreasureType.TRICK_OR_TREAT, 2); - MULTIPLIER.put(TreasureType.LOVE_CHEST, 2); - MULTIPLIER.put(TreasureType.ST_PATRICKS, 2); - MULTIPLIER.put(TreasureType.SPRING, 2); - MULTIPLIER.put(TreasureType.OMEGA, 3); +// MULTIPLIER.put(TreasureType.FREEDOM, 2); +// MULTIPLIER.put(TreasureType.HAUNTED, 2); +// MULTIPLIER.put(TreasureType.CHRISTMAS, 2); +// MULTIPLIER.put(TreasureType.TRICK_OR_TREAT, 2); +// MULTIPLIER.put(TreasureType.LOVE_CHEST, 2); +// MULTIPLIER.put(TreasureType.ST_PATRICKS, 2); +// MULTIPLIER.put(TreasureType.SPRING, 2); +// MULTIPLIER.put(TreasureType.OMEGA, 3); IRON.add(Material.IRON_SPADE); IRON.add(Material.IRON_PICKAXE); @@ -125,8 +125,8 @@ public class LuckyTrack extends Track int basePoints = POINTS.get(reward.getRarity()); - if (MULTIPLIER.get(event.getTreasure().getTreasureType()) != null) - basePoints *= MULTIPLIER.get(event.getTreasure().getTreasureType()); + if (MULTIPLIER.get(event.getTreasureType()) != null) + basePoints *= MULTIPLIER.get(event.getTreasureType()); incrementFor(event.getPlayer(), basePoints); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/TreasureHunterTrack.java b/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/TreasureHunterTrack.java index b7faf7d89..d8afeb06d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/TreasureHunterTrack.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/TreasureHunterTrack.java @@ -10,8 +10,8 @@ import mineplex.core.gadget.set.SetWisdom; import mineplex.core.titles.tracks.Track; import mineplex.core.titles.tracks.TrackFormat; import mineplex.core.titles.tracks.TrackTier; -import mineplex.core.treasure.TreasureType; import mineplex.core.treasure.event.TreasureStartEvent; +import mineplex.core.treasure.types.TreasureType; public class TreasureHunterTrack extends Track { @@ -23,17 +23,18 @@ public class TreasureHunterTrack extends Track POINTS.put(TreasureType.ANCIENT, 3); POINTS.put(TreasureType.MYTHICAL, 5); POINTS.put(TreasureType.ILLUMINATED, 10); - POINTS.put(TreasureType.FREEDOM, 25); - POINTS.put(TreasureType.HAUNTED, 25); - POINTS.put(TreasureType.CHRISTMAS, 25); +// POINTS.put(TreasureType.FREEDOM, 25); +// POINTS.put(TreasureType.HAUNTED, 25); +// POINTS.put(TreasureType.CHRISTMAS, 25); POINTS.put(TreasureType.TRICK_OR_TREAT, 25); - POINTS.put(TreasureType.THANKFUL, 25); - POINTS.put(TreasureType.GINGERBREAD, 25); - POINTS.put(TreasureType.LOVE_CHEST, 25); - POINTS.put(TreasureType.ST_PATRICKS, 25); - POINTS.put(TreasureType.SPRING, 25); +// POINTS.put(TreasureType.THANKFUL, 25); +// POINTS.put(TreasureType.GINGERBREAD, 25); +// POINTS.put(TreasureType.LOVE_CHEST, 25); +// POINTS.put(TreasureType.ST_PATRICKS, 25); +// POINTS.put(TreasureType.SPRING, 25); POINTS.put(TreasureType.OMEGA, 50); POINTS.put(TreasureType.MINESTRIKE, 3); + POINTS.put(TreasureType.MOBA, 25); } public TreasureHunterTrack() @@ -84,9 +85,9 @@ public class TreasureHunterTrack extends Track @EventHandler public void onUseCosmetic(TreasureStartEvent event) { - if (POINTS.containsKey(event.getTreasure().getTreasureType())) + if (POINTS.containsKey(event.getTreasureType())) { - int basePoints = POINTS.get(event.getTreasure().getTreasureType()); + int basePoints = POINTS.get(event.getTreasureType()); if (isSetActive(event.getPlayer(), SetWisdom.class)) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/UnluckyTrack.java b/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/UnluckyTrack.java index 3883722bd..f33e5fa6a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/UnluckyTrack.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/titles/tracks/standard/UnluckyTrack.java @@ -13,11 +13,11 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import mineplex.core.reward.Reward; -import mineplex.core.reward.RewardRarity; import mineplex.core.titles.tracks.Track; import mineplex.core.titles.tracks.TrackFormat; import mineplex.core.titles.tracks.TrackTier; import mineplex.core.treasure.event.TreasureStartEvent; +import mineplex.core.treasure.reward.RewardRarity; public class UnluckyTrack extends Track { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java deleted file mode 100644 index 894705556..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java +++ /dev/null @@ -1,36 +0,0 @@ -package mineplex.core.treasure; - -import org.bukkit.block.Block; - -/** - * Created by Shaun on 8/28/2014. - */ -public class BlockInfo -{ - private Block _block; - - private int _id; - private byte _data; - - public BlockInfo(Block block) - { - _block = block; - _id = block.getTypeId(); - _data = block.getData(); - } - - public Block getBlock() - { - return _block; - } - - public int getId() - { - return _id; - } - - public byte getData() - { - return _data; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/ChestData.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/ChestData.java deleted file mode 100644 index 43c970262..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/ChestData.java +++ /dev/null @@ -1,31 +0,0 @@ -package mineplex.core.treasure; - -import org.bukkit.block.Block; - -public class ChestData -{ - private Block _block; - private boolean _opened; - - public ChestData(Block block) - { - _block = block; - _opened = false; - } - - public boolean isOpened() - { - return _opened; - } - - public void setOpened(boolean opened) - { - _opened = opened; - } - - public Block getBlock() - { - return _block; - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java deleted file mode 100644 index 4ab193a74..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ /dev/null @@ -1,483 +0,0 @@ -package mineplex.core.treasure; - -import java.awt.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import net.minecraft.server.v1_8_R3.BlockPosition; -import net.minecraft.server.v1_8_R3.PacketPlayOutBlockAction; - -import org.bukkit.Bukkit; -import org.bukkit.Effect; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers; -import org.bukkit.entity.Player; - -import mineplex.core.account.permissions.PermissionGroup; -import mineplex.core.blockrestore.BlockRestore; -import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.particles.ColoredParticle; -import mineplex.core.common.util.particles.DustSpellColor; -import mineplex.core.hologram.HologramManager; -import mineplex.core.rankGiveaway.redis.TitanChestGiveawayMessage; -import mineplex.core.reward.RankRewardData; -import mineplex.core.reward.Reward; -import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardRarity; -import mineplex.core.reward.RewardType; -import mineplex.core.status.ServerStatusManager; -import mineplex.core.treasure.animation.Animation; -import mineplex.core.treasure.animation.BlockChangeAnimation; -import mineplex.core.treasure.animation.ChestOpenAnimation; -import mineplex.core.treasure.animation.ChestSpawnAnimation; -import mineplex.core.treasure.animation.FreedomChestAnimation; -import mineplex.core.treasure.animation.LootLegendaryAnimation; -import mineplex.core.treasure.animation.LootMythicalAnimation; -import mineplex.core.treasure.animation.LootRareAnimation; -import mineplex.core.treasure.animation.LootUncommonAnimation; -import mineplex.core.treasure.animation.TreasureRemoveAnimation; - -public class Treasure -{ - private BlockRestore _blockRestore; - - private List _chestBlockInfo = new ArrayList<>(); - private List _openedChestBlockInfo = new ArrayList<>(); - private List _otherBlockInfo = new ArrayList<>(); - - private Player _player; - private Random _random; - private Block _centerBlock; - private int _tickCount; - private TreasureType _treasureType; - - private ChestData[] _chestData; - private int _currentChest; - - private Reward[] _rewards; - private RewardType _rewardType; - private ConcurrentHashMap _rewardData = new ConcurrentHashMap(); - private int _currentReward; - - private boolean _finished; - private int _finishedTickCount; - - private LinkedList _animations; - - private HologramManager _hologramManager; - private ServerStatusManager _statusManager; - - private TreasureManager _treasureManager; - - public Treasure(TreasureManager treasureManager, Player player, Reward[] rewards, RewardType rewardType, Block centerBlock, Block[] chestBlocks, TreasureType treasureType, BlockRestore blockRestore, HologramManager hologramManager, ServerStatusManager statusManager) - { - this(treasureManager, player, new Random(), rewards, rewardType, centerBlock, chestBlocks, treasureType, hologramManager, statusManager); - - _blockRestore = blockRestore; - } - - public Treasure(TreasureManager treasureManager, Player player, Random seed, Reward[] rewards, RewardType rewardType, Block centerBlock, Block[] chestBlocks, TreasureType treasureType, HologramManager hologramManager, ServerStatusManager statusManager) - { - _treasureManager = treasureManager; - _player = player; - _random = seed; - - _treasureType = treasureType; - - _centerBlock = centerBlock; - _animations = new LinkedList(); - _hologramManager = hologramManager; - _statusManager = statusManager; - - _currentChest = 0; - _currentReward = 0; - _rewardType = rewardType; - _rewards = rewards; - - int max = chestBlocks.length; - _chestData = new ChestData[max]; - for (int i = 0; i < max; i++) - { - _chestData[i] = new ChestData(chestBlocks[i]); - } - - _animations.add(new BlockChangeAnimation(this, _otherBlockInfo, chestBlocks)); - - for (int i = 0; i < _rewards.length; i++) - { - Reward reward = _rewards[i]; - final int count = i; - reward.giveReward(_rewardType, player, new Callback() - { - @Override - public void run(RewardData data) - { - _rewardData.put(count, data); - } - }); - } - } - - public int getFinishedTickCount() - { - return _finishedTickCount; - } - - public void update() - { - if (_finished) - { - _finishedTickCount++; - } - - if (_tickCount % 10 == 0 && _currentChest < _chestData.length) - { - ChestSpawnAnimation chestSpawn = new ChestSpawnAnimation(this,_chestData[_currentChest].getBlock(), _chestBlockInfo, _centerBlock, _currentChest, _statusManager.getPlugin()); - _animations.add(chestSpawn); - _currentChest++; - } - - //Auto-open after 1 minute - if (_tickCount == 60 * 20) - { - for (BlockInfo blockInfo : _chestBlockInfo) - { - Block block = blockInfo.getBlock(); - openChest(block, false); - } - } - - Block block = _player.getTargetBlock((Set) null, 3); - if (block.getType() == _treasureType.getMaterial()) - { - ChestData data = getChestData(block); - if (!isFinished() && data != null && !data.isOpened()) - { - UtilParticle.ParticleType type = getTreasureType().getStyle().getHoverParticle(); - - if (_treasureType == TreasureType.OLD) - { - UtilParticle.PlayParticle(type, block.getLocation().add(0.5, 0.5, 0.5), 0F, 0F, 0F, 1, 4, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - else if (_treasureType == TreasureType.ANCIENT) - { - double yDif = 0.2 + 0.6 * Math.sin(Math.PI * (_tickCount / 10.0)); - double xDif = 0.7 * Math.sin(Math.PI * (_tickCount / 5.0)); - double zDif = 0.7 * Math.cos(Math.PI * (_tickCount / 5.0)); - float red = 0.1F + (float)( 0.4 * (1 + Math.cos(Math.PI * (_tickCount / 20.0)))); - UtilParticle.PlayParticle(type, block.getLocation().add(0.5 + xDif, 0.5 + yDif, 0.5 + zDif), red, 0.2F, 0.2F, 1F, 0, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - else if (_treasureType == TreasureType.CHRISTMAS) - { - UtilParticle.PlayParticle(type, block.getLocation().add(0.5f, 0.5f, 0.5f), 0.1f, 0.1F, 0.1F, 0.2F, 5, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - else if (_treasureType == TreasureType.ILLUMINATED) - { - UtilParticle.PlayParticleToAll(type, block.getLocation().add(0.5, 0.0, 0.5), 0.1f, 0.1f, 0.1f, 0.05f, 4, - ViewDist.NORMAL); - } - else if (_treasureType == TreasureType.FREEDOM) - { - int r = (int) (Math.random() * 3); - double rX = Math.random() * 2 - 1, rZ = Math.random() * 2 - 1; - ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, - new DustSpellColor((r == 0) ? Color.RED : (r == 1) ? Color.WHITE : Color.BLUE), - block.getLocation().add(.5 + rX, .7, .5 + rX)); - coloredParticle.display(); - } - else if (_treasureType == TreasureType.HAUNTED) - { - int r = (int) (Math.random() * 2); - double rX = Math.random() * 2 - 1, rZ = Math.random() * 2 - 1; - ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, - new DustSpellColor((r == 0) ? Color.ORANGE : Color.BLACK), - block.getLocation().add(.5 + rX, .7, .5 + rZ)); - coloredParticle.display(); - } - else if (_treasureType == TreasureType.LOVE_CHEST) - { - int r = (int) (Math.random() * 2); - double rX = Math.random() * 2 - 1, rZ = Math.random() * 2 - 1; - UtilParticle.PlayParticle(type, block.getLocation().add(.5 + rX, .7, .5 + rZ), .5f, .5f, .5f, .25f, 1, ViewDist.NORMAL); - } - else if (_treasureType == TreasureType.ST_PATRICKS) - { - int r = (int) (Math.random() * 2); - double rX = Math.random() * 2 - 1, rZ = Math.random() * 2 - 1; - ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, - new DustSpellColor((r == 0) ? Color.GREEN : new Color(0, 100, 0)), - block.getLocation().add(.5 + rX, .7, .5 + rZ)); - coloredParticle.display(); - } - else if (_treasureType == TreasureType.SPRING) - { - int r = (int) (Math.random() * 2); - double rX = Math.random() * 2 - 1, rZ = Math.random() * 2 - 1; - ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, - new DustSpellColor((r == 0) ? Color.RED : Color.YELLOW), - block.getLocation().add(.5 + rX, .7, .5 + rZ)); - coloredParticle.display(); - } - else - { - UtilParticle.PlayParticle(type, block.getLocation().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.2F, 0, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - } - } - - Iterator taskIterator = _animations.iterator(); - while (taskIterator.hasNext()) - { - Animation animation = taskIterator.next(); - - if (animation.isRunning()) - { - animation.run(); - } - else - { - taskIterator.remove(); - } - } - - _tickCount++; - } - - public Block getCenterBlock() - { - return _centerBlock; - } - - public void setBlock(Block block, Material material, byte data) - { - block.setType(material); - block.setData(data); - block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId()); - } - - public void openChest(Block block) - { - openChest(block, true); - } - - public void openChest(final Block block, final boolean swapList) - { - if(block.getType() != _treasureType.getMaterial()) return; - - // This is very experimental! Pray to god that this works - final ChestData data = getChestData(block); - if (data != null && !data.isOpened() && _currentReward < _rewards.length) - { - //final Reward reward = _rewards[_currentReward]; - final RewardData rewardData = _rewardData.get(_currentReward); - data.setOpened(true); - _currentReward++; - //reward.giveReward(_rewardType, _player, new Callback() - //{ - //@Override - //public void run(RewardData rewardData) - //{ - if (swapList) - { - BlockInfo info = getBlockInfo(block); - _chestBlockInfo.remove(info); - _openedChestBlockInfo.add(info); - } - - ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(Treasure.this, data, rewardData, _hologramManager); - _animations.add(chestOpenTask); - - // Extra effects based off the rarity of the treasure - if (_treasureType == TreasureType.FREEDOM) - { - _animations.add(new FreedomChestAnimation(Treasure.this, data.getBlock().getLocation().add(.5, .5, .5))); - } - if (rewardData.getRarity() == RewardRarity.UNCOMMON) - { - _animations.add(new LootUncommonAnimation(Treasure.this, data.getBlock())); - } - else if (rewardData.getRarity() == RewardRarity.RARE) - { - _animations.add(new LootRareAnimation(Treasure.this, data.getBlock().getLocation().add(0.5, 1.5, 0.5))); - Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cPurple + "Rare " + rewardData.getFriendlyName())); - } - else if (rewardData.getRarity() == RewardRarity.LEGENDARY) - { - _animations.add(new LootLegendaryAnimation(Treasure.this, data.getBlock())); - Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cGreen + "Legendary " + rewardData.getFriendlyName())); - } - else if (rewardData.getRarity() == RewardRarity.MYTHICAL) - { - if (rewardData instanceof RankRewardData) - { - if (((RankRewardData)rewardData).getWonRank() == PermissionGroup.TITAN) - { - TitanChestGiveawayMessage message = new TitanChestGiveawayMessage(_player.getName(), _statusManager.getCurrentServerName()); - message.publish(); - } - } - _animations.add(new LootMythicalAnimation(Treasure.this, data.getBlock())); - Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cRed + "Mythical " + rewardData.getFriendlyName())); - } - - if (isFinished()) - { - TreasureRemoveAnimation animation = new TreasureRemoveAnimation(Treasure.this, _chestBlockInfo); - _animations.add(animation); - _finished = true; - } - //} - //}); - } - } - - public BlockInfo getBlockInfo(Block block) - { - for (BlockInfo blockInfo : _chestBlockInfo) - { - if (blockInfo.getBlock().equals(block)) - return blockInfo; - } - return null; - } - - public void sendChestOpenPackets(Player... players) - { - for (ChestData data : _chestData) - { - if (data.isOpened()) - { - Block block = data.getBlock(); - PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(new BlockPosition(block.getX(), block.getY(), block.getZ()), CraftMagicNumbers.getBlock(block), 1, 1); - - for (Player player : players) - { - UtilPlayer.sendPacket(player, packet); - } - - } - } - - } - - public ChestData getChestData(Block block) - { - for (ChestData data : _chestData) - { - if (data.getBlock().equals(block)) - { - return data; - } - } - return null; - } - - public Player getPlayer() - { - return _player; - } - - public boolean isFinished() - { - return _currentReward == _rewards.length; - } - - public void cleanup() - { - - for (int i = _currentReward; i < _rewards.length; i++) - { - _rewards[_currentReward].giveReward(_rewardType, _player, new Callback() - { - @Override - public void run(RewardData data) - { - // Do nothing - System.out.println("Shards: " + data.getShards()); - } - }); - } - - _currentReward = _rewards.length; - - // Remove any extra blocks - resetBlockInfo(_chestBlockInfo); - resetBlockInfo(_openedChestBlockInfo); - resetBlockInfo(_otherBlockInfo); - - for (Animation animation : _animations) - { - animation.finish(); - } - _animations.clear(); - } - - public void resetBlockInfo(List blockInfoSet) - { - for (BlockInfo blockInfo : blockInfoSet) - { - resetBlockInfo(blockInfo); - } - - blockInfoSet.clear(); - } - - public void resetBlockInfo(BlockInfo blockInfo) - { - if (blockInfo == null) - return; - - Block block = blockInfo.getBlock(); - - if (block.getType().equals(Material.CHEST)) - { - UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_SMOKE, block.getLocation().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.1F, 10, - ViewDist.NORMAL, UtilServer.getPlayers()); -// block.getLocation().getWorld().createExplosion(block.getLocation().add(0.5, 0.5, 0.5), 0F); - } - block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId()); - - block.setTypeId(blockInfo.getId()); - block.setData(blockInfo.getData()); - } - - public boolean containsBlock(Block block) - { - for (BlockInfo info : _chestBlockInfo) - if (info.getBlock().equals(block)) - return true; - - return false; - } - - public TreasureType getTreasureType() - { - return _treasureType; - } - - public void addAnimation(Animation animation) - { - _animations.add(animation); - } - - public TreasureManager getTreasureManager() - { - return _treasureManager; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureKey.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureKey.java deleted file mode 100644 index 30ef863f6..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureKey.java +++ /dev/null @@ -1,19 +0,0 @@ -package mineplex.core.treasure; - -import mineplex.core.shop.item.SalesPackageBase; -import org.bukkit.ChatColor; -import org.bukkit.Material; - -/** - * Created by shaun on 14-09-18. - */ -public class TreasureKey extends SalesPackageBase -{ - public TreasureKey() - { - super("Treasure Key", Material.TRIPWIRE_HOOK, (byte) 0, new String[] { ChatColor.RESET + "Used to open Treasure Chests" }, 1000); - - KnownPackage = false; - OneTimePurchaseOnly = false; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java index 33401bf40..3028d4e42 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java @@ -1,456 +1,270 @@ package mineplex.core.treasure; import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerVelocityEvent; -import mineplex.core.account.CoreClientManager; +import mineplex.core.Managers; import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.donation.DonationManager; -import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.event.GadgetBlockEvent; import mineplex.core.hologram.Hologram; -import mineplex.core.hologram.HologramInteraction; +import mineplex.core.hologram.Hologram.HologramTarget; import mineplex.core.hologram.HologramManager; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.reward.Reward; -import mineplex.core.status.ServerStatusManager; -import mineplex.core.treasure.event.TreasureFinishEvent; -import mineplex.core.treasure.event.TreasurePreStartEvent; -import mineplex.core.treasure.event.TreasureStartEvent; -import mineplex.core.treasure.gui.TreasureShop; +import mineplex.core.treasure.types.Treasure; +import mineplex.core.treasure.types.TreasureType; +import mineplex.core.treasure.ui.TreasureShop; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; public class TreasureLocation implements Listener { - private TreasureManager _treasureManager; - private InventoryManager _inventoryManager; - private Hologram _hologram; - private HologramManager _hologramManager; - private ServerStatusManager _statusManager; - private Treasure _currentTreasure; - private Block _chestBlock; - private byte _chestBlockData; - private Block[] _chestSpawns; - private TreasureShop _shop; - private Location _resetLocation; - public TreasureLocation(TreasureManager treasureManager, InventoryManager inventoryManager, CoreClientManager clientManager, DonationManager donationManager, Block chestBlock, Block[] chestSpawns, Location resetLocation, HologramManager hologramManager, GadgetManager gadgetManager, ServerStatusManager statusManager) + private static final HologramManager HOLOGRAM_MANAGER = Managers.require(HologramManager.class); + private static final String HOLOGRAM_TEXT = C.cGreenB + "Open Treasure"; + + private final TreasureManager _manager; + private final Location _chest; + private final List _chests; + private final TreasureShop _shop; + private final Map _hologramMap; + + private TreasureSession _session; + private boolean _colourTick; + + public TreasureLocation(TreasureManager manager, Location chest) { - _treasureManager = treasureManager; - _resetLocation = resetLocation; - _inventoryManager = inventoryManager; - _chestBlock = chestBlock; - _chestBlockData = _chestBlock.getData(); - _chestSpawns = chestSpawns; - _hologramManager = hologramManager; - _statusManager = statusManager; - _currentTreasure = null; - _hologram = new Hologram(_hologramManager, chestBlock.getLocation().add(0.5, 1.5, 0.5), C.cGreen + C.Bold + "Open Treasure"); - _hologram.setInteraction(new HologramInteraction() - { + _manager = manager; + _chest = chest; + _chests = Arrays.asList( + _chest.clone().add(3, 0, 1), + _chest.clone().add(3, 0, -1), + _chest.clone().add(-3, 0, 1), + _chest.clone().add(-3, 0, -1), + _chest.clone().add(1, 0, 3), + _chest.clone().add(-1, 0, 3), + _chest.clone().add(1, 0, -3), + _chest.clone().add(-1, 0, -3) + ); + _shop = new TreasureShop(manager, manager.getClientManager(), manager.getDonationManager(), this); + _hologramMap = new HashMap<>(); - @Override - public void onClick(Player player, ClickType clickType) - { - if (clickType == ClickType.LEFT) - return; - - openShop(player); - } - }); - setHoloChestVisible(true); - _shop = new TreasureShop(treasureManager, _inventoryManager, clientManager, donationManager, gadgetManager, this); + setHologramVisible(true); } @EventHandler - public void onInteract(PlayerInteractEvent event) + public void playerInteract(PlayerInteractEvent event) { - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().equals(_chestBlock)) - { - openShop(event.getPlayer()); - event.setCancelled(true); - } - } - - public void attemptOpenTreasure(Player player, TreasureType treasureType) - { - if (isTreasureInProgress()) - { - player.sendMessage(F.main("Treasure", "Please wait for the current chest to be opened")); - return; - } - - TreasurePreStartEvent event = new TreasurePreStartEvent(player, treasureType); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) + if (!UtilEvent.isAction(event, ActionType.R_BLOCK) || inUse()) { return; } + Location location = event.getClickedBlock().getLocation(); - chargeAccount(player, treasureType, new Callback() + if (UtilMath.offsetSquared(location, _chest) > 2) { - @Override - public void run(Boolean success) - { - - if (!success) - { - player.sendMessage(F.main("Treasure", "You don't have any chests to open!")); - - return; - } - - - if (isTreasureInProgress()) - { - // Need to check again because of callback. Add item back - player.sendMessage(F.main("Treasure", "Please wait for the current chest to be opened")); - _inventoryManager.addItemToInventory(player, treasureType.getItemName(), 1); - return; - } - - if(treasureType == TreasureType.ILLUMINATED || treasureType == TreasureType.FREEDOM || treasureType == TreasureType.OMEGA - || treasureType == TreasureType.HAUNTED || treasureType == TreasureType.GINGERBREAD || treasureType == TreasureType.LOVE_CHEST) - { - if(!_treasureManager.hasItemsToGivePlayer(treasureType.getRewardPool(), player)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - _inventoryManager.addItemToInventory(player, treasureType.getItemName(), 1); - return; - } - } - - Reward[] rewards = _treasureManager.getRewards(player, treasureType.getRewardPool(), treasureType.getRewardType()); - for(Reward r : rewards) - { - if(r == null) - { - reset(); - player.sendMessage(F.main("Treasure", "There are no available items in this chest for you to open")); - _inventoryManager.addItemToInventory(player, treasureType.getItemName(), 1); - return; - } - } - - // Treasure is now being opened - setHoloChestVisible(false); - - if (treasureType != TreasureType.OLD) - { - String pron = "a "; - if (treasureType == TreasureType.ANCIENT || treasureType == TreasureType.ILLUMINATED || treasureType == TreasureType.OMEGA) - pron = "an "; - String name = treasureType.getName().replace("Chest", "Treasure"); - Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening " + pron + name)); - } - - Treasure treasure = new Treasure(_treasureManager, player, rewards, treasureType.getRewardType(), _chestBlock, _chestSpawns, treasureType, _treasureManager.getBlockRestore(), _hologramManager, _statusManager); - _currentTreasure = treasure; - - for (Entity entity : player.getNearbyEntities(3, 3, 3)) - { - UtilAction.velocity(entity, UtilAlg.getTrajectory(entity.getLocation(), treasure.getCenterBlock().getLocation()).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); - } - - Location teleportLocation = treasure.getCenterBlock().getLocation().add(0.5, 0, 0.5); - teleportLocation.setPitch(player.getLocation().getPitch()); - teleportLocation.setYaw(player.getLocation().getYaw()); - - player.teleport(teleportLocation); - TreasureStartEvent startEvent = new TreasureStartEvent(player, treasure, Arrays.asList(rewards)); - UtilServer.CallEvent(startEvent); - - UtilTextMiddle.display(treasureType.getName(), "Choose " + rewards.length + " " + UtilText.plural("Chest", rewards.length) + " To Open", 20, 180, 20, player); - UtilPlayer.message(player, F.main("Treasure", "Choose " + rewards.length + " " + UtilText.plural("Chest", rewards.length) + " To Open")); - - _treasureManager.addOpenStat(player, treasureType); - } - }); - } - - private void chargeAccount(Player player, TreasureType treasureType, Callback callback) - { - int itemCount = _inventoryManager.Get(player).getItemCount(treasureType.getItemName()); - if (itemCount > 0) - { - // Should always handle the callback for us - _inventoryManager.addItemToInventory(callback, player, treasureType.getItemName(), -1); + return; } - else - { - callback.run(false); - } - } - private void setHoloChestVisible(boolean visible) - { - if (visible) - { - _hologram.start(); - _chestBlock.setType(Material.CHEST); - _chestBlock.setData(_chestBlockData); - } - else - { - _hologram.stop(); - _chestBlock.setType(Material.AIR); - } - } - - public void cleanup() - { - if (_currentTreasure != null) - { - _currentTreasure.cleanup(); - _currentTreasure = null; - } + event.setCancelled(true); + _shop.attemptShopOpen(event.getPlayer()); } @EventHandler public void update(UpdateEvent event) { - if (event.getType() != UpdateType.TICK) + if (event.getType() != UpdateType.SEC || inUse()) + { return; - - if (isTreasureInProgress()) - { - Treasure treasure = _currentTreasure; - - treasure.update(); - - if (!treasure.getPlayer().isOnline() || (treasure.isFinished() && treasure.getFinishedTickCount() >= 80)) - { - treasure.cleanup(); - - TreasureFinishEvent finishEvent = new TreasureFinishEvent(treasure.getPlayer(), treasure); - Bukkit.getPluginManager().callEvent(finishEvent); - } } - } - @EventHandler - public void onTreasureFinish(TreasureFinishEvent event) - { - if (event.getTreasure().equals(_currentTreasure)) + for (Player player : UtilServer.getPlayersCollection()) { - Player player = _currentTreasure.getPlayer(); - player.teleport(_resetLocation); - _currentTreasure = null; - setHoloChestVisible(true); - } - } + Hologram hologram = _hologramMap.get(player); - @EventHandler(priority = EventPriority.HIGH) - public void interact(PlayerInteractEvent event) - { - Player player = event.getPlayer(); - if (isTreasureInProgress()) - { - if (_currentTreasure.getPlayer().equals(player)) + if (hologram == null) { - if (event.getAction() == Action.RIGHT_CLICK_BLOCK) - { - _currentTreasure.openChest(event.getClickedBlock()); - } - event.setCancelled(true); - } - else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) - { - ChestData chestData = _currentTreasure.getChestData(event.getClickedBlock()); - if (chestData != null) - { - event.setCancelled(true); - } - } - } - } - - @EventHandler - public void inventoryOpen(InventoryOpenEvent event) - { - // Ignore punish gui - if (event.getInventory().getTitle() != null && event.getInventory().getTitle().contains("Punish")) - return; - - if (isTreasureInProgress() && event.getPlayer().equals(_currentTreasure.getPlayer())) - { - event.setCancelled(true); - } - } - - @EventHandler - public void cancelMove(PlayerMoveEvent event) - { - Player player = event.getPlayer(); - if (isTreasureInProgress()) - { - if (_currentTreasure.getPlayer().equals(player)) - { - Treasure treasure = _currentTreasure; - Location centerLocation = treasure.getCenterBlock().getLocation().add(0.5, 0.5, 0.5); - if (event.getTo().distanceSquared(centerLocation) > 9) - { - Location newTo = centerLocation.clone(); - newTo.setPitch(event.getTo().getPitch()); - newTo.setYaw(event.getTo().getYaw()); - event.setTo(newTo); - } - } - else if (event.getFrom().getWorld().equals(_currentTreasure.getCenterBlock().getWorld()) && - event.getTo().getWorld().equals(_currentTreasure.getCenterBlock().getWorld())) - { - Location fromLocation = event.getFrom(); - Location toLocation = event.getTo(); - if (!fromLocation.getWorld().equals(toLocation.getWorld())) return; - Location centerLocation = _currentTreasure.getCenterBlock().getLocation().add(0.5, 1.5, 0.5); - double toDistanceFromCenter = centerLocation.distanceSquared(toLocation); - if (toDistanceFromCenter <= 16) - { - // Only cancel movement if they are moving towards the center - double fromDistanceFromCenter = centerLocation.distanceSquared(fromLocation); - if (toDistanceFromCenter < fromDistanceFromCenter) - { - Entity target = player; - while (target.getVehicle() != null) + hologram = new Hologram(HOLOGRAM_MANAGER, _chest.clone().add(0, 1, 0), true, "") + .setHologramTarget(HologramTarget.WHITELIST) + .addPlayer(player) + .setInteraction((interactor, clicktype) -> { - target = target.getVehicle(); - } - Location spawnLocation = new Location(target.getWorld(), 0, 64, 0); - UtilAction.velocity(target, UtilAlg.getTrajectory(target.getLocation(), spawnLocation).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); - } + if (clicktype == ClickType.LEFT) + { + return; + } + + _shop.attemptShopOpen(player); + }) + .start(); + _hologramMap.put(player, hologram); + } + + String amountLine = _manager.getChestsToOpen(player) > 0 ? ((_colourTick ? C.cAqua : C.cDAqua) + _manager.getChestsToOpen(player) + " Chests to Open") : null; + + if (amountLine == null) + { + hologram.setText(HOLOGRAM_TEXT); + } + else + { + hologram.setText(amountLine, HOLOGRAM_TEXT); + } + } + + _colourTick = !_colourTick; + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + Hologram hologram = _hologramMap.remove(event.getPlayer()); + + if (hologram != null) + { + hologram.stop(); + } + } + + public boolean openChest(Player player, Treasure treasure) + { + if (inUse()) + { + player.sendMessage(F.main(getManager().getName(), "This station is already in use.")); + return false; + } + + if (getManager().getChestsToOpen(player, treasure) <= 0) + { + player.sendMessage(F.main(getManager().getName(), "You do not have any " + F.name(treasure.getTreasureType().getName()) + " to open.")); + return false; + } + + if (!treasure.isDuplicates() && getManager().getRewardManager().hasAllItems(player, treasure)) + { + player.sendMessage(F.main(getManager().getName(), "You already have all the rewards possible for this chest.")); + return false; + } + + if (!treasure.hasAnimations()) + { + player.sendMessage(F.main(getManager().getName(), "Ruh ro rhaggy, looks like there's no ranimation set for the rhest type.")); + return false; + } + + getManager().getInventoryManager().addItemToInventory(success -> + { + if (!success) + { + player.sendMessage(F.main(getManager().getName(), "It looks like something went wrong when processing your request. Please try again.")); + } + else + { + _session = new TreasureSession(player, this, treasure); + + if (_session.hasFailed()) + { + getManager().getInventoryManager().addItemToInventory(player, treasure.getTreasureType().getItemName(), 1); + _session = null; + player.sendMessage(F.main(getManager().getName(), "Sorry, it looks like the rewards for the chest could not be generated.")); + return; } + + player.eject(); + player.leaveVehicle(); + player.teleport(_chest); + prepareChestArea(); + + String treasureName = treasure.getTreasureType().getName(); + + if (treasure.getTreasureType() != TreasureType.OLD) + { + boolean an = UtilText.startsWithVowel(ChatColor.stripColor(treasureName)); + Bukkit.broadcastMessage(F.main(getManager().getName(), F.name(player.getName()) + " is opening " + (an ? "an" : "a") + " " + F.name(treasureName) + ".")); + } + + UtilTextMiddle.display(treasureName, "Choose " + C.cYellow + treasure.getRewardsPerChest() + C.cWhite + " to open", 10, 30, 10, player); } - } + }, player, treasure.getTreasureType().getItemName(), -1); + + return true; } - @EventHandler - public void cancelTeleport(PlayerTeleportEvent event) + public void cleanup() { - Player player = event.getPlayer(); - if (isTreasureInProgress()) + for (Location location : _chests) { - if (_currentTreasure.getPlayer().equals(player)) - { - return; - } - if (_currentTreasure.getCenterBlock().getWorld() != event.getTo().getWorld()) - { - return; - } - double toDistanceFromCenter = _currentTreasure.getCenterBlock().getLocation().add(0.5, 1.5, 0.5).distanceSquared(event.getTo()); - if (toDistanceFromCenter <= 16) - { - Location spawnLocation = new Location(player.getWorld(), 0, 64, 0); - UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), spawnLocation).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); - } + location.getWorld().playEffect(location, Effect.STEP_SOUND, location.getBlock().getType()); + MapUtil.QuickChangeBlockAt(location, Material.AIR); } + + _session = null; + setHologramVisible(true); } - @EventHandler - public void cancelVelocity(PlayerVelocityEvent event) + private void prepareChestArea() { - Player player = event.getPlayer(); - if (isTreasureInProgress() && _currentTreasure.getPlayer().equals(player)) + _session.pushEntitiesAway(); + setHologramVisible(false); + } + + private void setHologramVisible(boolean visible) + { + if (visible) { - event.setCancelled(true); + MapUtil.QuickChangeBlockAt(_chest, Material.CHEST); + _hologramMap.values().forEach(Hologram::start); } - } - - @EventHandler - public void preventGadgetBlockEvent(GadgetBlockEvent event) - { - List blocks = event.getBlocks(); - - int x = _chestBlock.getX(); - int y = _chestBlock.getY(); - int z = _chestBlock.getZ(); - - for (Block block : blocks) + else { - int dx = Math.abs(x - block.getX()); - int dy = Math.abs(y - block.getY()); - int dz = Math.abs(z - block.getZ()); - - if (dx <= 4 && dz <= 4 && dy <= 4) - { - event.setCancelled(true); - return; - } + MapUtil.QuickChangeBlockAt(_chest, Material.AIR); + _hologramMap.values().forEach(Hologram::stop); } } - @EventHandler - public void quit(PlayerQuitEvent event) + private boolean inUse() { - if (isTreasureInProgress() && _currentTreasure.getPlayer().equals(event.getPlayer())) - { - reset(); - } + return _session != null; } - public boolean isTreasureInProgress() + public Location getChest() { - return _currentTreasure != null; + return _chest; } - public void reset() + public List getChestLocations() { - cleanup(); - _chestBlock.setType(Material.CHEST); - _chestBlock.setData(_chestBlockData); - _hologram.start(); + return Collections.unmodifiableList(_chests); } - public Treasure getCurrentTreasure() + public TreasureManager getManager() { - return _currentTreasure; + return _manager; } - public void openShop(Player player) + public TreasureSession getSession() { - _shop.attemptShopOpen(player); - } - - @Override - public String toString() - { - StringBuilder builder = new StringBuilder(); - builder.append("TesureLoc: ").append(_chestBlock.getX()).append(" : ").append(_chestBlock.getY()).append(" : ").append(_chestBlock.getZ()); - builder.append("BlockLocs: ["); - for(Block block : _chestSpawns) - { - builder.append("BlockLoc: ").append(block.getX()).append(" : ").append(block.getY()).append(" : ").append(block.getZ()).append(",\n"); - } - builder.append("]"); - return builder.toString(); + return _session; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java index 13a13af58..1c7285945 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java @@ -1,151 +1,153 @@ package mineplex.core.treasure; -import java.util.HashMap; -import java.util.Iterator; +import java.util.ArrayList; import java.util.List; -import java.util.Map; +import java.util.function.Consumer; import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerPickupItemEvent; -import org.bukkit.plugin.java.JavaPlugin; - -import com.google.common.collect.Lists; import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.blockrestore.BlockRestore; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; +import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; -import mineplex.core.gadget.GadgetManager; -import mineplex.core.hologram.HologramManager; +import mineplex.core.gadget.event.GadgetBlockEvent; +import mineplex.core.gadget.event.GadgetSelectLocationEvent; import mineplex.core.inventory.InventoryManager; -import mineplex.core.locations.LocationConstants; -import mineplex.core.pet.PetManager; -import mineplex.core.reward.Reward; -import mineplex.core.reward.RewardManager; -import mineplex.core.reward.RewardPool; -import mineplex.core.reward.RewardType; -import mineplex.core.stats.StatsManager; -import mineplex.core.status.ServerStatusManager; -import mineplex.core.treasure.animation.Animation; -import mineplex.core.treasure.event.TreasureFinishEvent; -import mineplex.core.treasure.event.TreasureStartEvent; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.recharge.Recharge; +import mineplex.core.treasure.reward.TreasureRewardManager; +import mineplex.core.treasure.types.AncientTreasure; +import mineplex.core.treasure.types.IlluminatedTreasure; +import mineplex.core.treasure.types.MOBATreasure; +import mineplex.core.treasure.types.MinestrikeTreasure; +import mineplex.core.treasure.types.MythicalTreasure; +import mineplex.core.treasure.types.OldTreasure; +import mineplex.core.treasure.types.OmegaTreasure; +import mineplex.core.treasure.types.Treasure; +import mineplex.core.treasure.types.TrickOrTreatTreasure; +@ReflectivelyCreateMiniPlugin public class TreasureManager extends MiniPlugin { - private CoreClientManager _clientManager; - private RewardManager _rewardManager; - private InventoryManager _inventoryManager; - private BlockRestore _blockRestore; - private HologramManager _hologramManager; - private StatsManager _statsManager; - private List _treasureLocations; - private List _blockLocations; - private List _items; - private Map _treasureAnimations = new HashMap<>(); + private final BlockRestore _blockRestore; + private final CoreClientManager _clientManager; + private final DisguiseManager _disguiseManager; + private final DonationManager _donationManager; + private final InventoryManager _inventoryManager; + private final TreasureRewardManager _rewardManager; - public TreasureManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, GadgetManager gadgetManager, BlockRestore blockRestore, HologramManager hologramManager, StatsManager statsManager, RewardManager rewardManager) + private final List _treasures; + private final List _treasureLocations; + + private TreasureManager() { - super("Treasure", plugin); + super("Treasure"); - _clientManager = clientManager; - _inventoryManager = inventoryManager; - _blockRestore = blockRestore; - _hologramManager = hologramManager; - _statsManager = statsManager; - _rewardManager = rewardManager; + _blockRestore = require(BlockRestore.class); + _clientManager = require(CoreClientManager.class); + _disguiseManager = require(DisguiseManager.class); + _donationManager = require(DonationManager.class); + _inventoryManager = require(InventoryManager.class); + _rewardManager = require(TreasureRewardManager.class); - _treasureLocations = Lists.newArrayList(); - _blockLocations = Lists.newArrayList(); - _items = Lists.newArrayList(); + _treasures = new ArrayList<>(); + _treasureLocations = new ArrayList<>(5); - for(Location location : LocationConstants.CHEST_LOCATIONS) + populateTreasureTypes(); + } + + private void populateTreasureTypes() + { + addTreasureType(new OldTreasure()); + addTreasureType(new AncientTreasure()); + addTreasureType(new MythicalTreasure()); + addTreasureType(new IlluminatedTreasure()); + addTreasureType(new OmegaTreasure()); + addTreasureType(new MinestrikeTreasure()); + addTreasureType(new MOBATreasure()); + addTreasureType(new TrickOrTreatTreasure()); + } + + private void addTreasureType(Treasure treasure) + { + _treasures.add(treasure); + } + + public void addTreasureLocation(Location location) + { + TreasureLocation treasureLocation = new TreasureLocation(this, location.subtract(0, 1, 0)); + UtilServer.RegisterEvents(treasureLocation); + _treasureLocations.add(treasureLocation); + } + + public int getChestsToOpen(Player player) + { + int chests = 0; + + for (Treasure treasure : _treasures) { - Location resetLocation = LocationConstants.getResetLocation(location); - Block[] blocks = setup(location.getBlock()); - _blockLocations.add(location); - - _treasureLocations.add(new TreasureLocation(this, _inventoryManager, clientManager, donationManager, location.getBlock(), blocks, resetLocation, _hologramManager, gadgetManager, statusManager)); + chests += getChestsToOpen(player, treasure); } - for (TreasureLocation treasureLocation : _treasureLocations) + return chests; + } + + public int getChestsToOpen(Player player, Treasure treasure) + { + return _inventoryManager.Get(player).getItemCount(treasure.getTreasureType().getItemName()); + } + + public void purchase(Consumer callback, Player player, Treasure treasure, int amount) + { + if (!Recharge.Instance.use(player, "Buy Treasure Chest", 1000, false, false)) { - _plugin.getServer().getPluginManager().registerEvents(treasureLocation, _plugin); + return; } - gadgetManager.setTreasureManager(this); - } + int ownedItems = _rewardManager.getOwnedItems(player, treasure); + int totalItems = _rewardManager.getTotalItems(treasure); - private Block[] setup(Block chestBlock) - { - List locations = Lists.newArrayList(new Location(chestBlock.getWorld(), chestBlock.getX() + 3, chestBlock.getY(), chestBlock.getZ() - 1), - new Location(chestBlock.getWorld(), chestBlock.getX() + 3, chestBlock.getY(), chestBlock.getZ() + 1), - new Location(chestBlock.getWorld(), chestBlock.getX() - 3, chestBlock.getY(), chestBlock.getZ() - 1), - new Location(chestBlock.getWorld(), chestBlock.getX() - 3, chestBlock.getY(), chestBlock.getZ() + 1), - new Location(chestBlock.getWorld(), chestBlock.getX() - 1, chestBlock.getY(), chestBlock.getZ() + 3), - new Location(chestBlock.getWorld(), chestBlock.getX() + 1, chestBlock.getY(), chestBlock.getZ() - 3), - new Location(chestBlock.getWorld(), chestBlock.getX() + 1, chestBlock.getY(), chestBlock.getZ() + 3), - new Location(chestBlock.getWorld(), chestBlock.getX() - 1, chestBlock.getY(), chestBlock.getZ() - 3)); - - Block[] blocks = new Block[locations.size()]; - for (int i = 0; i < blocks.length; i++) + if (ownedItems == totalItems) { - blocks[i] = locations.get(i).getBlock(); + player.sendMessage(F.main(_moduleName, "Sorry, it seems that you already have all the items for this chest!")); + return; } - return blocks; + + callback.accept(amount); } - @Override - public void disable() + public void giveTreasure(Player player, Treasure treasure, int amount) { - for (TreasureLocation treasureLocation : _treasureLocations) + _inventoryManager.addItemToInventory(player, treasure.getTreasureType().getItemName(), amount); + } + + @EventHandler + public void gadgetSelectBlock(GadgetBlockEvent event) + { + event.getBlocks().removeIf(block -> isTooClose(block.getLocation())); + } + + @EventHandler + public void gadgetSelectLocation(GadgetSelectLocationEvent event) + { + if (isTooClose(event.getLocation())) { - treasureLocation.cleanup(); - HandlerList.unregisterAll(treasureLocation); + event.setCancelled(true); } - _treasureLocations.clear(); } - public void addOpenStat(Player player, TreasureType treasureType) + private boolean isTooClose(Location gadgetLocation) { - _statsManager.incrementStat(player, "Global.Treasure." + treasureType.getStatName(), 1); - } - - public void addTreasureLocation(TreasureLocation loc) - { - _treasureLocations.add(loc); - _plugin.getServer().getPluginManager().registerEvents(loc, _plugin); - } - - public Reward[] getRewards(Player player, RewardPool.Type pool, RewardType rewardType) - { - return _rewardManager.getRewards(player, pool, rewardType); - } - - public boolean hasItemsToGivePlayer(RewardPool.Type pool, Player player) - { - return _rewardManager.hasItemsToGivePlayer(pool, player); - } - - public boolean isOpening(Player player) - { - for (TreasureLocation treasureLocation : _treasureLocations) + for (TreasureLocation location : _treasureLocations) { - Treasure treasure = treasureLocation.getCurrentTreasure(); - - if (treasure == null) - { - continue; - } - - if (treasure.getPlayer().equals(player)) + if (UtilMath.offsetSquared(location.getChest(), gadgetLocation) < 25) { return true; } @@ -164,67 +166,28 @@ public class TreasureManager extends MiniPlugin return _clientManager; } - public List getTreasureLocations() + public DisguiseManager getDisguiseManager() { - return _treasureLocations; + return _disguiseManager; } - public List getBlockLocations() + public DonationManager getDonationManager() { - return _blockLocations; + return _donationManager; } - @EventHandler - public void playCustomAnimation(TreasureStartEvent event) + public InventoryManager getInventoryManager() { - TreasureType treasureType = event.getTreasure().getTreasureType(); - /*if (treasureType == TreasureType.ST_PATRICKS) - { - StPatricksChestAnimation stPatricksChestAnimation = new StPatricksChestAnimation(event.getTreasure(), event.getTreasure().getCenterBlock()); - event.getTreasure().addAnimation(stPatricksChestAnimation); - _treasureAnimations.put(event.getTreasure(), stPatricksChestAnimation); - }*/ + return _inventoryManager; } - @EventHandler - public void stopCustomAnimation(TreasureFinishEvent event) + public TreasureRewardManager getRewardManager() { - if (_treasureAnimations.containsKey(event.getTreasure())) - { - Animation animation = _treasureAnimations.get(event.getTreasure()); - animation.setRunning(false); - } + return _rewardManager; } - public void addItem(Item item) + public List getTreasures() { - _items.add(item); - } - - @EventHandler - public void pickupItem(PlayerPickupItemEvent event) - { - if (_items.contains(event.getItem())) - { - event.setCancelled(true); - } - } - - @EventHandler - public void removeItems(UpdateEvent event) - { - if (event.getType() == UpdateType.TICK) - { - Iterator it = _items.iterator(); - while (it.hasNext()) - { - Item item = it.next(); - if (item.getTicksLived() >= 20) - { - item.remove(); - it.remove(); - } - } - } + return _treasures; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureSession.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureSession.java new file mode 100644 index 000000000..4397f4afd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureSession.java @@ -0,0 +1,260 @@ +package mineplex.core.treasure; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTime; +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardData; +import mineplex.core.treasure.animation.TreasureAnimation; +import mineplex.core.treasure.animation.TreasureRewardAnimation; +import mineplex.core.treasure.reward.RewardRarity; +import mineplex.core.treasure.types.Treasure; +import mineplex.core.treasure.util.TreasureUtil; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class TreasureSession implements Listener +{ + + private static final double CHEST_RADIUS = 3.5; + private static final long TIMEOUT = TimeUnit.MINUTES.toMillis(1); + + private final Player _player; + private final TreasureLocation _treasureLocation; + private final Treasure _treasure; + private final TreasureAnimation _animation; + private final List _rewardAnimations; + private final List _rewards; + private final List _rewardData; + private final List _openedChests; + private final long _start; + + TreasureSession(Player player, TreasureLocation treasureLocation, Treasure treasure) + { + _player = player; + _treasureLocation = treasureLocation; + _treasure = treasure; + _animation = treasure.getAnimations(treasureLocation); + _rewardAnimations = new ArrayList<>(); + _rewards = Treasure.getRewardManager().getRewards(player, treasure); + _rewardData = new ArrayList<>(treasure.getRewardsPerChest()); + _openedChests = new ArrayList<>(treasure.getRewardsPerChest()); + _start = System.currentTimeMillis(); + + if (!hasFailed()) + { + _rewards.forEach(reward -> reward.giveReward(player, _rewardData::add)); + _animation.setRunning(true); + UtilServer.RegisterEvents(this); + } + } + + @EventHandler + public void chestInteract(PlayerInteractEvent event) + { + if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) + { + return; + } + + Player player = event.getPlayer(); + Location location = event.getClickedBlock().getLocation(); + + boolean found = false; + + for (Location chestLocation : _treasureLocation.getChestLocations()) + { + if (!chestLocation.getBlock().equals(location.getBlock())) + { + continue; + } + + found = true; + break; + } + + if (!found) + { + return; + } + + event.setCancelled(true); + + if (!player.equals(event.getPlayer()) || _openedChests.contains(location) || isDone()) + { + return; + } + + RewardData rewardData = _rewardData.get(_openedChests.size()); + RewardRarity rarity = rewardData.getRarity(); + TreasureRewardAnimation rewardAnimation = TreasureRewardAnimation.getAnimationFor(_treasure, _treasureLocation, location.clone().add(0.5, 1, 0.5), rewardData); + Material material = event.getClickedBlock().getType(); + + if (material == Material.CHEST || material == Material.TRAPPED_CHEST || material == Material.ENDER_CHEST) + { + TreasureUtil.playChestOpen(location, true); + } + + if (rarity.ordinal() >= RewardRarity.RARE.ordinal()) + { + boolean an = UtilText.startsWithVowel(rewardData.getFriendlyName()); + Bukkit.broadcastMessage(F.main(_treasureLocation.getManager().getName(), F.name(player.getName()) + " found " + (an ? "an" : "a") + " " + F.name(rarity.getColor() + rarity.getName()) + " " + F.name(rewardData.getFriendlyName()) + ".")); + } + + if (rewardAnimation != null) + { + _rewardAnimations.add(rewardAnimation); + rewardAnimation.setRunning(true); + } + + _openedChests.add(location); + + if (isDone()) + { + UtilServer.runSyncLater(this::cleanup, 5 * 20); + } + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + if (!event.getPlayer().equals(getPlayer())) + { + return; + } + + cleanup(); + } + + private void cleanup() + { + _animation.cleanup(); + _rewardAnimations.forEach(TreasureRewardAnimation::cleanup); + + _treasureLocation.cleanup(); + UtilServer.Unregister(this); + } + + @EventHandler + public void updateAnimation(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + _rewardAnimations.stream() + .filter(TreasureAnimation::isRunning) + .forEach(TreasureAnimation::run); + + if (_animation.isRunning()) + { + _animation.run(); + } + } + + @EventHandler + public void updateEntities(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + { + return; + } + + pushEntitiesAway(); + } + + void pushEntitiesAway() + { + for (LivingEntity entity : UtilEnt.getInRadius(_treasureLocation.getChest(), CHEST_RADIUS).keySet()) + { + if (entity.equals(_player) || UtilEnt.hasFlag(entity, UtilEnt.FLAG_ENTITY_COMPONENT)) + { + continue; + } + + UtilAction.velocity(entity, UtilAlg.getTrajectory(_treasureLocation.getChest(), entity.getLocation()).setY(1)); + } + } + + @EventHandler + public void playerMove(PlayerMoveEvent event) + { + Player player = event.getPlayer(); + + if (!player.equals(getPlayer())) + { + return; + } + + if (UtilMath.offset2dSquared(player.getLocation(), _treasureLocation.getChest()) > CHEST_RADIUS * CHEST_RADIUS) + { + event.setTo(_treasureLocation.getChest()); + } + } + + @EventHandler + public void updateTimeout(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW || !UtilTime.elapsed(_start, TIMEOUT)) + { + return; + } + + getPlayer().sendMessage(F.main(_treasureLocation.getManager().getName(), "You took too long opening your chest. I picked your rewards for you:")); + + for (RewardData rewardData : _rewardData) + { + getPlayer().sendMessage(F.main(_treasureLocation.getManager().getName(), rewardData.getHeader() + " : " + rewardData.getFriendlyName())); + } + + cleanup(); + } + + public Player getPlayer() + { + return _player; + } + + public Treasure getTreasure() + { + return _treasure; + } + + public List getRewards() + { + return _rewards; + } + + boolean hasFailed() + { + return _rewards == null; + } + + private boolean isDone() + { + return _openedChests.size() == _treasure.getRewardsPerChest(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureStyle.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureStyle.java deleted file mode 100644 index 4d8960dd5..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureStyle.java +++ /dev/null @@ -1,157 +0,0 @@ -package mineplex.core.treasure; - -import org.bukkit.Sound; - -import mineplex.core.common.util.UtilParticle.ParticleType; - -public enum TreasureStyle -{ - OLD( - ParticleType.EXPLODE, - ParticleType.EXPLODE, - ParticleType.ENCHANTMENT_TABLE, - Sound.FIZZ, - Sound.HORSE_ARMOR), - - ANCIENT( - ParticleType.FLAME, - ParticleType.LAVA, - ParticleType.MOB_SPELL, - Sound.LAVA_POP, - Sound.EXPLODE), - - MYTHICAL( - ParticleType.HAPPY_VILLAGER, - ParticleType.LARGE_EXPLODE, - ParticleType.INSTANT_SPELL, - Sound.PORTAL_TRAVEL, - Sound.ANVIL_LAND), - - CHRISTMAS( - ParticleType.SNOW_SHOVEL, - ParticleType.SNOWBALL_POOF, - ParticleType.SNOW_SHOVEL, - Sound.FIZZ, - Sound.CHICKEN_EGG_POP), - - ILLUMINATED( - ParticleType.WITCH_MAGIC, - null, - ParticleType.WITCH_MAGIC, - Sound.ENDERDRAGON_DEATH, - Sound.BLAZE_HIT - ), - - FREEDOM( - ParticleType.RED_DUST, - ParticleType.RED_DUST, - ParticleType.RED_DUST, - Sound.FIZZ, - Sound.FIREWORK_TWINKLE2 - ), - OMEGA( - ParticleType.CRIT, - null, - ParticleType.CRIT, - Sound.FIRE, - Sound.FIREWORK_TWINKLE - ), - HALLOWEEN( - ParticleType.RED_DUST, - ParticleType.RED_DUST, - ParticleType.RED_DUST, - Sound.IRONGOLEM_HIT, - Sound.IRONGOLEM_THROW - ), - THANKFUL( - ParticleType.HAPPY_VILLAGER, - ParticleType.HAPPY_VILLAGER, - ParticleType.HAPPY_VILLAGER, - Sound.CHICKEN_IDLE, - Sound.CHICKEN_EGG_POP - ), - GINGERBREAD( - ParticleType.SNOW_SHOVEL, - ParticleType.SNOW_SHOVEL, - ParticleType.SNOW_SHOVEL, - Sound.DIG_SNOW, - Sound.DIG_SNOW - ), - MINESTRIKE( - ParticleType.FIREWORKS_SPARK, - ParticleType.FIREWORKS_SPARK, - ParticleType.INSTANT_SPELL, - Sound.EXPLODE, - Sound.EXPLODE - ), - LOVECHEST( - ParticleType.HEART, - ParticleType.HEART, - ParticleType.HEART, - Sound.VILLAGER_YES, - Sound.VILLAGER_YES - ), - STPATRICKS( - ParticleType.HAPPY_VILLAGER, - ParticleType.HAPPY_VILLAGER, - ParticleType.HAPPY_VILLAGER, - Sound.VILLAGER_YES, - Sound.VILLAGER_YES - ), - SPRING( - ParticleType.RED_DUST, - ParticleType.RED_DUST, - ParticleType.RED_DUST, - Sound.STEP_GRASS, - Sound.STEP_GRASS - ), - MOBA( - ParticleType.FIREWORKS_SPARK, - ParticleType.FIREWORKS_SPARK, - ParticleType.FIREWORKS_SPARK, - Sound.ANVIL_LAND, - Sound.ANVIL_LAND - ), - - ; - - private ParticleType _secondaryParticle; - private ParticleType _chestSpawnParticle; - private ParticleType _hoverParticle; - private Sound _sound; - private Sound _chestSpawnSound; - - TreasureStyle(ParticleType secondaryParticle, ParticleType chestSpawnParticle, ParticleType hoverParticle, Sound sound, Sound chestSpawnSound) - { - _secondaryParticle = secondaryParticle; - _chestSpawnParticle = chestSpawnParticle; - _hoverParticle = hoverParticle; - _sound = sound; - _chestSpawnSound = chestSpawnSound; - } - - public ParticleType getSecondaryParticle() - { - return _secondaryParticle; - } - - public ParticleType getChestSpawnParticle() - { - return _chestSpawnParticle; - } - - public ParticleType getHoverParticle() - { - return _hoverParticle; - } - - public Sound getSound() - { - return _sound; - } - - public Sound getChestSpawnSound() - { - return _chestSpawnSound; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureType.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureType.java deleted file mode 100644 index 668a12f78..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureType.java +++ /dev/null @@ -1,112 +0,0 @@ -package mineplex.core.treasure; - -import org.bukkit.Material; - -import mineplex.core.common.util.C; -import mineplex.core.reward.RewardPool; -import mineplex.core.reward.RewardPool.Type; -import mineplex.core.reward.RewardType; - -public enum TreasureType -{ - OLD(C.cYellow + "Old Treasure", "Old Chest", "Old", RewardType.OLD_CHEST, Material.CHEST, TreasureStyle.OLD, RewardPool.Type.NORMAL, true, 1000), - - ANCIENT(C.cGold + "Ancient Treasure", "Ancient Chest", "Ancient", RewardType.ANCIENT_CHEST, Material.TRAPPED_CHEST, TreasureStyle.ANCIENT, RewardPool.Type.NORMAL, true, 5000), - - MYTHICAL(C.cRed + "Mythical Treasure", "Mythical Chest", "Mythical", RewardType.MYTHICAL_CHEST, Material.ENDER_CHEST, TreasureStyle.MYTHICAL, RewardPool.Type.MYTHICAL, true, 10000), - - CHRISTMAS(C.cDGreen + "Winter Holiday Treasure", "Winter Chest", "Christmas", RewardType.WINTER_CHEST, Material.CHEST, TreasureStyle.CHRISTMAS, RewardPool.Type.WINTER_HOLIDAY, false, 15000), - - ILLUMINATED(C.cAqua + "Illuminated Treasure", "Illuminated Chest", "Illuminated", RewardType.ILLUMINATED_CHEST, Material.CHEST, TreasureStyle.ILLUMINATED, RewardPool.Type.ILLUMINATED, true, 20000), - - FREEDOM(C.cRed + "Freedom " + C.cBlue + "Treasure", "Freedom Treasure", "Freedom", RewardType.FREEDOM_CHEST, Material.CHEST, TreasureStyle.FREEDOM, RewardPool.Type.FREEDOM, true, 20000), - - OMEGA(C.cAqua + "Omega Chest", "Omega Chest", "Omega", RewardType.OMEGA_CHEST, Material.ENDER_CHEST, TreasureStyle.OMEGA, RewardPool.Type.OMEGA, false, 50000), - - HAUNTED(C.cGold + "Haunted Chest", "Haunted Chest", "Haunted", RewardType.HAUNTED_CHEST, Material.CHEST, TreasureStyle.HALLOWEEN, RewardPool.Type.HAUNTED, true, 35000), - - TRICK_OR_TREAT(C.cGold + "Trick or Treat Treasure", "Trick or Treat Chest", "TrickOrTreat", RewardType.TRICK_OR_TREAT_CHEST, Material.CHEST, TreasureStyle.HALLOWEEN, RewardPool.Type.TRICK_OR_TREAT, true, 20000), - - THANKFUL(C.cGold + "Thankful Treasure", "Thankful Chest", "ThankFul", RewardType.THANKFUL_CHEST, Material.CHEST, TreasureStyle.THANKFUL, RewardPool.Type.THANKFUL, true, 20000), - - GINGERBREAD(C.cRed + "Gingerbread " + C.cGreen + "Treasure", "Gingerbread Chest", "Gingerbread", RewardType.GINGERBREAD_CHEST, Material.CHEST, TreasureStyle.GINGERBREAD, RewardPool.Type.GINGERBREAD, true, 20000), - - MINESTRIKE(C.cGold + "Minestrike Treasure", "Minestrike Chest", "MinestrikeChest", RewardType.MINESTRIKE_CHEST, Material.CHEST, TreasureStyle.MINESTRIKE, RewardPool.Type.MINESTRIKE, true, 10000), - - LOVE_CHEST(C.cRed + "Love Treasure", "Love Chest", "LoveChest", RewardType.LOVE_CHEST, Material.CHEST, TreasureStyle.LOVECHEST, RewardPool.Type.LOVECHEST, true, 20000), - - ST_PATRICKS(C.cGreen + "St Patrick's Treasure", "St Patricks Chest", "StPatricksChest", RewardType.ST_PATRICKS, Material.CHEST, TreasureStyle.STPATRICKS,RewardPool.Type.STPATRICKS, true, 20000), - - SPRING(C.cGreen + "Spring Treasure", "Spring Chest", "SpringChest", RewardType.SPRING, Material.CHEST, TreasureStyle.SPRING, RewardPool.Type.SPRING, true, 20000), - - MOBA(C.cAqua + "Heroes of GWEN Treasure", "HOG Chest", "HOGChest", RewardType.MOBA, Material.ENDER_CHEST, TreasureStyle.MOBA, RewardPool.Type.MOBA, true, 12000), - ; - - private final String _name; - private final RewardType _rewardType; - private final Material _material; - private final TreasureStyle _treasureStyle; - private final String _itemName; - private final String _statName; - private final RewardPool.Type _rewardPool; - private final int _purchasePrice; - private final boolean _purchasable; - - TreasureType(String name, String itemName, String statName, RewardType rewardType, Material material, TreasureStyle treasureStyle, RewardPool.Type rewardPool, boolean purchasable, int purchasePrice) - { - _name = name; - _itemName = itemName; - _statName = statName; - _rewardType = rewardType; - _material = material; - _treasureStyle = treasureStyle; - _rewardPool = rewardPool; - _purchasePrice = purchasePrice; - _purchasable = purchasable; - } - - public RewardType getRewardType() - { - return _rewardType; - } - - public String getName() - { - return _name; - } - - public Material getMaterial() - { - return _material; - } - - public TreasureStyle getStyle() - { - return _treasureStyle; - } - - public String getItemName() - { - return _itemName; - } - - public String getStatName() - { - return _statName; - } - - public RewardPool.Type getRewardPool() - { - return _rewardPool; - } - - public int getPurchasePrice() - { - return _purchasePrice; - } - - public boolean isPurchasable() - { - return _purchasable; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/Animation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/Animation.java deleted file mode 100644 index a6b986660..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/Animation.java +++ /dev/null @@ -1,66 +0,0 @@ -package mineplex.core.treasure.animation; - -import mineplex.core.treasure.Treasure; - -/** - * Created by Shaun on 8/29/2014. - */ -public abstract class Animation -{ - private Treasure _treasure; - private boolean _running; - private int _ticks; - - public Animation(Treasure treasure) - { - _treasure = treasure; - _running = true; - } - - public Animation() {} - - public void run() - { - tick(); - _ticks++; - } - - protected abstract void tick(); - - protected abstract void onFinish(); - - public void finish() - { - if (_running) - { - _running = false; - onFinish(); - } - } - - public boolean isRunning() - { - return _running; - } - - public int getTicks() - { - return _ticks; - } - - public Treasure getTreasure() - { - return _treasure; - } - - public void setRunning(boolean b) - { - _running = b; - } - - public void setTicks(int ticks) - { - _ticks = ticks; - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/BlockChangeAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/BlockChangeAnimation.java deleted file mode 100644 index 44b54d3c9..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/BlockChangeAnimation.java +++ /dev/null @@ -1,354 +0,0 @@ -package mineplex.core.treasure.animation; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.Skull; - -import mineplex.core.common.MaterialData; -import mineplex.core.common.skin.SkinData; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilMath; -import mineplex.core.treasure.BlockInfo; -import mineplex.core.treasure.Treasure; -import mineplex.core.treasure.TreasureType; - -public class BlockChangeAnimation extends Animation -{ - private static final int MAX_RADIUS = 4; - - private int _currentRadius; - private List _blockInfoList; - private Block[] _chests; - - public BlockChangeAnimation(Treasure treasure, List blockInfoList, Block[] chests) - { - super(treasure); - - _currentRadius = 0; - _blockInfoList = blockInfoList; - _chests = chests; - } - - @Override - protected void tick() - { - if (_currentRadius == MAX_RADIUS) - { - finish(); - return; - } - else if (getTicks() % 10 == 0) - { - Block centerBlock = getTreasure().getCenterBlock().getRelative(BlockFace.DOWN); - - for (int x = -_currentRadius; x <= _currentRadius; x++) - { - for (int y = 0; y <= _currentRadius; y++) - { - for (int z = -_currentRadius; z <= _currentRadius; z++) - { - Block b = centerBlock.getRelative(x, y, z); - if (y > 0 && (b.getType() == Material.SMOOTH_BRICK || b.getType() == Material.STEP || b.getType() == Material.SMOOTH_STAIRS)) - { - _blockInfoList.add(new BlockInfo(b)); - b.setType(Material.AIR); - } - else if (b.getType() == Material.SMOOTH_BRICK) - { - if (getTreasure().getTreasureType() == TreasureType.OLD) - continue; - - Material mat; - byte data = -1; - if (getTreasure().getTreasureType() == TreasureType.ANCIENT) mat = Material.NETHER_BRICK; - else if (getTreasure().getTreasureType() == TreasureType.MYTHICAL) mat = Material.QUARTZ_BLOCK; - else if (getTreasure().getTreasureType() == TreasureType.CHRISTMAS) mat = Material.ICE; - else if (getTreasure().getTreasureType() == TreasureType.ILLUMINATED) - { - mat = Material.PRISMARINE; - data = 1; - } - else if (getTreasure().getTreasureType() == TreasureType.FREEDOM) - { - mat = Material.WOOL; - data = 11; - } - else if (getTreasure().getTreasureType() == TreasureType.OMEGA) - { - mat = Material.ENDER_STONE; - data = 0; - } - else if (getTreasure().getTreasureType() == TreasureType.HAUNTED || getTreasure().getTreasureType() == TreasureType.TRICK_OR_TREAT) - { - mat = Material.WOOL; - data = 1; - } - else if (getTreasure().getTreasureType() == TreasureType.GINGERBREAD) - { - mat = Material.STAINED_CLAY; - data = 13; - } - else if (getTreasure().getTreasureType() == TreasureType.LOVE_CHEST) - { - mat = Material.WOOL; - data = 6; - } - else if (getTreasure().getTreasureType() == TreasureType.ST_PATRICKS) - { - mat = Material.WOOL; - data = 13; - } - else if (getTreasure().getTreasureType() == TreasureType.SPRING) - { - mat = Material.GRASS; - } - else if (getTreasure().getTreasureType() == TreasureType.MOBA) - { - mat = Material.PRISMARINE; - data = 1; - } - else - continue; - - _blockInfoList.add(new BlockInfo(b)); - b.setType(mat); - if(data != -1) b.setData(data); - } - else if (b.getType() == Material.SMOOTH_STAIRS || b.getType() == Material.COBBLESTONE_STAIRS) - { - if (getTreasure().getTreasureType() == TreasureType.OLD) - continue; - - Material mat; - byte data = -1; - if (getTreasure().getTreasureType() == TreasureType.ANCIENT) mat = Material.NETHER_BRICK_STAIRS; - else if (getTreasure().getTreasureType() == TreasureType.MYTHICAL) mat = Material.QUARTZ_STAIRS; - else if (getTreasure().getTreasureType() == TreasureType.CHRISTMAS) mat = Material.PACKED_ICE; - else if (getTreasure().getTreasureType() == TreasureType.ILLUMINATED) - { - mat = Material.PRISMARINE; - data = 2; - } - else if (getTreasure().getTreasureType() == TreasureType.FREEDOM) - { - mat = Material.WOOL; - data = 14; - } - else if (getTreasure().getTreasureType() == TreasureType.OMEGA) - { - mat = Material.ENDER_STONE; - data = 0; - } - else if (getTreasure().getTreasureType() == TreasureType.HAUNTED || getTreasure().getTreasureType() == TreasureType.TRICK_OR_TREAT) - { - mat = Material.WOOL; - data = 15; - } - else if (getTreasure().getTreasureType() == TreasureType.GINGERBREAD) - { - mat = Material.STAINED_CLAY; - data = 14; - } - else if (getTreasure().getTreasureType() == TreasureType.LOVE_CHEST) - { - mat = Material.WOOL; - data = 14; - } - else if (getTreasure().getTreasureType() == TreasureType.ST_PATRICKS) - { - mat = Material.GOLD_BLOCK; - data = 0; - } - else if (getTreasure().getTreasureType() == TreasureType.SPRING) - { - mat = Material.DIRT; - data = 2; - } - else if (getTreasure().getTreasureType() == TreasureType.MOBA) - { - mat = Material.STAINED_CLAY; - data = 11; - } - else - continue; - - _blockInfoList.add(new BlockInfo(b)); - if(data == -1) data = b.getData(); - b.setType(mat); - b.setData(data); - } - - if(getTreasure().getTreasureType() == TreasureType.ILLUMINATED) - { - for(Block c : _chests) - { - if(c.equals(b)) - { - _blockInfoList.add(new BlockInfo(b)); - b.setType(Material.SEA_LANTERN); - } - } - } - else if (getTreasure().getTreasureType() == TreasureType.FREEDOM) - { - for(Block c : _chests) - { - if(c.equals(b)) - { - _blockInfoList.add(new BlockInfo(b)); - b.setType(Material.WOOL); - b.setData((byte) 0); - } - } - } - else if (getTreasure().getTreasureType() == TreasureType.HAUNTED) - { - for(Block c : _chests) - { - if(c.equals(b)) - { - _blockInfoList.add(new BlockInfo(b)); - b.setType(Material.JACK_O_LANTERN); - b.setData(getDirection(c)); - } - } - } - else if (getTreasure().getTreasureType() == TreasureType.TRICK_OR_TREAT) - { - for (Block c : _chests) - { - if (c.equals(b)) - { - _blockInfoList.add(new BlockInfo(b)); - b.setType(Material.CAULDRON); - b.setData((byte)3); - } - } - } - else if (getTreasure().getTreasureType() == TreasureType.GINGERBREAD) - { - for (Block c : _chests) - { - if (c.equals(b)) - { - _blockInfoList.add(new BlockInfo(b)); - try - { - Skull skull = UtilBlock.blockToSkull(c, SkinData.GINGERBREAD); - if (skull != null) - { - skull.setRotation(getSkullDirection(skull.getBlock())); - skull.update(); - } - else - { - c.setType(Material.AIR); - } - } catch (Exception e) - { - e.printStackTrace(); - } - } - } - } - else if (getTreasure().getTreasureType() == TreasureType.LOVE_CHEST) - { - for (Block c : _chests) - { - if (c.equals(b)) - { - _blockInfoList.add(new BlockInfo(b)); - b.setType(Material.WOOL); - b.setData((byte) 6); - } - } - } - else if (getTreasure().getTreasureType() == TreasureType.SPRING) - { - List materials = new ArrayList<>(); - materials.add(MaterialData.of(Material.LEAVES, (byte) 0)); - materials.add(MaterialData.of(Material.LEAVES, (byte) 1)); - materials.add(MaterialData.of(Material.LEAVES, (byte) 2)); - materials.add(MaterialData.of(Material.LEAVES, (byte) 3)); - materials.add(MaterialData.of(Material.LEAVES_2, (byte) 0)); - materials.add(MaterialData.of(Material.LEAVES_2, (byte) 1)); - for (Block c : _chests) - { - if (c.equals(b)) - { - _blockInfoList.add(new BlockInfo(b)); - int r = UtilMath.random.nextInt(materials.size()); - MaterialData materialData = materials.get(r); - b.setType(materialData.getMaterial()); - b.setData(materialData.getData()); - } - } - } - else if(getTreasure().getTreasureType() == TreasureType.MOBA) - { - for(Block c : _chests) - { - if(c.equals(b)) - { - _blockInfoList.add(new BlockInfo(b)); - b.setType(Material.PRISMARINE); - } - } - } - - } - } - } - _currentRadius++; - } - } - - @Override - protected void onFinish() - { - } - - private byte getDirection(Block block) - { - byte direction; - int relX = getTreasure().getCenterBlock().getX() - block.getX(); - int relZ = getTreasure().getCenterBlock().getZ() - block.getZ(); - if (Math.abs(relX) > Math.abs(relZ)) - { - if (relX > 0) - direction = (byte) 3; - else - direction = (byte) 1; - } - else - { - if (relZ > 0) - direction = (byte) 0; - else - direction = (byte) 2; - } - return direction; - } - - private BlockFace getSkullDirection(Block block) - { - byte direction = getDirection(block); - switch (direction) - { - case (byte) 0: - return BlockFace.SOUTH; - case (byte) 1: - return BlockFace.WEST; - case (byte) 2: - return BlockFace.NORTH; - case (byte) 3: - return BlockFace.EAST; - default: - return BlockFace.SOUTH; - } - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java deleted file mode 100644 index 8e65a6da1..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java +++ /dev/null @@ -1,125 +0,0 @@ -package mineplex.core.treasure.animation; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers; -import org.bukkit.entity.Item; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import mineplex.core.common.util.C; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.hologram.Hologram; -import mineplex.core.hologram.HologramManager; -import mineplex.core.reward.RankRewardData; -import mineplex.core.reward.RewardData; -import mineplex.core.treasure.ChestData; -import mineplex.core.treasure.Treasure; -import mineplex.core.treasure.TreasureType; -import net.minecraft.server.v1_8_R3.BlockPosition; -import net.minecraft.server.v1_8_R3.PacketPlayOutBlockAction; -import net.minecraft.server.v1_8_R3.TileEntity; -import net.minecraft.server.v1_8_R3.TileEntityEnderChest; - -/** - * Created by Shaun on 8/29/2014. - */ -public class ChestOpenAnimation extends Animation -{ - private ChestData _chestData; - private RewardData _rewardData; - private HologramManager _hologramManager; - - private Item _itemEntity; - private Hologram _hologram; - - public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData, HologramManager hologramManager) - { - super(treasure); - _hologramManager = hologramManager; - _chestData = chestData; - _rewardData = rewardData; - - if (treasure.getTreasureType() == TreasureType.TRICK_OR_TREAT && rewardData instanceof RankRewardData) - { - Block block = chestData.getBlock(); - for (Player other : UtilServer.getPlayers()) - { - other.sendBlockChange(block.getLocation(), Material.DRAGON_EGG, (byte)0); - } - return; - } - - // Send chest open packet - Block block = chestData.getBlock(); - PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(new BlockPosition(block.getX(), block.getY(), block.getZ()), - CraftMagicNumbers.getBlock(block), 1, 1); - - for (Player other : UtilServer.getPlayers()) - { - UtilPlayer.sendPacket(other, packet); - if (block.getType() == Material.ENDER_CHEST) - { - // Fix for Ender Chests closing as soon as they are opened - TileEntity tileEntity = ((CraftWorld) block.getWorld()).getTileEntityAt(block.getX(), block.getY(), block.getZ()); - if (tileEntity instanceof TileEntityEnderChest) - ((TileEntityEnderChest)tileEntity).g = 1; - } - - other.playSound(block.getLocation(), Sound.CHEST_OPEN, 1, 1); - } - } - - @Override - protected void tick() - { - if (getTicks() == 5) - { - double y = UtilBlock.getSize(_chestData.getBlock(), BlockFace.UP); - Location location = _chestData.getBlock().getLocation().add(0.5, y, 0.5); - _itemEntity = location.getWorld().dropItem(location, _rewardData.getDisplayItem()); - _itemEntity.setVelocity(new Vector(0, 0, 0)); - _itemEntity.setPickupDelay(Integer.MAX_VALUE); - } - else if (getTicks() == 15) - { - if (_rewardData.getHeader() != null) - { - _hologram = new Hologram(_hologramManager, _chestData.getBlock().getLocation().add(0.5, 1.4, 0.5), - _rewardData.getHeader(), _rewardData.getFriendlyName()); - } - else - { - _hologram = new Hologram(_hologramManager, _chestData.getBlock().getLocation().add(0.5, 1.4, 0.5), - _rewardData.getFriendlyName()); - } - _hologram.start(); - } - else if (getTicks() == 25) - { - if (_rewardData.isRewardedShards()) - { - if (_rewardData.getHeader() != null) - _hologram.setText(C.cWhite + "Duplicate", C.cAqua + "+" + _rewardData.getShards() + " Treasure Shards", " ", _rewardData.getHeader(), _rewardData.getFriendlyName()); - else - _hologram.setText(C.cWhite + "Duplicate", C.cAqua + "+" + _rewardData.getShards() + " Treasure Shards", " ", _rewardData.getFriendlyName()); - } - } - } - - public void onFinish() - { - if (_hologram != null) - { - _hologram.stop(); - _itemEntity.remove(); - } - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestSpawnAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestSpawnAnimation.java deleted file mode 100644 index 40105ed9e..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestSpawnAnimation.java +++ /dev/null @@ -1,450 +0,0 @@ -package mineplex.core.treasure.animation; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import net.minecraft.server.v1_8_R3.BlockPosition; -import net.minecraft.server.v1_8_R3.MathHelper; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Item; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerPickupItemEvent; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -import com.google.common.collect.Lists; - -import mineplex.core.Managers; -import mineplex.core.common.MaterialData; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilParticle.ParticleType; -import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.particles.ColoredParticle; -import mineplex.core.common.util.particles.DustSpellColor; -import mineplex.core.disguise.DisguiseManager; -import mineplex.core.disguise.disguises.DisguiseBat; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.particleeffects.BabyFireworkEffect; -import mineplex.core.particleeffects.CircleEffect; -import mineplex.core.treasure.BlockInfo; -import mineplex.core.treasure.Treasure; -import mineplex.core.treasure.TreasureType; - -public class ChestSpawnAnimation extends Animation implements Listener -{ - private static final int ANIMATION_DURATION = 80; - - private Block _block; - private byte _direction; - private Location _centerLocation; - - private Location _particleLocation; - private Vector _particleDirection; - - private Location _openingCenter; - - private List _chestBlockInfo; - - private double _radialOffset; - - private JavaPlugin _javaPlugin; - private int _babyFireworks = 0; - private int _circleAmount = 0; - - private int _currentHauntedColor = 0; - - private List _bats = Lists.newArrayList(); - private List _flowers = new ArrayList<>(); - private List _droppedFlowers = new ArrayList<>(); - - public ChestSpawnAnimation(Treasure treasure, Block block, List chestBlockInfo, Block openingCenter, double radialOffset, JavaPlugin javaPlugin) - { - super(treasure); - _block = block; - int relX = getTreasure().getCenterBlock().getX() - block.getX(); - int relZ = getTreasure().getCenterBlock().getZ() - block.getZ(); - if (Math.abs(relX) > Math.abs(relZ)) - { - if (relX > 0) - _direction = (byte) 5; - else - _direction = (byte) 4; - } - else - { - if (relZ > 0) - _direction = (byte) 3; - else - _direction = (byte) 2; - } - - _centerLocation = block.getLocation().clone().add(0.5, 0.5, 0.5); - _chestBlockInfo = chestBlockInfo; - - _particleLocation = openingCenter.getLocation().clone().add(0.5, 4, 0.5); - - _openingCenter = openingCenter.getLocation(); - - _particleDirection = UtilAlg.getTrajectory(_particleLocation, _centerLocation); - _particleDirection.multiply(UtilMath.offset(_particleLocation, _centerLocation) / (double)ANIMATION_DURATION); - - if (treasure.getTreasureType() == TreasureType.TRICK_OR_TREAT) - { - for (int i = 0; i < 5; i++) - { - ArmorStand stand = (ArmorStand)_centerLocation.getWorld().spawnEntity(_centerLocation, EntityType.ARMOR_STAND); - stand.setGravity(false); - stand.setVisible(false); - _bats.add(stand); - } - doBats(true, _centerLocation.clone().add(0, 6, 0), _bats); - } - - _radialOffset = radialOffset; - - _javaPlugin = javaPlugin; - - Bukkit.getPluginManager().registerEvents(this, javaPlugin); - } - - @Override - public void tick() - { - float scale = (float)((double)(ANIMATION_DURATION - getTicks()) / (double)ANIMATION_DURATION); - - //Move Particle Forwards - _particleLocation.add(_particleDirection); - - Iterator droppedFlowersIterator = _droppedFlowers.iterator(); - while (droppedFlowersIterator.hasNext()) - { - Item flower = droppedFlowersIterator.next(); - if (flower.getTicksLived() >= 20) - { - flower.remove(); - droppedFlowersIterator.remove(); - } - } - - //Play Particles - if (getTreasure().getTreasureType() == TreasureType.OLD || getTreasure().getTreasureType() == TreasureType.LOVE_CHEST) - { - UtilParticle.PlayParticle(getTreasure().getTreasureType().getStyle().getSecondaryParticle(), _centerLocation, 0.1f, 0.1f, 0.1f, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - else if (getTreasure().getTreasureType() == TreasureType.ANCIENT) - { - float x = (float) (Math.sin(getTicks()/4D)); - float z = (float) (Math.cos(getTicks()/4D)); - - Location newLoc = _particleLocation.clone(); - newLoc.add(UtilAlg.getLeft(_particleDirection).multiply(x * scale)); - newLoc.add(UtilAlg.getUp(_particleDirection).multiply(z * scale)); - - UtilParticle.PlayParticle(getTreasure().getTreasureType().getStyle().getSecondaryParticle(), newLoc, 0f, 0f, 0f, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - else if (getTreasure().getTreasureType() == TreasureType.MYTHICAL || getTreasure().getTreasureType() == TreasureType.MINESTRIKE || - getTreasure().getTreasureType() == TreasureType.ST_PATRICKS || getTreasure().getTreasureType() == TreasureType.MOBA) - { - float y = 5 * scale; - double width = 0.7 * ((double) getTicks() / (double) ANIMATION_DURATION); - - for (int i=0 ; i < 2 ; i++) - { - double lead = i * ((2d * Math.PI)/2); - - float x = (float) (Math.sin(getTicks()/4D + lead)); - float z = (float) (Math.cos(getTicks()/4D + lead)); - - if (getTreasure().getTreasureType() == TreasureType.MYTHICAL || getTreasure().getTreasureType() == TreasureType.MOBA) - { - UtilParticle.PlayParticle(getTreasure().getTreasureType().getStyle().getSecondaryParticle(), _centerLocation.clone().add(x * width, y, z * width), 0f, 0f, 0f, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - else - { - DustSpellColor minestrikeColor = new DustSpellColor(Color.YELLOW); - DustSpellColor stpatricksColor = new DustSpellColor(Color.GREEN); - ColoredParticle coloredParticle = new ColoredParticle(ParticleType.RED_DUST, - (getTreasure().getTreasureType() == TreasureType.MINESTRIKE) ? minestrikeColor : stpatricksColor, _centerLocation.clone().add(x * width, y, z * width)); - coloredParticle.display(); - } - } - } - else if (getTreasure().getTreasureType() == TreasureType.CHRISTMAS) - { - float spread = 1f - (getTicks() / (float)ANIMATION_DURATION); - - UtilParticle.PlayParticle(ParticleType.SNOW_SHOVEL, _centerLocation.clone().add(0, 5, 0), spread, 0.1f, spread, 0, 30, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - else if (getTreasure().getTreasureType() == TreasureType.ILLUMINATED || getTreasure().getTreasureType() == TreasureType.THANKFUL) - { - Location loc = _centerLocation.clone(); - loc.add(Vector.getRandom().subtract(Vector.getRandom()).multiply(0.5)); - - UtilParticle.PlayParticle(getTreasure().getTreasureType().getStyle().getSecondaryParticle(), loc, null, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - - if(getTicks() >= ANIMATION_DURATION-70 && getTicks() <= ANIMATION_DURATION-30) - { - loc = _centerLocation.clone().subtract(0, 0.5, 0); - - UtilParticle.PlayParticleToAll(ParticleType.PORTAL, loc, null, 0.55f, 20, ViewDist.NORMAL); - } - } - else if (getTreasure().getTreasureType() == TreasureType.FREEDOM) - { - if (_babyFireworks <= 2) - { - Location loc = _centerLocation.clone().add(Vector.getRandom().subtract(Vector.getRandom()).multiply(0.5)); - - int r = (int) (Math.random() * 3); - - BabyFireworkEffect babyFireworkEffect = new BabyFireworkEffect(loc, _javaPlugin, (r == 0) ? - Color.RED : (r == 1) ? Color.WHITE : Color.BLUE); - babyFireworkEffect.start(); - _babyFireworks++; - } - } - else if (getTreasure().getTreasureType() == TreasureType.OMEGA) - { - if (_circleAmount <= 15) - { - int particles = 50; - int radius = 1; - - for (int i = 0; i < particles; i++) - { - double angle = (double) 2 * Math.PI * i / particles; - double x = Math.cos(angle) * radius; - double z = Math.sin(angle) * radius; - Location loc = _centerLocation.clone().add(x, .1 * _circleAmount, z); - UtilParticle.PlayParticleToAll(ParticleType.PORTAL, loc, null, 0, 2, ViewDist.NORMAL); - } - } - - _circleAmount++; - } - else if (getTreasure().getTreasureType() == TreasureType.GINGERBREAD) - { - CircleEffect circleEffect = new CircleEffect(_javaPlugin, _centerLocation.clone().add(0, 0.5, 0), 1.3, Color.GREEN); - circleEffect.setMaxCircles(2); - circleEffect.start(); - } - else if (getTreasure().getTreasureType() == TreasureType.HAUNTED || getTreasure().getTreasureType() == TreasureType.TRICK_OR_TREAT) - { - float x = (float) (Math.sin(getTicks()/4D)); - float z = (float) (Math.cos(getTicks()/4D)); - - Location newLoc = _particleLocation.clone(); - newLoc.add(UtilAlg.getLeft(_particleDirection).multiply(x * scale)); - newLoc.add(UtilAlg.getUp(_particleDirection).multiply(z * scale)); - - Color color = (_currentHauntedColor == 0) ? Color.ORANGE : Color.BLACK; - ColoredParticle coloredParticle = new ColoredParticle(ParticleType.RED_DUST, new DustSpellColor(color), newLoc); - coloredParticle.display(); - if (_currentHauntedColor == 0) - { - _currentHauntedColor = 1; - } - else - { - _currentHauntedColor = 0; - } - - if (getTreasure().getTreasureType() == TreasureType.TRICK_OR_TREAT) - { - doBats(true, _centerLocation.clone().add(0, 6, 0), _bats); - } - } - else if (getTreasure().getTreasureType() == TreasureType.SPRING) - { - if (getTicks() % 5 == 0) - { - if (_flowers.size() == 0) - generateFlowerList(); - - int r = UtilMath.random.nextInt(_flowers.size()); - MaterialData materialData = _flowers.get(r); - Item flower = _openingCenter.getWorld().dropItem(_openingCenter.clone().add(0.5, 0, 0.5), ItemStackFactory.Instance.CreateStack(materialData.getMaterial(), materialData.getData(), 1, "Flower" + getTicks())); - Vector vel = new Vector(_openingCenter.getX() - _centerLocation.getX(), 0, _openingCenter.getZ() - _centerLocation.getZ()); - UtilAction.velocity(flower, vel, 0.1, false, 0, 0.2 + 1 * 0.4, 1, false); - _droppedFlowers.add(flower); - } - } - - //Spawn Chest - if (getTicks() >= ANIMATION_DURATION) - { - if(getTreasure().getTreasureType() == TreasureType.ILLUMINATED || getTreasure().getTreasureType() == TreasureType.GINGERBREAD) - { - UtilBlock.setQuick(_block.getWorld(), _block.getX(), _block.getY(), _block.getZ(), 0, (byte) 0); - } - - _chestBlockInfo.add(new BlockInfo(_block)); - getTreasure().setBlock(_block, getTreasure().getTreasureType().getMaterial(), _direction); - _block.getLocation().getWorld().playSound(_centerLocation, getTreasure().getTreasureType().getStyle().getChestSpawnSound(), 0.5f, 1f); - - - if(getTreasure().getTreasureType() == TreasureType.ILLUMINATED) - { - Location loc = _block.getLocation().add(0.5, 0.2, 0.5); - UtilParticle.PlayParticle(getTreasure().getTreasureType().getStyle().getSecondaryParticle(), loc, 0.7f, 0.7f, 0.7f, 1, 50, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - - if (getTreasure().getTreasureType() == TreasureType.TRICK_OR_TREAT) - { - _bats.forEach(bat -> bat.remove()); - _bats.clear(); - } - - UtilParticle.ParticleType particleType = getTreasure().getTreasureType().getStyle().getChestSpawnParticle(); - - if (particleType != null) - { - if (getTreasure().getTreasureType() == TreasureType.MINESTRIKE) - { - ColoredParticle coloredParticle = new ColoredParticle(ParticleType.RED_DUST, new DustSpellColor(Color.YELLOW), _centerLocation.clone().add(0, 1, 0)); - coloredParticle.display(50); - } - else if (getTreasure().getTreasureType() != TreasureType.FREEDOM && getTreasure().getTreasureType() != TreasureType.HAUNTED - && getTreasure().getTreasureType() != TreasureType.GINGERBREAD && getTreasure().getTreasureType() != TreasureType.LOVE_CHEST) - { - UtilParticle.PlayParticle(particleType, _centerLocation, 0.2f, 0.2f, 0.2f, 0, 50, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - else if (getTreasure().getTreasureType() == TreasureType.LOVE_CHEST) - { - UtilParticle.PlayParticle(particleType, _centerLocation, 0.2f, 0.2f, 0.2f, 0, 15, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - else if (getTreasure().getTreasureType() == TreasureType.FREEDOM) - { - int r = (int) (Math.random() * 3); - ColoredParticle coloredParticle = new ColoredParticle(ParticleType.RED_DUST, - new DustSpellColor((r == 0) ? Color.RED : (r == 1) ? Color.WHITE : Color.BLUE), - _centerLocation.clone().add(.5, .5, .5)); - coloredParticle.display(); - } - else if (getTreasure().getTreasureType() == TreasureType.GINGERBREAD) - { - int r = (int) (Math.random() * 3); - ColoredParticle coloredParticle = new ColoredParticle(ParticleType.RED_DUST, - new DustSpellColor(Color.GREEN), - _centerLocation.clone().add(.5, .5, .5)); - coloredParticle.display(); - } - else - { - int r = (int) (Math.random() * 2); - ColoredParticle coloredParticle = new ColoredParticle(ParticleType.RED_DUST, - new DustSpellColor((r == 0) ? Color.ORANGE : Color.BLACK), - _centerLocation.clone().add(.5, .5, .5)); - coloredParticle.display(); - } - } - else - { - // TODO This doesnt work for 1.8 clients - int i = MathHelper.floor(_centerLocation.getX()); - int j = MathHelper.floor(_centerLocation.getY() - 0.20000000298023224D - 0.5); - int k = MathHelper.floor(_centerLocation.getZ()); - ((CraftWorld) _centerLocation.getWorld()).getHandle().triggerEffect(2006, new BlockPosition(i, j, k), MathHelper.f(60 - 3.0F)); - } - finish(); - } - } - - @Override - protected void onFinish() - { - HandlerList.unregisterAll(this); - for (Item item : _droppedFlowers) - { - item.remove(); - } - _droppedFlowers.clear(); - } - - private void doBats(boolean initial, Location center, List bats) - { - for (int i = 0; i < bats.size(); i++) - { - ArmorStand bat = bats.get(i); - double lead = i * ((2d * Math.PI)/bats.size()); - - double sizeMod = 2; - - //Orbit - double speed = 10d; - double oX = -Math.sin(getTicks()/speed + lead) * 2 * sizeMod; - double oY = 0; - double oZ = Math.cos(getTicks()/speed + lead) * 2 * sizeMod; - - if (initial) - { - DisguiseManager disguiseMan = Managers.get(DisguiseManager.class); - DisguiseBat disguise = new DisguiseBat(bat); - disguise.setSitting(false); - disguiseMan.disguise(disguise); - bat.teleport(center.clone().add(oX, oY, oZ)); - } - else - { - Location to = center.clone().add(oX, oY, oZ); - UtilEnt.LookAt(bat, to); - UtilAction.velocity(bat, UtilAlg.getTrajectory(bat.getLocation(), to), 0.4, false, 0, 0.1, 1, true); - } - } - } - - private void generateFlowerList() - { - _flowers.add(MaterialData.of(Material.LONG_GRASS, (byte) 1)); - _flowers.add(MaterialData.of(Material.LONG_GRASS, (byte) 2)); - _flowers.add(MaterialData.of(Material.DEAD_BUSH, (byte) 0)); - _flowers.add(MaterialData.of(Material.YELLOW_FLOWER, (byte) 0)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 0)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 1)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 2)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 3)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 4)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 5)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 6)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 7)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 8)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 0)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 1)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 2)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 3)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 4)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 5)); - } - - @EventHandler - public void onPickup(PlayerPickupItemEvent event) - { - if (_droppedFlowers.contains(event.getItem())) - event.setCancelled(true); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/FreedomChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/FreedomChestAnimation.java deleted file mode 100644 index 64f09c1d8..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/FreedomChestAnimation.java +++ /dev/null @@ -1,37 +0,0 @@ -package mineplex.core.treasure.animation; - -import mineplex.core.common.util.UtilFirework; -import mineplex.core.treasure.Treasure; -import org.bukkit.Location; - -public class FreedomChestAnimation extends Animation -{ - - private Location _centerLocation; - - public FreedomChestAnimation(Treasure treasure, Location location) - { - super(treasure); - _centerLocation = location; - } - - @Override - protected void tick() - { - if (getTicks() == 2) - { - UtilFirework.playFreedomFirework(_centerLocation); - } - else if (getTicks() >= 60) - { - finish(); - } - } - - @Override - protected void onFinish() - { - - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootLegendaryAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootLegendaryAnimation.java deleted file mode 100644 index aa2b224de..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootLegendaryAnimation.java +++ /dev/null @@ -1,85 +0,0 @@ -package mineplex.core.treasure.animation; - -import java.util.Random; - -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.FireworkEffect.Type; -import org.bukkit.block.Block; - -import mineplex.core.common.util.UtilFirework; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.treasure.Treasure; - -/** - * Created by shaun on 14-09-12. - */ -public class LootLegendaryAnimation extends Animation -{ - /** - * Played when a "Very Rare" chest is opened - */ - - private Random _random = new Random(); - private Block _chestBlock; - - public LootLegendaryAnimation(Treasure treasure, Block chestBlock) - { - super(treasure); - - _chestBlock = chestBlock; - } - - @Override - protected void tick() - { - if (getTicks() < 12 && getTicks() % 3 == 0) - { - UtilFirework.playFirework(_chestBlock.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.LIME, true, true); - } - - if (getTicks() == 1) - { - _chestBlock.getLocation().getWorld().playSound(_chestBlock.getLocation().add(0.5, 0.5, 0.5), Sound.ENDERDRAGON_DEATH, 10F, 2.0F); - } - else if (getTicks() < 35) - { - double radius = 2 - (getTicks() / 10D * 2); - int particleAmount = 20 - (getTicks() * 2); - Location _centerLocation = _chestBlock.getLocation().add(0.5, 0.1, 0.5); - for (int i = 0; i < particleAmount; i++) - { - double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; - double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; - - Location location = _centerLocation.clone().add(xDiff, 0, zDiff); - UtilParticle.PlayParticle(UtilParticle.ParticleType.HAPPY_VILLAGER, location, 0, 0, 0, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - } - else if (getTicks() < 40) - { - double xDif = _random.nextGaussian() * 0.5; - double zDif = _random.nextGaussian() * 0.5; - double yDif = _random.nextGaussian() * 0.5; - - Location loc = _chestBlock.getLocation().add(0.5, 0.5, 0.5).add(xDif, zDif, yDif); - - loc.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 0F); - } - else - { - finish(); - } - } - - @Override - protected void onFinish() - { - - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootMythicalAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootMythicalAnimation.java deleted file mode 100644 index bdb720f4c..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootMythicalAnimation.java +++ /dev/null @@ -1,65 +0,0 @@ -package mineplex.core.treasure.animation; - -import java.util.Random; - -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.FireworkEffect.Type; -import org.bukkit.block.Block; -import org.bukkit.util.Vector; - -import mineplex.core.common.util.UtilFirework; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.treasure.Treasure; - -/** - * Created by shaun on 14-09-12. - */ -public class LootMythicalAnimation extends Animation -{ - /** - * Played when a "Very Rare" chest is opened - */ - - private Random _random = new Random(); - private Block _chestBlock; - - public LootMythicalAnimation(Treasure treasure, Block chestBlock) - { - super(treasure); - - _chestBlock = chestBlock; - } - - @Override - protected void tick() - { - if (getTicks() < 30 && getTicks() % 3 == 0) - { - UtilFirework.playFirework(_chestBlock.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.RED, true, true); - } - - if (getTicks() == 1) - { - _chestBlock.getLocation().getWorld().playSound(_chestBlock.getLocation().add(0.5, 0.5, 0.5), Sound.PORTAL_TRAVEL, 10F, 2.0F); - _chestBlock.getLocation().getWorld().playSound(_chestBlock.getLocation().add(0.5, 0.5, 0.5), Sound.ZOMBIE_UNFECT, 10F, 0.1F); - } - else if (getTicks() < 60) - { - UtilFirework.launchFirework(_chestBlock.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.RED, true, true, - new Vector((Math.random()-0.5)*0.05, 0.1, (Math.random()-0.5)*0.05), 1); - } - else - { - finish(); - } - } - - @Override - protected void onFinish() - { - - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootRareAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootRareAnimation.java deleted file mode 100644 index 5824c2db3..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootRareAnimation.java +++ /dev/null @@ -1,80 +0,0 @@ -package mineplex.core.treasure.animation; - -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.FireworkEffect.Type; - -import mineplex.core.common.util.UtilFirework; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.treasure.Treasure; - -/** - * Created by shaun on 2014-09-09. - */ -public class LootRareAnimation extends Animation -{ - /** - * Played when a "Rare" chest is opened - */ - - private Location _centerLocation; - - public LootRareAnimation(Treasure treasure, Location centerLocation) - { - super(treasure); - - _centerLocation = centerLocation; - } - - @Override - protected void tick() - { - if (getTicks() == 2) - { - UtilFirework.playFirework(_centerLocation, Type.BALL, Color.FUCHSIA, false, false); - - _centerLocation.getWorld().playSound(_centerLocation, Sound.WITHER_SPAWN, 10F, 1.2F); - } - else if (getTicks() >= 60) - { - finish(); - } - - //Particle Ground - { - double currentRotation = getTicks() / 20D; - double radius = currentRotation; - double yDiff = currentRotation; - double xDiff = Math.sin(currentRotation * 2 * Math.PI) * radius; - double zDiff = Math.cos(currentRotation * 2 * Math.PI) * radius; - - Location location = _centerLocation.clone().add(xDiff, yDiff, zDiff); - - UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - - //Particle Spiral Up - double radius = getTicks() / 20D; - int particleAmount = getTicks() / 2; - for (int i = 0; i < particleAmount; i++) - { - double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; - double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; - - Location location = _centerLocation.clone().add(xDiff, -1.3, zDiff); - UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - } - - @Override - protected void onFinish() - { - - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootUncommonAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootUncommonAnimation.java deleted file mode 100644 index c294d4840..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/LootUncommonAnimation.java +++ /dev/null @@ -1,57 +0,0 @@ -package mineplex.core.treasure.animation; - -import java.util.Random; - -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.FireworkEffect.Type; -import org.bukkit.block.Block; - -import mineplex.core.common.util.UtilFirework; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.treasure.Treasure; - -/** - * Created by shaun on 2014-09-09. - */ -public class LootUncommonAnimation extends Animation -{ - /** - * Played when an "Uncommon" chest is opened - */ - - private Random _random = new Random(); - private Block _block; - - public LootUncommonAnimation(Treasure treasure, Block block) - { - super(treasure); - - _block = block; - } - - @Override - protected void tick() - { - if (getTicks() >= 10) - finish(); - - if (getTicks() == 10) - { - UtilFirework.playFirework(_block.getLocation().add(0.5, 0.5, 0.5), Type.BURST, Color.AQUA, false, false); - } - else if (getTicks() % 2 == 0) - { - UtilParticle.PlayParticle(UtilParticle.ParticleType.HEART, _block.getLocation().add(0.5, 1.2, 0.5), 0.5F, 0.2F, 0.5F, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - } - } - - @Override - protected void onFinish() - { - - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ParticleAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ParticleAnimation.java deleted file mode 100644 index b717b39a6..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ParticleAnimation.java +++ /dev/null @@ -1,71 +0,0 @@ -package mineplex.core.treasure.animation; - -import java.util.ArrayList; - -import org.bukkit.util.Vector; - -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.treasure.Treasure; - -/** - * Created by Shaun on 8/29/2014. - */ -public class ParticleAnimation extends Animation -{ - private static double MODIFIER = 0.5; - private static ArrayList PATH = new ArrayList(); - - static - { - double y = 5; - double x = 3; - double z = -3; - - for (z = -3; z <= 3; z += MODIFIER) - { - PATH.add(new Vector(x, y, z)); - } - - for (x = 3; x >= -3; x -= MODIFIER) - { - PATH.add(new Vector(x, y, z)); - } - - for (z = 3; z >= -3; z -= MODIFIER) - { - PATH.add(new Vector(x, y, z)); - } - - for (x = -3; x <= 3; x += MODIFIER) - { - PATH.add(new Vector(x, y, z)); - } - } - - private int pathPosition = 0; - - public ParticleAnimation(Treasure treasure) - { - super(treasure); - } - - @Override - protected void tick() - { - Vector position = PATH.get(pathPosition); - - UtilParticle.PlayParticle(getTreasure().getTreasureType().getStyle().getSecondaryParticle(), getTreasure().getCenterBlock().getLocation().add(0.5, 0, 0.5).add(position), 0, 0, 0, 0, 1, - ViewDist.NORMAL, UtilServer.getPlayers()); - - pathPosition = (pathPosition + 1) % PATH.size(); - } - - @Override - protected void onFinish() - { - - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/StPatricksChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/StPatricksChestAnimation.java deleted file mode 100644 index 4b65b5787..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/StPatricksChestAnimation.java +++ /dev/null @@ -1,46 +0,0 @@ -package mineplex.core.treasure.animation; - -import java.awt.Color; - -import org.bukkit.block.Block; -import org.bukkit.util.Vector; - -import mineplex.core.common.shape.ShapeWings; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.treasure.Treasure; - -public class StPatricksChestAnimation extends Animation -{ - - private Block _center; - private int _tick = 0; - - private ShapeWings _cloverBlack = new ShapeWings(UtilParticle.ParticleType.RED_DUST.particleName, new Vector(1, 1, 1), 1, 0, '#', ShapeWings.DEFAULT_ROTATION, ShapeWings.FOUR_LEAF_CLOVER); - private ShapeWings _cloverDarkGreen = new ShapeWings(UtilParticle.ParticleType.RED_DUST.particleName, new Vector(1, 1, 1), 1, 0, '%', ShapeWings.DEFAULT_ROTATION, ShapeWings.FOUR_LEAF_CLOVER); - private ShapeWings _cloverGreen = new ShapeWings(UtilParticle.ParticleType.RED_DUST.particleName, new Vector(1, 1, 1), 1, 0, '*', ShapeWings.DEFAULT_ROTATION, ShapeWings.FOUR_LEAF_CLOVER); - - public StPatricksChestAnimation(Treasure treasure, Block center) - { - super(treasure); - _center = center; - } - - @Override - protected void tick() - { - _tick++; - if (_tick % 5 == 0) - { - _cloverBlack.displayColored(_center.getLocation().add(0, 5, 0), Color.BLACK); - _cloverDarkGreen.displayColored(_center.getLocation().add(0, 5, 0), new Color(0, 100, 0)); - _cloverGreen.displayColored(_center.getLocation().add(0, 5, 0), Color.GREEN); - } - } - - @Override - protected void onFinish() - { - - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureAnimation.java new file mode 100644 index 000000000..489ee40eb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureAnimation.java @@ -0,0 +1,186 @@ +package mineplex.core.treasure.animation; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.EulerAngle; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; +import mineplex.core.disguise.disguises.DisguiseBase; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.TreasureSession; +import mineplex.core.treasure.animation.event.TreasureAnimationFinishEvent; +import mineplex.core.treasure.types.Treasure; + +public abstract class TreasureAnimation implements Runnable +{ + + private final Treasure _treasure; + private final TreasureLocation _treasureLocation; + + protected final List _entities; + protected final List _stands; + protected final List _items; + + private int _tick; + private boolean _running; + + public TreasureAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + _treasure = treasure; + _treasureLocation = treasureLocation; + + _entities = new ArrayList<>(); + _stands = new ArrayList<>(); + _items = new ArrayList<>(); + } + + protected abstract void onStart(); + + @Override + public void run() + { + onTick(); + _tick++; + + _items.forEach(item -> + { + if (!UtilEnt.hasFlag(item, UtilEnt.FLAG_NO_REMOVE) && item.getTicksLived() > 20) + { + item.remove(); + } + }); + } + + public abstract void onTick(); + + protected abstract void onFinish(); + + public void cleanup() + { + _entities.forEach(Entity::remove); + _entities.clear(); + _stands.forEach(Entity::remove); + _stands.clear(); + _items.forEach(Entity::remove); + _items.clear(); + } + + protected T spawnEntity(Location location, Class clazz) + { + return spawnEntity(location, clazz, false); + } + + protected T spawnEntity(Location location, Class clazz, boolean ai) + { + T entity = location.getWorld().spawn(location, clazz); + + if (!ai) + { + UtilEnt.vegetate(entity); + } + + UtilEnt.ghost(entity, true, false); + UtilEnt.CreatureLook(entity, location.getPitch(), location.getYaw()); + UtilEnt.addFlag(entity, UtilEnt.FLAG_ENTITY_COMPONENT); + _entities.add(entity); + + return entity; + } + + protected void disguise(DisguiseBase disguise) + { + _treasureLocation.getManager().getDisguiseManager().disguise(disguise); + } + + protected ArmorStand spawnArmourStand(Location location) + { + float yaw = Math.round(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _treasureLocation.getChest())) / 90F) * 90F; + location.setYaw(yaw); + + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _treasureLocation.getChest()))); + ArmorStand stand = location.getWorld().spawn(location, ArmorStand.class); + + stand.setVisible(false); + stand.setGravity(false); + _stands.add(stand); + + return stand; + } + + protected void shakeArmourStand(ArmorStand stand, double magnitude) + { + stand.setHeadPose( + new EulerAngle( + UtilMath.random(-magnitude, magnitude), + UtilMath.random(-magnitude, magnitude), + UtilMath.random(-magnitude, magnitude) + ) + ); + } + + protected void resetArmourStand(ArmorStand stand) + { + stand.setHeadPose(EulerAngle.ZERO); + } + + protected Item spawnItem(Location location, ItemStack itemStack, boolean temporary) + { + Item item = location.getWorld().dropItemNaturally(location, itemStack); + + if (!temporary) + { + UtilEnt.addFlag(item, UtilEnt.FLAG_NO_REMOVE); + } + + item.setPickupDelay(Integer.MAX_VALUE); + _items.add(item); + + return item; + } + + public Treasure getTreasure() + { + return _treasure; + } + + public TreasureLocation getTreasureLocation() + { + return _treasureLocation; + } + + public int getTicks() + { + return _tick; + } + + public boolean isRunning() + { + return _running; + } + + public void setRunning(boolean running) + { + _running = running; + + if (running) + { + onStart(); + } + else + { + onFinish(); + TreasureSession session = _treasureLocation.getSession(); + UtilServer.CallEvent(new TreasureAnimationFinishEvent(session.getPlayer(), session, this)); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureOpenAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureOpenAnimation.java new file mode 100644 index 000000000..5880aa6e9 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureOpenAnimation.java @@ -0,0 +1,94 @@ +package mineplex.core.treasure.animation; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.scheduler.BukkitRunnable; + +import mineplex.core.blockrestore.BlockRestore; +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilServer; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.types.Treasure; +import mineplex.core.treasure.util.TreasureUtil; + +public abstract class TreasureOpenAnimation extends TreasureAnimation +{ + + private final List _blocksToRestore; + + public TreasureOpenAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + super(treasure, treasureLocation); + + _blocksToRestore = new ArrayList<>(); + } + + protected void createChestAt(Location location, Material material) + { + MapUtil.QuickChangeBlockAt(location, material, TreasureUtil.getChestFacing(location.getYaw())); + } + + protected int changeFloor(Material materialA, int dataA) + { + return changeFloor(materialA, dataA, materialA, dataA); + } + + protected int changeFloor(Material materialA, int dataA, Material materialB, int dataB) + { + BlockRestore blockRestore = getTreasureLocation().getManager().getBlockRestore(); + AtomicInteger size = new AtomicInteger(); + AtomicBoolean tick = new AtomicBoolean(); + Location center = getTreasureLocation().getChest().clone().subtract(0, 1, 0); + + UtilServer.runSyncTimer(new BukkitRunnable() + { + @Override + public void run() + { + int aSize = size.get(); + + if (aSize > 3) + { + cancel(); + return; + } + + int id = tick.get() ? materialA.getId() : materialB.getId(); + byte data = (byte) (tick.get() ? dataA : dataB); + + for (Block block : UtilBlock.getInBoundingBox(center.clone().add(aSize, 0, aSize), center.clone().subtract(aSize, 0, aSize))) + { + if (blockRestore.contains(block)) + { + continue; + } + + _blocksToRestore.add(block); + blockRestore.add(block, id, data, Long.MAX_VALUE); + } + + size.getAndIncrement(); + tick.set(!tick.get()); + + } + }, 0, 10); + + return getTicks() + 40; + } + + @Override + public void cleanup() + { + super.cleanup(); + + BlockRestore blockRestore = getTreasureLocation().getManager().getBlockRestore(); + _blocksToRestore.forEach(blockRestore::restore); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java deleted file mode 100644 index 21bbad471..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java +++ /dev/null @@ -1,108 +0,0 @@ -package mineplex.core.treasure.animation; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Item; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -import mineplex.core.common.MaterialData; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilMath; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.treasure.BlockInfo; -import mineplex.core.treasure.Treasure; -import mineplex.core.treasure.TreasureType; - -public class TreasureRemoveAnimation extends Animation -{ - private Random _random = new Random(); - private List _otherChests; - private int _count = 0; - private List _flowers = new ArrayList<>(); - - public TreasureRemoveAnimation(Treasure treasure, List otherChests) - { - super(treasure); - _otherChests = otherChests; - } - - @Override - protected void tick() - { - if (getTicks() >= 20 && getTicks() % 10 == 0) - { - if (!_otherChests.isEmpty()) - { - BlockInfo info = _otherChests.remove(_random.nextInt(_otherChests.size())); - getTreasure().resetBlockInfo(info); - if (getTreasure().getTreasureType() == TreasureType.ST_PATRICKS) - { - // Drops gold nugget - dropItem(ItemStackFactory.Instance.CreateStack(Material.GOLD_NUGGET, (byte) 0, 1, "DroppedNugget" + _count), info); - _count++; - } - else if (getTreasure().getTreasureType() == TreasureType.SPRING) - { - // Drops random flower - if (_flowers.size() == 0) - generateFlowerList(); - - int r = UtilMath.random.nextInt(_flowers.size()); - MaterialData materialData = _flowers.get(r); - dropItem(ItemStackFactory.Instance.CreateStack(materialData.getMaterial(), materialData.getData(), 1, "Flower" + _count), info); - _count++; - info.getBlock().setType(Material.AIR); - info.getBlock().setData((byte) 0); - } - } - else - { - finish(); - } - } - } - - private void dropItem(ItemStack itemStack, BlockInfo blockInfo) - { - Location location = blockInfo.getBlock().getLocation(); - Item item = location.getWorld().dropItem(location.add(0, .5, 0), itemStack); - Vector vel = new Vector(Math.sin(_count * 9/5d), 0, Math.cos(_count * 9/5d)); - UtilAction.velocity(item, vel, Math.abs(Math.sin(_count * 12/3000d)), false, 0, 0.2 + - Math.abs(Math.cos(_count * 12/3000d))*0.6, 1, false); - getTreasure().getTreasureManager().addItem(item); - } - - private void generateFlowerList() - { - _flowers.add(MaterialData.of(Material.LONG_GRASS, (byte) 1)); - _flowers.add(MaterialData.of(Material.LONG_GRASS, (byte) 2)); - _flowers.add(MaterialData.of(Material.DEAD_BUSH, (byte) 0)); - _flowers.add(MaterialData.of(Material.YELLOW_FLOWER, (byte) 0)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 0)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 1)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 2)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 3)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 4)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 5)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 6)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 7)); - _flowers.add(MaterialData.of(Material.RED_ROSE, (byte) 8)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 0)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 1)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 2)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 3)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 4)); - _flowers.add(MaterialData.of(Material.DOUBLE_PLANT, (byte) 5)); - } - - @Override - protected void onFinish() - { - - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRewardAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRewardAnimation.java new file mode 100644 index 000000000..d29300975 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRewardAnimation.java @@ -0,0 +1,108 @@ +package mineplex.core.treasure.animation; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Item; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.Managers; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.HologramManager; +import mineplex.core.reward.RewardData; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.animations.reward.CommonRewardAnimation; +import mineplex.core.treasure.animation.animations.reward.LegendaryRewardAnimation; +import mineplex.core.treasure.animation.animations.reward.MythicalRewardAnimation; +import mineplex.core.treasure.animation.animations.reward.RareRewardAnimation; +import mineplex.core.treasure.animation.animations.reward.UncommonRewardAnimation; +import mineplex.core.treasure.types.Treasure; + +public abstract class TreasureRewardAnimation extends TreasureAnimation +{ + + private static final HologramManager HOLOGRAM_MANAGER = Managers.require(HologramManager.class); + private static final ItemStack FALL_BACK_ITEM = new ItemStack(Material.PRISMARINE_SHARD); + + public static TreasureRewardAnimation getAnimationFor(Treasure treasure, TreasureLocation treasureLocation, Location location, RewardData rewardData) + { + switch (rewardData.getRarity()) + { + case COMMON: + return new CommonRewardAnimation(treasure, treasureLocation, location, rewardData); + case UNCOMMON: + return new UncommonRewardAnimation(treasure, treasureLocation, location, rewardData); + case RARE: + return new RareRewardAnimation(treasure, treasureLocation, location, rewardData); + case LEGENDARY: + return new LegendaryRewardAnimation(treasure, treasureLocation, location, rewardData); + case MYTHICAL: + return new MythicalRewardAnimation(treasure, treasureLocation, location, rewardData); + } + + return null; + } + + private final Location _location; + private final RewardData _rewardData; + + private Hologram _hologram; + + public TreasureRewardAnimation(Treasure treasure, TreasureLocation treasureLocation, Location location, RewardData rewardData) + { + super(treasure, treasureLocation); + + _location = location; + _rewardData = rewardData; + } + + protected void createHologramItemPair() + { + UtilServer.runSyncLater(this::createHologramItemPair0, 5); + } + + private void createHologramItemPair0() + { + ArmorStand itemHolder = spawnArmourStand(_location.clone().subtract(0, 1.5, 0)); + Item item = spawnItem(_location, _rewardData.getDisplayItem() == null ? FALL_BACK_ITEM : _rewardData.getDisplayItem(), false); + itemHolder.setPassenger(item); + + List text = new ArrayList<>(); + + if (_rewardData.isRewardedShards()) + { + text.add(C.cAqua + "Duplicate"); + text.add("+" + F.currency(GlobalCurrency.TREASURE_SHARD, _rewardData.getShards())); + text.add(" "); + } + + text.add(_rewardData.getHeader()); + text.add(_rewardData.getFriendlyName()); + + _hologram = new Hologram(HOLOGRAM_MANAGER, _location.clone().add(0, 0.5, 0), true, text.toArray(new String[0])) + .start(); + } + + @Override + public void cleanup() + { + super.cleanup(); + + if (_hologram != null) + { + _hologram.stop(); + } + } + + public Location getLocation() + { + return _location; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/AncientChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/AncientChestAnimation.java new file mode 100644 index 000000000..904887aa7 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/AncientChestAnimation.java @@ -0,0 +1,81 @@ +package mineplex.core.treasure.animation.animations; + +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.ArmorStand; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.disguise.disguises.DisguiseBlaze; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureOpenAnimation; +import mineplex.core.treasure.types.Treasure; + +public class AncientChestAnimation extends TreasureOpenAnimation +{ + + public AncientChestAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + super(treasure, treasureLocation); + } + + @Override + protected void onStart() + { + changeFloor(Material.NETHER_BRICK, 0); + + for (Location location : getTreasureLocation().getChestLocations()) + { + location = location.clone().add(0, UtilMath.rRange(4, 6) + Math.random(), 0); + ArmorStand stand = spawnArmourStand(location); + disguise(new DisguiseBlaze(stand)); + } + } + + @Override + public void onTick() + { + double y = getTreasureLocation().getChest().getY() + 0.5; + + _stands.removeIf(stand -> + { + Location location = stand.getLocation(); + + if (Math.random() < 0.05) + { + stand.getWorld().playSound(location, Sound.ZOMBIE_REMEDY, 1, 0.6F); + } + + stand.teleport(location.subtract(0, 0.1, 0)); + + if (stand.isValid() && location.getY() < y) + { + stand.getWorld().playEffect(location, Effect.ENDER_SIGNAL, 0); + stand.getWorld().playSound(location, Sound.EXPLODE, 1, 0.4F); + UtilParticle.PlayParticleToAll(ParticleType.LAVA, location, 0.5F, 0.5F, 0.5F, 0.1F, 10, ViewDist.NORMAL); + UtilParticle.PlayParticleToAll(ParticleType.FLAME, location, 0.2F, 0.2F, 0.2F, 0.1F, 10, ViewDist.NORMAL); + stand.remove(); + createChestAt(location, Material.TRAPPED_CHEST); + return true; + } + + return false; + }); + + if (_stands.isEmpty()) + { + setRunning(false); + } + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/IlluminatedChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/IlluminatedChestAnimation.java new file mode 100644 index 000000000..ec98d322f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/IlluminatedChestAnimation.java @@ -0,0 +1,102 @@ +package mineplex.core.treasure.animation.animations; + +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.ArmorStand; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureOpenAnimation; +import mineplex.core.treasure.types.Treasure; + +public class IlluminatedChestAnimation extends TreasureOpenAnimation +{ + + private static final ItemStack HELMET = new ItemStack(Material.SEA_LANTERN); + private static final int RADIUS = 3; + private static final double OFFSET_THETA = Math.PI / 10; + private static final double DELTA_RADIUS = 0.1; + private static final float DELTA_YAW = 6F; + + private float _yaw; + private double _radius; + private double _deltaTheta; + + public IlluminatedChestAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + super(treasure, treasureLocation); + } + + @Override + protected void onStart() + { + changeFloor(Material.PRISMARINE, 0, Material.PRISMARINE, 1); + + List chests = getTreasureLocation().getChestLocations(); + _deltaTheta = Math.PI * 2 / (double) chests.size(); + + for (Location location : chests) + { + ArmorStand stand = spawnArmourStand(location.clone()); + stand.setHelmet(HELMET); + } + } + + @Override + public void onTick() + { + int index = 0; + for (ArmorStand stand : _stands) + { + Location location = getTreasureLocation().getChest().clone().subtract(0, 1, 0); + double x = _radius * Math.cos(OFFSET_THETA + index * _deltaTheta); + double z = _radius * Math.sin(OFFSET_THETA + index * _deltaTheta); + + location.add(x, 0, z); + location.setYaw(_yaw ); + + stand.teleport(location); + location.add(0, 1, 0); + UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, location, 0.25F, 0.25F, 0.25F, 0.1F, 1, ViewDist.NORMAL); + UtilParticle.PlayParticleToAll(ParticleType.PORTAL, location, 0.25F, 0.25F, 0.25F, 0.1F, 3, ViewDist.NORMAL); + + index++; + } + + if (getTicks() % 2 == 0) + { + getTreasureLocation().getChest().getWorld().playSound(getTreasureLocation().getChest(), Sound.NOTE_PLING, 1, (float) (_radius / 3 + 0.3F)); + } + + _yaw += DELTA_YAW; + _radius += DELTA_RADIUS; + if (_radius >= RADIUS) + { + for (ArmorStand stand : _stands) + { + Location location = stand.getLocation().add(0, 1, 0); + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, getTreasureLocation().getChest()))); + location.getWorld().playSound(location, Sound.EXPLODE, 1, 1); + UtilParticle.PlayParticleToAll(ParticleType.PORTAL, location, 0.5F, 0.5F, 0.5F, 0.5F, 10, ViewDist.NORMAL); + stand.remove(); + + createChestAt(location, Material.ENDER_CHEST); + } + + setRunning(false); + } + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/MOBAChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/MOBAChestAnimation.java new file mode 100644 index 000000000..7ec4beb22 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/MOBAChestAnimation.java @@ -0,0 +1,94 @@ +package mineplex.core.treasure.animation.animations; + +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.ArmorStand; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.disguise.disguises.DisguiseGuardian; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureOpenAnimation; +import mineplex.core.treasure.types.Treasure; + +public class MOBAChestAnimation extends TreasureOpenAnimation +{ + + private static final int RADIUS = 3; + private static final double OFFSET_THETA = Math.PI / 10; + private static final double DELTA_THETA = Math.PI / 40; + private static final double TOTAL_THETA = 2 * Math.PI; + + private double _deltaTheta; + private double _totalTheta; + + public MOBAChestAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + super(treasure, treasureLocation); + } + + @Override + protected void onStart() + { + changeFloor(Material.PRISMARINE, 0, Material.PRISMARINE, 1); + + List chests = getTreasureLocation().getChestLocations(); + _deltaTheta = Math.PI * 2 / (double) chests.size(); + + for (Location location : chests) + { + ArmorStand stand = spawnArmourStand(location); + disguise(new DisguiseGuardian(stand)); + } + } + + @Override + public void onTick() + { + _totalTheta += DELTA_THETA; + + int index = 0; + for (ArmorStand stand : _stands) + { + Location location = getTreasureLocation().getChest().clone(); + double x = RADIUS * Math.cos(_totalTheta + OFFSET_THETA + index * _deltaTheta); + double z = RADIUS * Math.sin(_totalTheta + OFFSET_THETA + index * _deltaTheta); + + location.add(x, 0, z); + + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, getTreasureLocation().getChest()))); + + stand.teleport(location); + UtilParticle.PlayParticleToAll(ParticleType.DRIP_WATER, location.add(0, 1, 0), 0.25F, 0.25F, 0.25F, 0.1F, 1, ViewDist.NORMAL); + + index++; + } + + if (_totalTheta >= TOTAL_THETA) + { + for (ArmorStand stand : _stands) + { + Location location = stand.getLocation(); + stand.getWorld().playSound(location, Sound.NOTE_PLING, 1, 1.2F); + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, location, 0, 0, 0, 0.1F, 1, ViewDist.NORMAL); + UtilParticle.PlayParticleToAll(ParticleType.PORTAL, location, 0.8F, 0.8F, 0.8F, 0.1F, 20, ViewDist.NORMAL); + stand.remove(); + + createChestAt(location, Material.ENDER_CHEST); + } + + setRunning(false); + } + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/MinestrikeChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/MinestrikeChestAnimation.java new file mode 100644 index 000000000..18dc008c3 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/MinestrikeChestAnimation.java @@ -0,0 +1,61 @@ +package mineplex.core.treasure.animation.animations; + +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureOpenAnimation; +import mineplex.core.treasure.types.Treasure; + +public class MinestrikeChestAnimation extends TreasureOpenAnimation +{ + + public MinestrikeChestAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + super(treasure, treasureLocation); + } + + @Override + protected void onStart() + { + changeFloor(Material.SAND, 0, Material.SANDSTONE, 0); + } + + @Override + public void onTick() + { + if (getTicks() % 3 == 0) + { + for (Location location : getTreasureLocation().getChestLocations()) + { + UtilParticle.PlayParticleToAll(ParticleType.BLOCK_DUST.getParticle(Material.OBSIDIAN, 0), location.clone().add(0, 0.4, 0), 0.25F, 0.25F, 0.25F, 0, 3, ViewDist.NORMAL); + } + } + + if (getTicks() > 50) + { + setRunning(false); + } + } + + @Override + protected void onFinish() + { + for (Location location : getTreasureLocation().getChestLocations()) + { + location = location.clone(); + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, getTreasureLocation().getChest()))); + location.getWorld().playEffect(location, Effect.STEP_SOUND, Material.CHEST); + createChestAt(location, Material.CHEST); + + location.add(0, 1, 0); + + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, location, 0, 0, 0, 0.1F, 1, ViewDist.NORMAL); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/MythicalChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/MythicalChestAnimation.java new file mode 100644 index 000000000..32e5fb8ef --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/MythicalChestAnimation.java @@ -0,0 +1,95 @@ +package mineplex.core.treasure.animation.animations; + +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.ArmorStand; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureOpenAnimation; +import mineplex.core.treasure.types.Treasure; + +public class MythicalChestAnimation extends TreasureOpenAnimation +{ + + private static final ItemStack HELMET = new ItemStack(Material.ENDER_CHEST); + private static final int RADIUS = 3; + private static final double OFFSET_THETA = Math.PI / 10; + private static final double DELTA_THETA = Math.PI / 40; + private static final double TOTAL_THETA = 2 * Math.PI; + + private double _deltaTheta; + private double _totalTheta; + + public MythicalChestAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + super(treasure, treasureLocation); + } + + @Override + protected void onStart() + { + changeFloor(Material.QUARTZ_BLOCK, 0, Material.QUARTZ_BLOCK, 1); + + List chests = getTreasureLocation().getChestLocations(); + _deltaTheta = Math.PI * 2 / (double) chests.size(); + + for (Location location : chests) + { + ArmorStand stand = spawnArmourStand(location); + stand.setHelmet(HELMET); + } + } + + @Override + public void onTick() + { + _totalTheta += DELTA_THETA; + + int index = 0; + for (ArmorStand stand : _stands) + { + Location location = getTreasureLocation().getChest().clone(); + double x = RADIUS * Math.cos(_totalTheta + OFFSET_THETA + index * _deltaTheta); + double z = RADIUS * Math.sin(_totalTheta + OFFSET_THETA + index * _deltaTheta); + + location.add(x, 0, z); + + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, getTreasureLocation().getChest()))); + + stand.teleport(location); + UtilParticle.PlayParticleToAll(ParticleType.HAPPY_VILLAGER, location.add(0, 1, 0), 0.25F, 0.25F, 0.25F, 0.1F, 1, ViewDist.NORMAL); + + index++; + } + + if (_totalTheta >= TOTAL_THETA) + { + for (ArmorStand stand : _stands) + { + Location location = stand.getLocation(); + stand.getWorld().playSound(location, Sound.ANVIL_LAND, 1, 0.8F); + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, location, 0, 0, 0, 0.1F, 1, ViewDist.NORMAL); + UtilParticle.PlayParticleToAll(ParticleType.HAPPY_VILLAGER, location, 0.8F, 0.8F, 0.8F, 0.1F, 20, ViewDist.NORMAL); + stand.remove(); + + createChestAt(location, Material.ENDER_CHEST); + } + + setRunning(false); + } + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/OldChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/OldChestAnimation.java new file mode 100644 index 000000000..7d8d2abbe --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/OldChestAnimation.java @@ -0,0 +1,102 @@ +package mineplex.core.treasure.animation.animations; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.ArmorStand; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureOpenAnimation; +import mineplex.core.treasure.types.Treasure; + +public class OldChestAnimation extends TreasureOpenAnimation +{ + + private static final ItemStack HELMET = new ItemBuilder(Material.SKULL_ITEM, (byte) 3) + .setPlayerHead("MHF_Chest") + .build(); + private static final double SHAKE_MAGNITUDE = Math.PI / 30D; + + private int _index; + + public OldChestAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + super(treasure, treasureLocation); + } + + @Override + protected void onStart() + { + for (Location location : getTreasureLocation().getChestLocations()) + { + ArmorStand stand = spawnArmourStand(location.clone().subtract(0, 2.5, 0)); + + stand.setHelmet(HELMET); + } + } + + @Override + public void onTick() + { + if (getTicks() % 10 == 0 && _index != _stands.size()) + { + _index++; + } + + int chestY = getTreasureLocation().getChest().getBlockY(); + boolean moved = false; + + for (int i = 0; i < _index; i++) + { + ArmorStand stand = _stands.get(i); + Location location = stand.getLocation(); + + if (location.getY() > chestY - 1) + { + continue; + } + else if (Math.random() < 0.1) + { + stand.getWorld().playSound(location, Sound.HORSE_ARMOR, 1, 0.7F); + } + + moved = true; + location.add(0, 0.1, 0); + stand.teleport(location); + UtilParticle.PlayParticleToAll(ParticleType.BLOCK_DUST.getParticle(Material.STONE, 0), stand.getLocation().add(0, 1.5, 0), 0.25F, 0.25F, 0.25F, 0, 3, ViewDist.NORMAL); + + if (location.getY() > chestY - 1) + { + resetArmourStand(stand); + } + else + { + shakeArmourStand(stand, SHAKE_MAGNITUDE); + } + } + + if (!moved) + { + for (ArmorStand stand : _stands) + { + Location location = stand.getLocation().add(0, 1, 0); + UtilParticle.PlayParticleToAll(ParticleType.CLOUD, location, 0.5F, 0.5F, 0.5F, 0, 20, ViewDist.NORMAL); + createChestAt(location, Material.CHEST); + stand.remove(); + } + + setRunning(false); + } + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/OmegaChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/OmegaChestAnimation.java new file mode 100644 index 000000000..7d35237fe --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/OmegaChestAnimation.java @@ -0,0 +1,102 @@ +package mineplex.core.treasure.animation.animations; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.ArmorStand; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.skin.SkinData; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureOpenAnimation; +import mineplex.core.treasure.types.Treasure; + +public class OmegaChestAnimation extends TreasureOpenAnimation +{ + + private static final ItemStack HELMET = SkinData.OMEGA_CHEST.getSkull(); + private static final double SHAKE_MAGNITUDE = Math.PI / 35D; + + private int _index; + + public OmegaChestAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + super(treasure, treasureLocation); + } + + @Override + protected void onStart() + { + changeFloor(Material.WOOL, 15, Material.WOOL, 7); + + for (Location location : getTreasureLocation().getChestLocations()) + { + ArmorStand stand = spawnArmourStand(location.clone().subtract(0, 2.5, 0)); + + stand.setHelmet(HELMET); + } + } + + @Override + public void onTick() + { + if (getTicks() % 10 == 0 && _index != _stands.size()) + { + _index++; + } + + int chestY = getTreasureLocation().getChest().getBlockY(); + boolean moved = false; + + for (int i = 0; i < _index; i++) + { + ArmorStand stand = _stands.get(i); + Location location = stand.getLocation(); + + if (location.getY() > chestY - 1) + { + continue; + } + else if (Math.random() < 0.1) + { + stand.getWorld().playSound(location, Sound.ZOMBIE_UNFECT, 1, 0.7F); + } + + moved = true; + location.add(0, 0.05, 0); + stand.teleport(location); + UtilParticle.PlayParticleToAll(ParticleType.BLOCK_DUST.getParticle(Material.OBSIDIAN, 0), stand.getLocation().add(0, 1.5, 0), 0.25F, 0.25F, 0.25F, 0, 3, ViewDist.NORMAL); + + if (location.getY() > chestY - 1) + { + resetArmourStand(stand); + } + else + { + shakeArmourStand(stand, SHAKE_MAGNITUDE); + } + } + + if (!moved) + { + for (ArmorStand stand : _stands) + { + Location location = stand.getLocation().add(0, 1, 0); + UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, location, 0.5F, 0.5F, 0.5F, 0.5F, 20, ViewDist.NORMAL); + createChestAt(location, Material.ENDER_CHEST); + stand.remove(); + } + + setRunning(false); + } + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/TrickOrTreatChestAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/TrickOrTreatChestAnimation.java new file mode 100644 index 000000000..1135daeac --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/TrickOrTreatChestAnimation.java @@ -0,0 +1,90 @@ +package mineplex.core.treasure.animation.animations; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Bat; + +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureOpenAnimation; +import mineplex.core.treasure.types.Treasure; +import mineplex.core.treasure.util.TreasureUtil; + +public class TrickOrTreatChestAnimation extends TreasureOpenAnimation +{ + + private boolean _tick; + + public TrickOrTreatChestAnimation(Treasure treasure, TreasureLocation treasureLocation) + { + super(treasure, treasureLocation); + } + + @Override + protected void onStart() + { + changeFloor(Material.WOOL, 15, Material.WOOL, 1); + } + + @Override + public void onTick() + { + if (getTicks() % 10 == 0) + { + for (Location location : getTreasureLocation().getChestLocations()) + { + if (Math.random() > 0.7) + { + location.getWorld().playSound(location, Sound.ORB_PICKUP, 1, 0.5F); + } + + MapUtil.QuickChangeBlockAt( + location, + _tick ? Material.PUMPKIN : Material.JACK_O_LANTERN, + TreasureUtil.getPumpkinFacing(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, getTreasureLocation().getChest()))) + ); + } + + _tick = !_tick; + } + + if (getTicks() % 3 == 0) + { + for (Location location : getTreasureLocation().getChestLocations()) + { + UtilParticle.PlayParticleToAll(ParticleType.FLAME, location.clone().add(0, 1, 0), 0.2F, 0.2F, 0.2F, 0.05F, 2, ViewDist.NORMAL); + } + } + + if (getTicks() > 50) + { + setRunning(false); + } + } + + @Override + protected void onFinish() + { + for (Location location : getTreasureLocation().getChestLocations()) + { + location = location.clone(); + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, getTreasureLocation().getChest()))); + createChestAt(location, Material.ENDER_CHEST); + + location.add(0, 1, 0); + + for (int i = 0; i < 3; i++) + { + Bat bat = spawnEntity(location, Bat.class, true); + bat.setAwake(true); + } + + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, location, 0, 0, 0, 0.1F, 1, ViewDist.NORMAL); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/CommonRewardAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/CommonRewardAnimation.java new file mode 100644 index 000000000..3b2481809 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/CommonRewardAnimation.java @@ -0,0 +1,36 @@ +package mineplex.core.treasure.animation.animations.reward; + +import org.bukkit.Location; + +import mineplex.core.reward.RewardData; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureRewardAnimation; +import mineplex.core.treasure.types.Treasure; + +public class CommonRewardAnimation extends TreasureRewardAnimation +{ + + public CommonRewardAnimation(Treasure treasure, TreasureLocation treasureLocation, Location location, RewardData rewardData) + { + super(treasure, treasureLocation, location, rewardData); + } + + @Override + protected void onStart() + { + createHologramItemPair(); + setRunning(false); + } + + @Override + public void onTick() + { + + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/LegendaryRewardAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/LegendaryRewardAnimation.java new file mode 100644 index 000000000..f1ed6c89d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/LegendaryRewardAnimation.java @@ -0,0 +1,68 @@ +package mineplex.core.treasure.animation.animations.reward; + +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.FireworkEffect.Type; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Item; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilFirework; +import mineplex.core.reward.RewardData; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureRewardAnimation; +import mineplex.core.treasure.types.Treasure; + +public class LegendaryRewardAnimation extends TreasureRewardAnimation +{ + + private static final FireworkEffect FIREWORK_EFFECT = FireworkEffect.builder() + .with(Type.BALL_LARGE) + .withColor(Color.LIME) + .withFade(Color.GREEN) + .withFlicker() + .build(); + private static final ItemStack ITEM_STACK = new ItemStack(Material.EMERALD); + + public LegendaryRewardAnimation(Treasure treasure, TreasureLocation treasureLocation, Location location, RewardData rewardData) + { + super(treasure, treasureLocation, location, rewardData); + } + + @Override + protected void onStart() + { + createHologramItemPair(); + getLocation().getWorld().playSound(getLocation(), Sound.ENDERDRAGON_DEATH, 1, 1); + getLocation().getWorld().strikeLightningEffect(getLocation()); + } + + @Override + public void onTick() + { + if (getTicks() % 8 == 0) + { + UtilFirework.playFirework(getLocation(), FIREWORK_EFFECT); + + for (int i = 0; i < 3; i++) + { + Item item = spawnItem(getLocation(), ITEM_STACK, true); + item.setVelocity(new Vector(Math.random() - 0.5, Math.random(), Math.random() - 0.5)); + } + } + + if (getTicks() > 80) + { + setRunning(false); + } + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/MythicalRewardAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/MythicalRewardAnimation.java new file mode 100644 index 000000000..162cb351b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/MythicalRewardAnimation.java @@ -0,0 +1,77 @@ +package mineplex.core.treasure.animation.animations.reward; + +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.FireworkEffect.Type; +import org.bukkit.Location; +import org.bukkit.Sound; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilFirework; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.reward.RewardData; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureRewardAnimation; +import mineplex.core.treasure.types.Treasure; + +public class MythicalRewardAnimation extends TreasureRewardAnimation +{ + + private static final FireworkEffect FIREWORK_EFFECT = FireworkEffect.builder() + .with(Type.STAR) + .withColor(Color.RED) + .withFade(Color.MAROON) + .withFlicker() + .build(); + + private long _currentTime; + + public MythicalRewardAnimation(Treasure treasure, TreasureLocation treasureLocation, Location location, RewardData rewardData) + { + super(treasure, treasureLocation, location, rewardData); + + _currentTime = location.getWorld().getTime(); + } + + @Override + protected void onStart() + { + createHologramItemPair(); + getLocation().getWorld().playSound(getLocation(), Sound.ENDERDRAGON_DEATH, 1, 0.5F); + UtilParticle.PlayParticleToAll(ParticleType.LAVA, getLocation(), 0.5F, 0.5F, 0.5F, 0.1F, 10, ViewDist.NORMAL); + } + + @Override + public void onTick() + { + if (getTicks() % 5 == 0) + { + getLocation().getWorld().setTime(getLocation().getWorld().getTime() + 12000); + } + + if (getTicks() % 2 == 0) + { + Location random = UtilAlg.getRandomLocation(getLocation(), 5, 0, 5); + + if (Math.random() < 0.3) + { + random.getWorld().strikeLightningEffect(random); + } + UtilFirework.launchFirework(random, FIREWORK_EFFECT, null, UtilMath.r(3) + 1); + } + + if (getTicks() > 80) + { + setRunning(false); + } + } + + @Override + protected void onFinish() + { + getLocation().getWorld().setTime(_currentTime); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/RareRewardAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/RareRewardAnimation.java new file mode 100644 index 000000000..30e2ebf90 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/RareRewardAnimation.java @@ -0,0 +1,66 @@ +package mineplex.core.treasure.animation.animations.reward; + +import org.bukkit.Location; +import org.bukkit.Sound; + +import mineplex.core.common.util.UtilFirework; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilServer; +import mineplex.core.reward.RewardData; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureRewardAnimation; +import mineplex.core.treasure.types.Treasure; + +public class RareRewardAnimation extends TreasureRewardAnimation +{ + + private double _radius = 3; + private double _height = -0.5; + + public RareRewardAnimation(Treasure treasure, TreasureLocation treasureLocation, Location location, RewardData rewardData) + { + super(treasure, treasureLocation, location, rewardData); + } + + @Override + protected void onStart() + { + createHologramItemPair(); + getLocation().getWorld().playSound(getLocation(), Sound.WITHER_SPAWN, 1, 0.5F); + UtilParticle.PlayParticleToAll(ParticleType.ENCHANTMENT_TABLE, getLocation(), 0.5F, 0.5F, 0.5F, 0.1F, 10, ViewDist.NORMAL); + } + + @Override + public void onTick() + { + UtilParticle.PlayParticleToAll(ParticleType.PORTAL, getLocation(), 0.5F, 0.5F, 0.5F, 0.1F, 4, ViewDist.NORMAL); + + if (getTicks() % 2 == 0) + { + for (double theta = 0; theta < 2 * Math.PI; theta += Math.PI / 20) + { + double x = _radius * Math.cos(theta); + double z = _radius * Math.sin(theta); + + UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, getLocation().clone().add(x, _height, z), 0, 0, 0, 0.001F, 1, ViewDist.NORMAL); + } + + _radius -= 0.1; + _height += 0.1; + + if (_radius <= 0) + { + UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, getLocation().clone().add(0, _height, 0), 0, 0, 0, 0.5F, 30, ViewDist.NORMAL); + setRunning(false); + } + } + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/UncommonRewardAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/UncommonRewardAnimation.java new file mode 100644 index 000000000..246acb6b7 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/animations/reward/UncommonRewardAnimation.java @@ -0,0 +1,52 @@ +package mineplex.core.treasure.animation.animations.reward; + +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.FireworkEffect.Type; +import org.bukkit.Location; + +import mineplex.core.common.util.UtilFirework; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.reward.RewardData; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureRewardAnimation; +import mineplex.core.treasure.types.Treasure; + +public class UncommonRewardAnimation extends TreasureRewardAnimation +{ + + private static final FireworkEffect FIREWORK_EFFECT = FireworkEffect.builder() + .with(Type.BURST) + .withColor(Color.AQUA) + .withFade(Color.WHITE) + .withFlicker() + .build(); + + public UncommonRewardAnimation(Treasure treasure, TreasureLocation treasureLocation, Location location, RewardData rewardData) + { + super(treasure, treasureLocation, location, rewardData); + } + + @Override + protected void onStart() + { + createHologramItemPair(); + UtilParticle.PlayParticleToAll(ParticleType.HEART, getLocation(), 0.25F, 0.25F, 0.25F, 0.1F, 4, ViewDist.NORMAL); + UtilFirework.playFirework(getLocation(), FIREWORK_EFFECT); + setRunning(false); + } + + @Override + public void onTick() + { + + } + + @Override + protected void onFinish() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/event/TreasureAnimationFinishEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/event/TreasureAnimationFinishEvent.java new file mode 100644 index 000000000..3fe83397a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/event/TreasureAnimationFinishEvent.java @@ -0,0 +1,42 @@ +package mineplex.core.treasure.animation.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; + +import mineplex.core.treasure.TreasureSession; +import mineplex.core.treasure.animation.TreasureAnimation; +import mineplex.core.treasure.event.TreasureEvent; + +/** + * Called when a player is able to begin opening chests. + */ +public class TreasureAnimationFinishEvent extends TreasureEvent +{ + + private static final HandlerList handlers = new HandlerList(); + + private final TreasureAnimation _animation; + + public TreasureAnimationFinishEvent(Player player, TreasureSession session, TreasureAnimation animation) + { + super(player, session); + + _animation = animation; + } + + public TreasureAnimation getAnimation() + { + return _animation; + } + + @Override + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureEvent.java new file mode 100644 index 000000000..944af398e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureEvent.java @@ -0,0 +1,30 @@ +package mineplex.core.treasure.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerEvent; + +import mineplex.core.treasure.TreasureSession; +import mineplex.core.treasure.types.TreasureType; + +public abstract class TreasureEvent extends PlayerEvent +{ + + private final TreasureSession _session; + + public TreasureEvent(Player who, TreasureSession session) + { + super(who); + + _session = session; + } + + public TreasureSession getSession() + { + return _session; + } + + public TreasureType getTreasureType() + { + return _session.getTreasure().getTreasureType(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureFinishEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureFinishEvent.java index 15a85c4dd..5a337c6c1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureFinishEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureFinishEvent.java @@ -1,37 +1,24 @@ package mineplex.core.treasure.event; import org.bukkit.entity.Player; -import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import mineplex.core.treasure.Treasure; +import mineplex.core.treasure.TreasureSession; /** - * Called once a player has finished with the treasure opening process. + * Called when a player is able to begin opening chests. */ -public class TreasureFinishEvent extends Event +public class TreasureFinishEvent extends TreasureEvent { + private static final HandlerList handlers = new HandlerList(); - private final Player _player; - private final Treasure _treasure; - - public TreasureFinishEvent(Player player, Treasure treasure) + public TreasureFinishEvent(Player player, TreasureSession session) { - _player = player; - _treasure = treasure; - } - - public Player getPlayer() - { - return _player; - } - - public Treasure getTreasure() - { - return _treasure; + super(player, session); } + @Override public HandlerList getHandlers() { return handlers; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasurePreStartEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasurePreStartEvent.java deleted file mode 100644 index 29355cfd1..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasurePreStartEvent.java +++ /dev/null @@ -1,57 +0,0 @@ -package mineplex.core.treasure.event; - -import mineplex.core.treasure.TreasureType; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -/** - * Called when a player selects a chest to open. - */ -public class TreasurePreStartEvent extends Event implements Cancellable -{ - private static final HandlerList handlers = new HandlerList(); - - private Player _player; - private TreasureType _treasureType; - private boolean _cancelled = false; - - public TreasurePreStartEvent(Player player, TreasureType treasureType) - { - _player = player; - _treasureType = treasureType; - } - - public Player getPlayer() - { - return _player; - } - - public TreasureType getTreasureType() - { - return _treasureType; - } - - @Override - public boolean isCancelled() - { - return _cancelled; - } - - @Override - public void setCancelled(boolean cancelled) - { - _cancelled = cancelled; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureStartEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureStartEvent.java index 37d59dc74..35f863cd0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureStartEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/event/TreasureStartEvent.java @@ -4,45 +4,30 @@ import java.util.Collections; import java.util.List; import org.bukkit.entity.Player; -import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import mineplex.core.treasure.TreasureSession; import mineplex.core.reward.Reward; -import mineplex.core.treasure.Treasure; /** * Called when a player is able to begin opening chests. */ -public class TreasureStartEvent extends Event +public class TreasureStartEvent extends TreasureEvent { + private static final HandlerList handlers = new HandlerList(); - private Player _player; - private Treasure _treasure; - private List _rewards; - - public TreasureStartEvent(Player player, Treasure treasure, List rewards) + public TreasureStartEvent(Player player, TreasureSession session) { - _player = player; - _treasure = treasure; - _rewards = rewards; - } - - public Player getPlayer() - { - return _player; - } - - public Treasure getTreasure() - { - return _treasure; + super(player, session); } public List getRewards() { - return Collections.unmodifiableList(_rewards); + return Collections.unmodifiableList(getSession().getRewards()); } + @Override public HandlerList getHandlers() { return handlers; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java deleted file mode 100644 index c10c4d15d..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java +++ /dev/null @@ -1,175 +0,0 @@ -package mineplex.core.treasure.gui; - -import java.io.File; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; - -import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.common.util.F; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.recharge.Recharge; -import mineplex.core.shop.confirmation.ConfirmationPage; -import mineplex.core.shop.item.IButton; -import mineplex.core.shop.item.SalesPackageBase; -import mineplex.core.shop.item.SalesPackageProcessor; -import mineplex.core.treasure.ChestPackage; -import mineplex.core.treasure.TreasureType; - -public class BuyChestButton implements IButton -{ - private InventoryManager _inventoryManager; - - private TreasurePage _page; - - private String _chestName; - private Material _chestMat; - private int _chestCost; - private TreasureType _chestType; - - public BuyChestButton(InventoryManager inventoryManager, TreasurePage page, - String chestName, Material chestMat, int chestCost, TreasureType chestType) - { - _inventoryManager = inventoryManager; - - _page = page; - - _chestName = chestName; - _chestMat = chestMat; - _chestCost = chestCost; - _chestType = chestType; - } - - @Override - public void onClick(final Player player, ClickType clickType) - { - if (!Recharge.Instance.use(player, "Buy Treasure Chest", 1000, false, false)) - { - return; - } - - if (_chestType == TreasureType.TRICK_OR_TREAT) - { - if (!new File("../../update/files/EnableTrickOrTreatChest.dat").exists()) - { - player.sendMessage(F.main("Treasure", "That chest is no longer available for purchase!")); - return; - } - if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - return; - } - } - if (_chestType == TreasureType.THANKFUL) - { - if (!new File("../../update/files/EnableThankfulChest.dat").exists()) - { - player.sendMessage(F.main("Treasure", "That chest is no longer available for purchase!")); - return; - } - if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - return; - } - } - if (_chestType == TreasureType.GINGERBREAD) - { - if (!new File("../../update/files/EnableGingerbreadChest.dat").exists()) - { - player.sendMessage(F.main("Treasure", "That chest is no longer available for purchase!")); - return; - } - if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - return; - } - } - if (_chestType == TreasureType.LOVE_CHEST) - { - if (!new File("../../update/files/EnableLoveChest.dat").exists()) - { - player.sendMessage(F.main("Treasure", "That chest is no longer available for purchase!")); - return; - } - if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - return; - } - } - if (_chestType == TreasureType.ST_PATRICKS) - { - if (!new File("../../update/files/EnableStPatricksChest.dat").exists()) - { - player.sendMessage(F.main("Treasure", "That chest is no longer available for purchase!")); - return; - } - if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - return; - } - } - if (_chestType == TreasureType.SPRING) - { - if (!new File("../../update/files/EnableSpringChest.dat").exists()) - { - player.sendMessage(F.main("Treasure", "That chest is no longer available for purchase!")); - return; - } - if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - return; - } - } - if (_chestType == TreasureType.HAUNTED) - { - if (!new File("../../update/files/EnableHauntedChest.dat").exists()) - { - player.sendMessage(F.main("Treasure", "That chest is no longer available for purchase!")); - return; - } - if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - return; - } - } - if (_chestType == TreasureType.FREEDOM) - { - if (!new File("../../update/files/EnableFreedomChest.dat").exists()) - { - player.sendMessage(F.main("Treasure", "That chest is no longer available for purchase!")); - return; - } - if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - return; - } - } - if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player) - && (_chestType == TreasureType.ILLUMINATED || _chestType == TreasureType.OMEGA - || _chestType == TreasureType.HAUNTED || _chestType == TreasureType.GINGERBREAD - || _chestType == TreasureType.ST_PATRICKS)) - { - player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); - return; - } - SalesPackageBase salesPackage = new ChestPackage(_chestName, _chestMat, _chestCost); - _page.getShop().openPageForPlayer(player, new ConfirmationPage<>(player, _page, new SalesPackageProcessor(player, GlobalCurrency.TREASURE_SHARD, salesPackage, _page.getDonationManager(), () -> - { - _inventoryManager.addItemToInventory(player, _chestName, 1); - player.closeInventory(); - TreasurePage page = new TreasurePage(_page.getTreasureManager(), _page.getTreasureShop(), _page.getTreasureLocation(), - _page.getClientManager(), _page.getDonationManager(), _page.getInventoryManager(), - _page.getGadgetManager(), player, _page.getActualPage()); - _page.getTreasureShop().openPageForPlayer(player, page); - }), salesPackage.buildIcon())); - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/OpenTreasureButton.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/OpenTreasureButton.java deleted file mode 100644 index e280643e5..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/OpenTreasureButton.java +++ /dev/null @@ -1,36 +0,0 @@ -package mineplex.core.treasure.gui; - -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; - -import mineplex.core.recharge.Recharge; -import mineplex.core.shop.item.IButton; -import mineplex.core.treasure.TreasureLocation; -import mineplex.core.treasure.TreasureType; - -public class OpenTreasureButton implements IButton -{ - - private Player _player; - private TreasureLocation _treasureLocation; - private TreasureType _treasureType; - - public OpenTreasureButton(Player player, TreasureLocation treasureLocation, TreasureType treasureType) - { - _player = player; - _treasureLocation = treasureLocation; - _treasureType = treasureType; - } - - @Override - public void onClick(Player player, ClickType clickType) - { - if (!Recharge.Instance.use(player, "Open Treasure Chest", 1000, false, false)) - { - return; - } - - _treasureLocation.attemptOpenTreasure(player, _treasureType); - player.closeInventory(); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java deleted file mode 100644 index f5cc4df8a..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java +++ /dev/null @@ -1,785 +0,0 @@ -package mineplex.core.treasure.gui; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import com.google.common.collect.Lists; - -import mineplex.core.account.CoreClientManager; -import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.common.skin.SkinData; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.LineFormat; -import mineplex.core.common.util.UtilText; -import mineplex.core.donation.DonationManager; -import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailFreedom; -import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailRedWhite; -import mineplex.core.gadget.gadgets.death.DeathFreedom; -import mineplex.core.gadget.gadgets.death.DeathMapleLeaf; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpFreedom; -import mineplex.core.gadget.gadgets.doublejump.DoubleJumpMaple; -import mineplex.core.gadget.gadgets.flag.FlagType; -import mineplex.core.gadget.gadgets.hat.HatType; -import mineplex.core.gadget.gadgets.morph.MorphUncleSam; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleAuraNiceness; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleCanadian; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedom; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedomFireworks; -import mineplex.core.gadget.gadgets.particle.freedom.ParticleStarSpangled; -import mineplex.core.gadget.types.Gadget; -import mineplex.core.gadget.types.GadgetType; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.shop.item.ShopItem; -import mineplex.core.shop.page.ShopPageBase; -import mineplex.core.treasure.TreasureLocation; -import mineplex.core.treasure.TreasureManager; -import mineplex.core.treasure.TreasureType; -import mineplex.core.treasure.gui.pages.NextPageButton; -import mineplex.core.treasure.gui.pages.PreviousPageButton; - -public class TreasurePage extends ShopPageBase -{ - - private TreasureManager _treasureManager; - private TreasureShop _treasureShop; - private TreasureLocation _treasureLocation; - private InventoryManager _inventoryManager; - private GadgetManager _gadgetManager; - private int _actualPage = 1; - - private List _specialTreasures = new ArrayList<>(); - private List _normalTreasures = new ArrayList<>(); - private List _seasonalTreasures = new ArrayList<>(); - - public TreasurePage(TreasureManager plugin, TreasureShop shop, TreasureLocation treasureLocation, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, GadgetManager gadgetManager, Player player) - { - super(plugin, shop, clientManager, donationManager, "Open Treasure - Page 1", player, 54); - - _treasureManager = plugin; - _treasureShop = shop; - _treasureLocation = treasureLocation; - _inventoryManager = inventoryManager; - _gadgetManager = gadgetManager; - - buildPage(); - } - - public TreasurePage(TreasureManager plugin, TreasureShop shop, TreasureLocation treasureLocation, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, GadgetManager gadgetManager, Player player, int actualPage) - { - super(plugin, shop, clientManager, donationManager, "Open Treasure - Page " + actualPage, player, 54); - - _treasureManager = plugin; - _treasureShop = shop; - _treasureLocation = treasureLocation; - _inventoryManager = inventoryManager; - _gadgetManager = gadgetManager; - _actualPage = actualPage; - - buildPage(); - } - - public TreasureManager getTreasureManager() - { - return _treasureManager; - } - - public TreasureShop getTreasureShop() - { - return _treasureShop; - } - - public TreasureLocation getTreasureLocation() - { - return _treasureLocation; - } - - public InventoryManager getInventoryManager() - { - return _inventoryManager; - } - - public GadgetManager getGadgetManager() - { - return _gadgetManager; - } - - public int getActualPage() - { - return _actualPage; - } - - @Override - public void buildPage() - { - addAllChests(); - - if (_actualPage == 1) - buildFirstPage(); - else - buildSecondPage(); - } - - private void addAllChests() - { - int treasureShards = getDonationManager().Get(getPlayer()).getBalance(GlobalCurrency.TREASURE_SHARD); - - int basicCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.OLD.getItemName()); - int heroicCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.ANCIENT.getItemName()); - int legendaryCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.MYTHICAL.getItemName()); - int christmasCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.CHRISTMAS.getItemName()); - int illuminatedCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.ILLUMINATED.getItemName()); - int freedomCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.FREEDOM.getItemName()); - int omegaCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.OMEGA.getItemName()); - int hauntedCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.HAUNTED.getItemName()); - int trickCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.TRICK_OR_TREAT.getItemName()); - int thankCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.THANKFUL.getItemName()); - int gingerbreadCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.GINGERBREAD.getItemName()); - int minestrikeCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.MINESTRIKE.getItemName()); - int loveCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.LOVE_CHEST.getItemName()); - int stpatricksCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.ST_PATRICKS.getItemName()); - int springCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.SPRING.getItemName()); - int mobaCount = _inventoryManager.Get(getPlayer()).getItemCount(TreasureType.MOBA.getItemName()); - - boolean availableChristmas = new File("../../update/files/EnableChristmasChest.dat").exists(); - boolean availableFreedom = new File("../../update/files/EnableFreedomChest.dat").exists(); - boolean availableHaunted = new File("../../update/files/EnableHauntedChest.dat").exists(); - boolean availableTrick = new File("../../update/files/EnableTrickOrTreatChest.dat").exists(); - boolean availableThank = new File("../../update/files/EnableThankfulChest.dat").exists(); - boolean availableGingerbread = new File("../../update/files/EnableGingerbreadChest.dat").exists(); - boolean availableLove = new File("../../update/files/EnableLoveChest.dat").exists(); - boolean availableStPatricks = new File("../../update/files/EnableStPatricksChest.dat").exists(); - boolean availableSpring = new File("../../update/files/EnableSpringChest.dat").exists(); - - List shardLore = new ArrayList<>(); - shardLore.add(" "); - shardLore.add(C.cGray + "These seem like they might come in"); - shardLore.add(C.cGray + "handy. Maybe I should collect more!"); - - List basicLore = new ArrayList<>(); - basicLore.add(" "); - basicLore.add(F.value("Old Chests Owned", "" + basicCount)); - basicLore.add(" "); - basicLore.add(C.cGray + "We've scoured the lands of Minecraft"); - basicLore.add(C.cGray + "and found these abandoned chests."); - basicLore.add(C.cGray + "The contents are unknown, but"); - basicLore.add(C.cGray + "according to the inscriptions on the"); - basicLore.add(C.cGray + "the straps they appear to contain"); - basicLore.add(C.cGray + "many kinds of loot."); - basicLore.add(" "); - if (basicCount > 0) - basicLore.add(C.cGreen + "Click to Open!"); - else - { - basicLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + "1000 Treasure Shards"); - basicLore.add(" "); - basicLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - - List heroicLore = new ArrayList<>(); - heroicLore.add(" "); - heroicLore.add(F.value("Ancient Chests Owned", "" + heroicCount)); - heroicLore.add(" "); - heroicLore.add(C.cGray + "Some of our bravest adventurers"); - heroicLore.add(C.cGray + "have discovered these chests within "); - heroicLore.add(C.cGray + "temples hidden in Minecrafts worlds."); - heroicLore.add(" "); - if (heroicCount > 0) - heroicLore.add(C.cGreen + "Click to Open!"); - else - { - heroicLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + "5000 Treasure Shards"); - heroicLore.add(" "); - heroicLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - - List legendaryLore = new ArrayList<>(); - legendaryLore.add(" "); - legendaryLore.add(F.value("Mythical Chests Owned", "" + legendaryCount)); - legendaryLore.add(" "); - legendaryLore.add(C.cGray + "All our previous adventurers have"); - legendaryLore.add(C.cGray + "perished in search of these chests."); - legendaryLore.add(C.cGray + "However, legends of their existence"); - legendaryLore.add(C.cGray + "convinced Sterling, Chiss and Defek7"); - legendaryLore.add(C.cGray + "to venture out and discover the"); - legendaryLore.add(C.cGray + "location of these chests on their own."); - legendaryLore.add(" "); - if (legendaryCount > 0) - legendaryLore.add(C.cGreen + "Click to Open!"); - else - { - legendaryLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + "10000 Treasure Shards"); - legendaryLore.add(" "); - legendaryLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - - List christmasLore = new ArrayList<>(); - christmasLore.add(" "); - christmasLore.add(F.value("Winter Holiday Chests Owned", "" + christmasCount)); - christmasLore.add(" "); - christmasLore.add(C.cGray + "Legend tells of the Winter Lord's"); - christmasLore.add(C.cGray + "vast treasure horde, locked away in"); - christmasLore.add(C.cGray + "in a vault of ice, deep beneath the"); - christmasLore.add(C.cGray + "Frozen Sea. It is said it can only be"); - christmasLore.add(C.cGray + "accessed in the deepest parts of Winter..."); - christmasLore.add(" "); - if (christmasCount > 0) - christmasLore.add(C.cGreen + "Click to Open!"); - else - { - christmasLore.add(C.cRed + "This item is no longer available!"); - } - - List illuminatedLore = new ArrayList(); - illuminatedLore.add(" "); - illuminatedLore.add(F.value("Illuminated Chests Owned", "" + illuminatedCount)); - illuminatedLore.add(" "); - illuminatedLore.add(C.cGray + "The illuminated chest shines brightly"); - illuminatedLore.add(C.cGray + "in the depths, always bringing a new"); - illuminatedLore.add(C.cGray + "treasure from the darkness."); - illuminatedLore.add(" "); - if (illuminatedCount > 0) - illuminatedLore.add(C.cGreen + "Click to Open!"); - else - { - illuminatedLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + "20000 Treasure Shards"); - illuminatedLore.add(" "); - illuminatedLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - - List freedomLore = new ArrayList<>(); - freedomLore.add(" "); - freedomLore.add(F.value("Freedom Chests Owned", "" + freedomCount)); - freedomLore.add(" "); - freedomLore.add(C.cGray + "It is said that George Washington"); - freedomLore.add(C.cGray + "carved this chest himself from the wood"); - freedomLore.add(C.cGray + "of the cherry tree he cut down..."); - freedomLore.add(" "); - - if (freedomCount > 0) - { - if (hasAllFreedomItems(getPlayer())) - { - freedomLore.add(C.cWhite + "You own all treasures from this chest."); - } - else - { - freedomLore.add(C.cGreen + "Click to Open!"); - } - } - else - { - if (!availableFreedom) - { - freedomLore.add(C.cRed + "This item is no longer available!"); - } - else if (hasAllFreedomItems(getPlayer())) - { - freedomLore.add(C.cWhite + "You own all treasures from this chest."); - } - else - { - freedomLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + "20000 Treasure Shards"); - freedomLore.add(" "); - freedomLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - } - - freedomLore.add(" "); - freedomLore.add(ChatColor.RESET + C.cGreen + getFreedomUnlockedAmount(getPlayer()) + "/18 Unlocked"); - - List omegaLore = new ArrayList<>(); - omegaLore.add(" "); - omegaLore.add(F.value("Omega Chests Owned", "" + omegaCount)); - omegaLore.add(" "); - omegaLore.add(C.cGray + "The most powerful of all chests,"); - omegaLore.add(C.cGray + "it is able to go back in time to find"); - omegaLore.add(C.cGray + "loot that has been lost..."); - omegaLore.add(" "); - if (omegaCount > 0) - omegaLore.add(C.cGreen + "Click to Open!"); - else - { - - } - - List hauntedLore = new ArrayList<>(); - hauntedLore.add(" "); - hauntedLore.add(F.value("Haunted Chests Owned", "" + hauntedCount)); - hauntedLore.add(" "); - hauntedLore.add(C.cGray + "The Haunted Chest can only be found"); - hauntedLore.add(C.cGray + "during the month of October when the"); - hauntedLore.add(C.cGray + "veil between this world and the shadow is thin..."); - hauntedLore.add(" "); - if (hauntedCount > 0 && !hasAllHauntedItems(getPlayer())) - { - hauntedLore.add(C.cGreen + "Click to Open!"); - } - else - { - hauntedLore.add(C.cRed + "This item is no longer available!"); - } - - List trickLore = Lists.newArrayList(); - trickLore.add(" "); - trickLore.add(F.value("Trick or Treat Chests Owned", "" + trickCount)); - trickLore.add(" "); - trickLore.add(C.cGray + "The Trick or Treat Chest contains all"); - trickLore.add(C.cGray + "sorts of surprises, from Rank Upgrades to"); - trickLore.add(C.cGray + "long lost Halloween items, and even other chests!"); - trickLore.add(" "); - if (trickCount > 0) - { - trickLore.add(C.cGreen + "Click to Open!"); - } - else - { - if (!availableTrick) - { - trickLore.add(C.cRed + "This item is no longer available!"); - } - else - { - trickLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + "20000 Treasure Shards"); - trickLore.add(" "); - trickLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - } - - List thankLore = Lists.newArrayList(); - thankLore.add(" "); - thankLore.add(F.value("Thankful Chests Owned", "" + thankCount)); - thankLore.add(" "); - thankLore.add(C.cGray + "The Thankful Chest is our way of"); - thankLore.add(C.cGray + "showing thanks to you, containing items from Rank Upgrades to"); - thankLore.add(C.cGray + "Power Play Club Subscriptions, among other things!"); - thankLore.add(" "); - if (thankCount > 0) - { - thankLore.add(C.cGreen + "Click to Open!"); - } - else - { - if (!availableThank) - { - thankLore.add(C.cRed + "This item is no longer available!"); - } - else - { - thankLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + "20000 Treasure Shards"); - thankLore.add(" "); - thankLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - } - - List gingerbreadLore = Lists.newArrayList(); - gingerbreadLore.add(" "); - gingerbreadLore.add(F.value("Gingerbread Chests Owned", "" + gingerbreadCount)); - gingerbreadLore.add(" "); - gingerbreadLore.addAll(UtilText.splitLine(C.cGray + "The legendary burglar, " + - "the Gingerbread Man, has finally been caught! Now, for the first time his loot is available for auction." + - " There are 8 pieces available for to collect and no duplicates can be obtained from this chest!", - LineFormat.LORE)); - gingerbreadLore.add(" "); - if (gingerbreadCount > 0) - { - gingerbreadLore.add(C.cGreen + "Click to Open!"); - } - else - { - gingerbreadLore.add(C.cRed + "This item is no longer available!"); - } - - List minestrikeLore = Lists.newArrayList(); - minestrikeLore.add(" "); - minestrikeLore.add(F.value("Minestrike Chests Owned", "" + minestrikeCount)); - minestrikeLore.add(" "); - minestrikeLore.addAll(UtilText.splitLines(new String[] - { - C.cGray + "The Minestrike Chest is the only place to get the unique skins for Minestrike weapons!", - "", - C.cWhite + "Each use opens two chests. Can give duplicates." - }, LineFormat.LORE)); - minestrikeLore.add(" "); - if (minestrikeCount > 0) - { - minestrikeLore.add(C.cGreen + "Click to Open!"); - } - else - { - minestrikeLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + "10000 Treasure Shards"); - minestrikeLore.add(" "); - minestrikeLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - - List lovechestLore = Lists.newArrayList(); - lovechestLore.add(" "); - lovechestLore.add(F.value("Love Chests Owned", "" + loveCount)); - lovechestLore.add(" "); - lovechestLore.addAll(UtilText.splitLines(new String[]{C.cGray + "Cupid and his hunters have searched far and wide to collect a whole bunch of lovey dovey items. 6 items, no duplicates."}, LineFormat.LORE)); - lovechestLore.add(" "); - if (loveCount > 0) - { - lovechestLore.add(C.cGreen + "Click to Open!"); - } - else - { - if (!availableLove) - { - lovechestLore.add(C.cRed + "This item is no longer available"); - } - else - { - lovechestLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + TreasureType.LOVE_CHEST.getPurchasePrice() + " Treasure Shards"); - lovechestLore.add(" "); - lovechestLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - } - - List stpatricksLore = Lists.newArrayList(); - stpatricksLore.add(" "); - stpatricksLore.add(F.value("St Patrick's Chests Owned", "" + stpatricksCount)); - stpatricksLore.add(" "); - stpatricksLore.addAll(UtilText.splitLines(new String[]{C.cGray + "Happy St. Patrick's Day! Get your Pot's of Gold and Luck of the Irish in this chest! 7 items, no duplicates."}, LineFormat.LORE)); - stpatricksLore.add(" "); - if (stpatricksCount > 0) - { - stpatricksLore.add(C.cGreen + "Click to Open!"); - } - else - { - if (!availableStPatricks) - { - stpatricksLore.add(C.cRed + "This item is no longer available"); - } - else - { - stpatricksLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + TreasureType.ST_PATRICKS.getPurchasePrice() + " Treasure Shards"); - stpatricksLore.add(" "); - stpatricksLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - } - - List springLore = Lists.newArrayList(); - springLore.add(" "); - springLore.add(F.value("Spring Chests Owned", "" + springCount)); - springLore.add(" "); - springLore.addAll(UtilText.splitLines(new String[]{C.cGray + "Spring is here! Find 6 limited edition Spring Cosmetics in the Spring Chest! Only available for a limited time. Guaranteed no Duplicate items!"}, LineFormat.LORE)); - springLore.add(" "); - if (springCount > 0) - { - springLore.add(C.cGreen + "Click to Open!"); - } - else - { - if (!availableSpring) - { - springLore.add(C.cRed + "This item is no longer available"); - } - else - { - springLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + TreasureType.SPRING.getPurchasePrice() + " Treasure Shards"); - springLore.add(" "); - springLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); - } - } - - List mobaLore = Lists.newArrayList(); - mobaLore.add(" "); - mobaLore.add(F.value("HOG Chests Owned", "" + mobaCount)); - mobaLore.add(" "); - mobaLore.addAll(UtilText.splitLines(new String[]{C.cGray + "Heroes of GWEN exclusive cosmetics! Each chest contains 4 exclusive items to the game!"}, LineFormat.LORE)); - mobaLore.add(" "); - if (mobaCount > 0) - { - mobaLore.add(C.cGreen + "Click to Open!"); - } - else - { - mobaLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + TreasureType.MOBA.getPurchasePrice() + " Treasure Shards"); - mobaLore.add(" "); - mobaLore.add(C.cAqua + "or Earn HOG Chests by leveling up Roles with in Heroes of GWEN."); - } - - ShopItem shards = new ShopItem(Material.PRISMARINE_SHARD, C.cAqua + C.Bold + treasureShards + " Treasure Shards", shardLore.toArray(new String[0]), 0, false); - - // Normal chests - ShopItem basic = new ShopItem(Material.CHEST, C.cGreen + C.Bold + "Old Treasure", basicLore.toArray(new String[0]), 0, false, false); - ShopItem heroic = new ShopItem(Material.TRAPPED_CHEST, C.cGold + C.Bold + "Ancient Treasure", heroicLore.toArray(new String[0]), 0, false, false); - ShopItem legendary = new ShopItem(Material.ENDER_CHEST, C.cRed + C.Bold + "Mythical Treasure", legendaryLore.toArray(new String[0]), 0, false, false); - ItemStack illuminated = new ShopItem(Material.SEA_LANTERN, C.cDAqua + C.Bold + "Illuminated Treasure", illuminatedLore.toArray(new String[0]), 0, false, false); - ItemStack omega = SkinData.OMEGA_CHEST.getSkull(C.cAquaB + "Omega Treasure", omegaLore); - ItemStack minestrike = new ShopItem(Material.TNT, C.cGoldB + "Minestrike Treasure", minestrikeLore.toArray(new String[0]), 0, false, false); - ItemStack moba = new ShopItem(Material.PRISMARINE, (byte) 2, C.cAquaB + "Heroes of GWEN Treasure", mobaLore.toArray(new String[0]), 0, false, false); - - // Seasonal chests - ItemStack christmas = SkinData.PRESENT.getSkull(C.cDGreen + C.Bold + "Winter Holiday Treasure", christmasLore); - ItemStack freedom = SkinData.FREEDOM_CHEST.getSkull(C.cRedB + "Freedom " + C.cBlueB + "Treasure", freedomLore); - ItemStack haunted = SkinData.HAUNTED_CHEST.getSkull(C.cGoldB + "Haunted Treasure", hauntedLore); - ItemStack trick = new ShopItem(Material.SKULL_ITEM, C.cGoldB + "Trick or Treat Treasure", trickLore.toArray(new String[0]), 0, false, false); - ItemStack thank = new ShopItem(Material.COOKED_CHICKEN, C.cGoldB + "Thankful Treasure", thankLore.toArray(new String[0]), 0, false, false); - ItemStack gingerbread = SkinData.GINGERBREAD.getSkull(C.cRedB + "Gingerbread" + C.cGreenB + " Treasure", gingerbreadLore); - ItemStack lovechest = new ShopItem(Material.WOOL, (byte) 6, C.cRedB + "Love Chest", lovechestLore.toArray(new String[0]), 0, false, false); - ItemStack stpatricks = SkinData.LEPRECHAUN.getSkull(C.cGreenB + "St Patrick's Treasure", stpatricksLore); - ItemStack spring = new ShopItem(Material.DOUBLE_PLANT, (byte) 4, C.cGreenB + "Spring Treasure", springLore.toArray(new String[0]), 1, false, false); - - // Adds shard item - addItem(49, shards); - - // Adds chests to lists, to handle them later - - // Normal chests - TreasurePageItem oldTreasureItem = new TreasurePageItem(basic, basicCount, TreasureType.OLD); - TreasurePageItem ancientTreasureItem = new TreasurePageItem(heroic, heroicCount, TreasureType.ANCIENT); - TreasurePageItem mythicalTreasureItem = new TreasurePageItem(legendary, legendaryCount, TreasureType.MYTHICAL); - TreasurePageItem illuminatedTreasureItem = new TreasurePageItem(illuminated, illuminatedCount, TreasureType.ILLUMINATED); - TreasurePageItem omegaTreasureItem = new TreasurePageItem(omega, omegaCount, TreasureType.OMEGA); - TreasurePageItem minestrikeTreasureItem = new TreasurePageItem(minestrike, minestrikeCount, TreasureType.MINESTRIKE); - TreasurePageItem mobaTreasureItem = new TreasurePageItem(moba, mobaCount, TreasureType.MOBA); - - // Seasonal chests - TreasurePageItem winterTreasureItem = new TreasurePageItem(christmas, christmasCount, TreasureType.CHRISTMAS); - TreasurePageItem freedomTreasureItem = new TreasurePageItem(freedom, freedomCount, TreasureType.FREEDOM); - TreasurePageItem hauntedTreasureItem = new TreasurePageItem(haunted, hauntedCount, TreasureType.HAUNTED); - TreasurePageItem trickTreasureItem = new TreasurePageItem(trick, trickCount, TreasureType.TRICK_OR_TREAT); - TreasurePageItem thankTreasureItem = new TreasurePageItem(thank, thankCount, TreasureType.THANKFUL); - TreasurePageItem gingerbreadTreasureItem = new TreasurePageItem(gingerbread, gingerbreadCount, TreasureType.GINGERBREAD); - TreasurePageItem loveChestItem = new TreasurePageItem(lovechest, loveCount, TreasureType.LOVE_CHEST); - TreasurePageItem stPatricksItem = new TreasurePageItem(stpatricks, stpatricksCount, TreasureType.ST_PATRICKS); - TreasurePageItem springItem = new TreasurePageItem(spring, springCount, TreasureType.SPRING); - - _normalTreasures.add(oldTreasureItem); - _normalTreasures.add(ancientTreasureItem); - _normalTreasures.add(mythicalTreasureItem); - _normalTreasures.add(illuminatedTreasureItem); - _normalTreasures.add(omegaTreasureItem); - _normalTreasures.add(minestrikeTreasureItem); - _normalTreasures.add(mobaTreasureItem); - - if (availableSpring) - _specialTreasures.add(springItem); - else - _seasonalTreasures.add(springItem); - - if (availableStPatricks) - _specialTreasures.add(stPatricksItem); - else - _seasonalTreasures.add(stPatricksItem); - - if (availableLove) - _specialTreasures.add(loveChestItem); - else - _seasonalTreasures.add(loveChestItem); - - if (availableChristmas) - _specialTreasures.add(winterTreasureItem); - else - _seasonalTreasures.add(winterTreasureItem); - - if (availableFreedom) - _specialTreasures.add(freedomTreasureItem); - else - _seasonalTreasures.add(freedomTreasureItem); - - if (availableHaunted) - _specialTreasures.add(hauntedTreasureItem); - else - _seasonalTreasures.add(hauntedTreasureItem); - - if (availableTrick) - _specialTreasures.add(trickTreasureItem); - else - _seasonalTreasures.add(trickTreasureItem); - - if (availableThank) - _specialTreasures.add(thankTreasureItem); - else - _seasonalTreasures.add(thankTreasureItem); - - if (availableGingerbread) - _specialTreasures.add(gingerbreadTreasureItem); - else - _seasonalTreasures.add(gingerbreadTreasureItem); - } - - private void buildFirstPage() - { - int i = 0; - if (_specialTreasures.size() >= 0) - { - int[] specialDisplayPositions = getSpecialDisplayOrder(); - for (TreasurePageItem treasurePageItem : _specialTreasures) - { - addChest(treasurePageItem, specialDisplayPositions[i]); - i++; - } - } - - i = 0; - int[] normalDisplayPositions = getNormalDisplayOrder(); - for (TreasurePageItem treasurePageItem : _normalTreasures) - { - addChest(treasurePageItem, normalDisplayPositions[i]); - i++; - } - - ItemStack nextPage = ItemStackFactory.Instance.CreateStack(Material.ARROW, (byte) 0, 1, C.cGreen + "Next Page"); - NextPageButton nextPageButton = new NextPageButton(this, _player); - addButton(53, nextPage, nextPageButton); - } - - private void buildSecondPage() - { - int i = 0; - int[] seasonalDisplayPositions = getSeasonalDisplayOrder(); - for (TreasurePageItem treasurePageItem : _seasonalTreasures) - { - addChest(treasurePageItem, seasonalDisplayPositions[i]); - i++; - } - - ItemStack previousPage = ItemStackFactory.Instance.CreateStack(Material.ARROW, (byte) 0, 1, C.cGreen + "Previous Page"); - PreviousPageButton previousPageButton = new PreviousPageButton(this, _player); - addButton(45, previousPage, previousPageButton); - } - - private void addChest(TreasurePageItem treasurePageItem, int position) - { - ItemStack item = treasurePageItem.getItem(); - int owned = treasurePageItem.getCount(); - TreasureType treasureType = treasurePageItem.getTreasureType(); - - if (owned > 0) - { - addButton(position, item, new OpenTreasureButton(getPlayer(), _treasureLocation, treasureType)); - } - else if (treasureType.isPurchasable()) { - addButton(position, item, new BuyChestButton(_inventoryManager, this, treasureType.getItemName(), Material.CHEST, treasureType.getPurchasePrice(), treasureType)); - } - else - { - setItem(position, item); - } - } - - private int[] getSpecialDisplayOrder() - { - int specialTreasuresSize = _specialTreasures.size(); - switch (specialTreasuresSize) - { - case 1: - return new int[]{4}; - case 2: - return new int[]{3, 5}; - case 3: - return new int[]{2, 4, 6}; - case 4: - return new int[]{1, 3, 5, 7}; - } - return new int[]{4}; - } - - private int[] getNormalDisplayOrder() - { - int normalTreasuresSize = _normalTreasures.size(); - switch (normalTreasuresSize) - { - case 5: - return new int[]{20, 22, 24, 39, 41}; - case 6: - return new int[]{19, 21, 23, 25, 38, 42}; - case 7: - return new int[]{19, 21, 23, 25, 38, 40, 42}; - case 8: - return new int[]{19, 21, 23, 25, 37, 39, 41, 43}; - case 9: - return new int[]{19, 21, 23, 25, 31, 37, 39, 41, 43}; - case 10: - return new int[]{19, 21, 23, 25, 29, 33, 37, 39, 41, 43}; - case 11: - return new int[]{19, 21, 23, 25, 29, 31, 33, 37, 39, 32, 43}; - } - return new int[]{20, 22, 24, 39, 41}; - } - - private int[] getSeasonalDisplayOrder() - { - int seasonalTreasuresSize = _seasonalTreasures.size(); - switch (seasonalTreasuresSize) - { - case 5: - return new int[]{11, 13, 15, 30, 32}; - case 6: - return new int[]{10, 12, 14, 16, 29, 33}; - case 7: - return new int[]{10, 12, 14, 16, 29, 31, 33}; - case 8: - return new int[]{10, 12, 14, 16, 28, 30, 32, 34}; - case 9: - return new int[]{10, 12, 14, 16, 22, 28, 30, 32, 34}; - case 10: - return new int[]{10, 12, 14, 16, 20, 24, 28, 30, 32, 34}; - case 11: - return new int[]{10, 12, 14, 16, 20, 22, 24, 28, 30, 32, 34}; - } - return new int[]{11, 13, 15, 30, 32}; - } - - public boolean hasAllFreedomItems(Player player) - { - return !getPlugin().hasItemsToGivePlayer(TreasureType.FREEDOM.getRewardPool(), player); - } - - /** - * Checks if the player has all the items for the halloween chest - * @param player - * @return - */ - public boolean hasAllHauntedItems(Player player) - { - return !getPlugin().hasItemsToGivePlayer(TreasureType.HAUNTED.getRewardPool(), player); - } - - public int getFreedomUnlockedAmount(Player player) - { - if (hasAllFreedomItems(player)) - return 18; - int amount = 0; - Gadget[] gadgets = new Gadget[] - { - _gadgetManager.getGadget("Uncle Sam Hat", GadgetType.HAT), - _gadgetManager.getGadget(ParticleFreedom.class), - _gadgetManager.getGadget(ArrowTrailFreedom.class), - _gadgetManager.getGadget(DoubleJumpFreedom.class), - _gadgetManager.getGadget(DeathFreedom.class), - _gadgetManager.getGadget(MorphUncleSam.class), - _gadgetManager.getGadget(ArrowTrailRedWhite.class), - _gadgetManager.getGadget(DeathMapleLeaf.class), - _gadgetManager.getGadget(DoubleJumpMaple.class), - _gadgetManager.getGadget(ParticleAuraNiceness.class), - _gadgetManager.getGadget(ParticleCanadian.class), - _gadgetManager.getGadget(ParticleFreedomFireworks.class), - _gadgetManager.getGadget(ParticleStarSpangled.class), - _gadgetManager.getHatGadget(HatType.AMERICA), - _gadgetManager.getHatGadget(HatType.CANADA), - _gadgetManager.getFlagGadget(FlagType.CANADA), - _gadgetManager.getFlagGadget(FlagType.USA), - }; - - for (Gadget gadget : gadgets) - { - if (gadget.ownsGadget(player)) - amount++; - } - return amount; - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePageItem.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePageItem.java deleted file mode 100644 index 6a68fce5c..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePageItem.java +++ /dev/null @@ -1,35 +0,0 @@ -package mineplex.core.treasure.gui; - -import org.bukkit.inventory.ItemStack; - -import mineplex.core.treasure.TreasureType; - -public class TreasurePageItem -{ - - private final ItemStack _item; - private final int _count; - private final TreasureType _treasureType; - - public TreasurePageItem(ItemStack item, int count, TreasureType treasureType) - { - _item = item; - _count = count; - _treasureType = treasureType; - } - - public ItemStack getItem() - { - return _item; - } - - public int getCount() - { - return _count; - } - - public TreasureType getTreasureType() - { - return _treasureType; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasureShop.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasureShop.java deleted file mode 100644 index 3a421de6d..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasureShop.java +++ /dev/null @@ -1,33 +0,0 @@ -package mineplex.core.treasure.gui; - -import mineplex.core.gadget.GadgetManager; -import org.bukkit.entity.Player; - -import mineplex.core.account.CoreClientManager; -import mineplex.core.donation.DonationManager; -import mineplex.core.inventory.InventoryManager; -import mineplex.core.shop.ShopBase; -import mineplex.core.shop.page.ShopPageBase; -import mineplex.core.treasure.TreasureLocation; -import mineplex.core.treasure.TreasureManager; - -public class TreasureShop extends ShopBase -{ - private TreasureLocation _treasureLocation; - private InventoryManager _inventoryManager; - private GadgetManager _gadgetManager; - - public TreasureShop(TreasureManager plugin, InventoryManager inventoryManager, CoreClientManager clientManager, DonationManager donationManager, GadgetManager gadgetManager, TreasureLocation treasureLocation) - { - super(plugin, clientManager, donationManager, "Treasure Shop"); - _treasureLocation = treasureLocation; - _inventoryManager = inventoryManager; - _gadgetManager = gadgetManager; - } - - @Override - protected ShopPageBase> buildPagesFor(Player player) - { - return new TreasurePage(getPlugin(), this, _treasureLocation, getClientManager(), getDonationManager(), _inventoryManager, _gadgetManager, player); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/NextPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/NextPageButton.java deleted file mode 100644 index a26b6446c..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/NextPageButton.java +++ /dev/null @@ -1,32 +0,0 @@ -package mineplex.core.treasure.gui.pages; - -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; - -import mineplex.core.shop.item.IButton; -import mineplex.core.treasure.gui.TreasurePage; - -public class NextPageButton implements IButton -{ - - private TreasurePage _treasurePage; - private Player _player; - - public NextPageButton(TreasurePage treasurePage, Player player) - { - _treasurePage = treasurePage; - _player = player; - } - - @Override - public void onClick(Player player, ClickType clickType) - { - if (_player != player) - return; - player.closeInventory(); - TreasurePage nextPage = new TreasurePage(_treasurePage.getTreasureManager(), _treasurePage.getTreasureShop(), _treasurePage.getTreasureLocation(), - _treasurePage.getClientManager(), _treasurePage.getDonationManager(), _treasurePage.getInventoryManager(), - _treasurePage.getGadgetManager(), _player, _treasurePage.getActualPage() + 1); - _treasurePage.getTreasureShop().openPageForPlayer(player, nextPage); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/PreviousPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/PreviousPageButton.java deleted file mode 100644 index f6684b427..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/PreviousPageButton.java +++ /dev/null @@ -1,33 +0,0 @@ -package mineplex.core.treasure.gui.pages; - -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; - -import mineplex.core.shop.item.IButton; -import mineplex.core.treasure.gui.TreasurePage; - -public class PreviousPageButton implements IButton -{ - - private TreasurePage _treasurePage; - private Player _player; - - public PreviousPageButton(TreasurePage treasurePage, Player player) - { - _treasurePage = treasurePage; - _player = player; - } - - @Override - public void onClick(Player player, ClickType clickType) - { - if (_player != player) - return; - player.closeInventory(); - TreasurePage previousPage = new TreasurePage(_treasurePage.getTreasureManager(), _treasurePage.getTreasureShop(), _treasurePage.getTreasureLocation(), - _treasurePage.getClientManager(), _treasurePage.getDonationManager(), _treasurePage.getInventoryManager(), - _treasurePage.getGadgetManager(), _player, _treasurePage.getActualPage() - 1); - _treasurePage.getTreasureShop().openPageForPlayer(player, previousPage); - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardRarity.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardRarity.java new file mode 100644 index 000000000..95cae8ccd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardRarity.java @@ -0,0 +1,52 @@ +package mineplex.core.treasure.reward; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; + +public enum RewardRarity +{ + + COMMON("Common", C.cWhite, C.cGray, 7), + UNCOMMON("Uncommon", C.cAqua, C.cDAqua, 3), + RARE("Rare", C.cPurple, C.cDPurple, 10), + LEGENDARY("Legendary", C.cGreen, C.cDGreen, 5), + MYTHICAL("Mythical", C.cRed, C.cDRed, 14); + + private final String _name; + private final String _color; + private final String _darkColor; + private final ItemStack _itemStack; + + RewardRarity(String name, String color, String darkColor, int itemStackData) + { + _name = name; + _color = color; + _darkColor = darkColor; + _itemStack = new ItemBuilder(Material.STAINED_GLASS_PANE) + .setData((short) itemStackData) + .build(); + } + + public String getName() + { + return _name; + } + + public String getColor() + { + return _color; + } + + public String getDarkColor() + { + return _darkColor; + } + + public ItemStack getItemStack() + { + return _itemStack; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/TreasureRewardManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/TreasureRewardManager.java new file mode 100644 index 000000000..c3c1fbda8 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/TreasureRewardManager.java @@ -0,0 +1,286 @@ +package mineplex.core.treasure.reward; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.entity.Player; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.weight.WeightSet; +import mineplex.core.reward.Reward; +import mineplex.core.reward.rewards.TreasureShardReward; +import mineplex.core.treasure.types.Treasure; + +/** + * This manager serves as a random reward generator. + * A lot of this was adapted from the previous reward manager, so if you've come here to + * fix something then prepare yourself for a shock. + */ +@ReflectivelyCreateMiniPlugin +public class TreasureRewardManager extends MiniPlugin +{ + + /** + * For all the reward algorithms, if a condition cannot be met within {@value} iterations then it gives up. + * {@value} is a very generous threshold and most likely, unless due to error, each one should complete in one + * or two iterations. + */ + private static final int MAX_ATTEMPTS = 40; + + private final Map>> _rewardPoolMap; + + private TreasureRewardManager() + { + super("Treasure Rewards"); + + _rewardPoolMap = new HashMap<>(); + } + + /** + * Adds a reward into the pool for a particular chest type. + * + * @param treasure The {@link Treasure}'s pool you want to add the reward to. + * @param reward The {@link Reward} you want to add to the pool. + * @param weight The weight of the reward, bigger weight, more probable to be picked. + */ + public void addReward(Treasure treasure, Reward reward, int weight) + { + // Populate the map if absent + _rewardPoolMap.computeIfAbsent(treasure, k -> new HashMap<>()); + + // Populate the inner map if absent + Map> map = _rewardPoolMap.get(treasure); + map.computeIfAbsent(reward.getRarity(), k -> new WeightSet<>()); + // Add the reward to the WeightSet + map.get(reward.getRarity()).add(weight, reward); + } + + /** + * Returns whether or not a player has all the items within a chest's pool + * + * @param player The player you want to checl. + * @param treasure The {@link Treasure} you want to search through the pool of. + * @return a boolean value of if the player has all the items within a chest's pool. + */ + public boolean hasAllItems(Player player, Treasure treasure) + { + Map> rewardMap = _rewardPoolMap.get(treasure); + + // Null entry, programmer error + return rewardMap == null || getOwnedItems(player, treasure) == getTotalItems(treasure); + } + + /** + * Returns the number of items a player owns within a chest's pool + * + * @param player The player you want to check. + * @param treasure The {@link Treasure} you want to search through the pool of. + * @return an integer value of the amount of items the player has within a chest's pool. + */ + public int getOwnedItems(Player player, Treasure treasure) + { + Map> rewardMap = _rewardPoolMap.get(treasure); + + // Null entry, programmer error + if (rewardMap == null) + { + return 0; + } + + int owned = 0; + + // Check every reward + for (WeightSet weightSet : rewardMap.values()) + { + for (Reward reward : weightSet.elements()) + { + // If the player cannot be given that reward + if (!reward.canGiveReward(player)) + { + owned++; + } + } + } + + return owned; + } + + /** + * Returns the total number of items within a chest's pool. + * + * @param treasure The {@link Treasure} you want to search through the pool of. + * @return an integer value of the amount of items the chest has within it's pool. + */ + public int getTotalItems(Treasure treasure) + { + Map> rewardMap = _rewardPoolMap.get(treasure); + + // Null entry, programmer error + if (rewardMap == null) + { + return 0; + } + + int amount = 0; + + // Check every reward + for (WeightSet weightSet : rewardMap.values()) + { + amount += weightSet.elements().size(); + } + + return amount; + } + + /** + * Returns a list of random rewards that can be awarded to a player. + * + * @param player The player you want to give the rewards to. + * @param treasure The {@link Treasure} you want to search through the pool of. + * @return A {@link List} the size of {@link Treasure#getRewardsPerChest()} and with the contents of random rewards + * that can be given to the player or null if an error has occurred. + */ + public List getRewards(Player player, Treasure treasure) + { + Map> rewardMap = _rewardPoolMap.get(treasure); + + // Null entry, programmer error + if (rewardMap == null) + { + return null; + } + + // The list of rewards that will be returned + List rewards = new ArrayList<>(treasure.getRewardsPerChest()); + // These variables here are used to ensure that each chest opening will always contain at least one uncommon + // but never more than one mythical. + boolean hasUncommon = false; + boolean hasMythical = false; + int attempts = 0; + + for (int i = 0; i < treasure.getRewardsPerChest(); i++) + { + attempts++; + Reward reward = nextReward(player, treasure, rewardMap, i, hasUncommon, hasMythical); + + // If the reward was null then the reward could not have been given to the player + if (reward == null) + { + // At this point if it has taken 20+ attempts to find a reward and it's still null, then there seems to + // be a problem with the chest's pool or a programmer error. + if (attempts > MAX_ATTEMPTS) + { + return null; + } + // We run the loop again + i--; + continue; + } + + RewardRarity rarity = reward.getRarity(); + + // If the reward is as or more uncommon than an uncommon + if (rarity.ordinal() >= RewardRarity.UNCOMMON.ordinal()) + { + hasUncommon = true; + } + + // If the reward is as more uncommon than an mythical + if (rarity.ordinal() >= RewardRarity.MYTHICAL.ordinal()) + { + hasMythical = true; + } + + // Add the reward to our list of rewards + rewards.add(reward); + } + + // Due to the last reward always being an uncommon or better, we swap it randomly with another element as to + // appear more random. + Collections.swap(rewards, rewards.size() - 1, UtilMath.r(rewards.size())); + + return rewards; + } + + /** + * This determines the rarity of the reward. + * + * @param player The player you want to give the reward to. + * @param treasure The {@link Treasure} you want to search through the pool of. + * @param rewardMap The map of rarities and weights. + * @param index The current index of this reward, for example the first chest to open will have an index of 0, second 1 etc... + * @param hasUncommon Does the current list of rewards contain an uncommon or better? + * @param hasMythical Does the current list of rewards contain a mythical or better? + * @return A random reward that can be given to the player or null if not or an error has occurred. + */ + private Reward nextReward(Player player, Treasure treasure, Map> rewardMap, int index, boolean hasUncommon, boolean hasMythical) + { + RewardRarity rarity = treasure.getRewardType().generateRarity(); + int attempts = 0; + + // If the reward list already contains a mythical, keep trying until it isn't one + while (attempts++ < MAX_ATTEMPTS && hasMythical && rarity == RewardRarity.MYTHICAL) + { + rarity = treasure.getRewardType().generateRarity(); + } + + // If we are on the last reward and there hasn't been an uncommon then make sure this reward is uncommon + // Additional duplicates check is needed as chests without duplicates can only contain rare or above. + if (!hasUncommon && treasure.isDuplicates() && treasure.getRewardsPerChest() > 1 && index == treasure.getRewardsPerChest() - 1) + { + rarity = RewardRarity.UNCOMMON; + } + + WeightSet rewardSet = rewardMap.get(rarity); + + // Null entry, programmer error + if (rewardSet == null || rewardSet.elements().isEmpty()) + { + return null; + } + + // If the chest doesn't give duplicates + if (!treasure.isDuplicates()) + { + // Clone the set as we modify it below + rewardSet = new WeightSet<>(rewardSet); + // Remove all elements if they cannot be given to a player + rewardSet.removeIf(rewardWeight -> !rewardWeight.getValue().canGiveReward(player)); + } + + // Nothing for this rarity + if (rewardSet.elements().isEmpty()) + { + return null; + } + + return nextReward(player, treasure, rewardSet); + } + + /** + * This determines the actual reward. + * + * @param player The player you want to give the reward to. + * @param treasure The {@link Treasure} you want to search through the pool of. + * @param rewardSet The set of reward weights. + * @return A random reward that can be given to the player or null if not or an error has occurred. + */ + private Reward nextReward(Player player, Treasure treasure, WeightSet rewardSet) + { + // Get a random reward + Reward reward = rewardSet.generateRandom(); + + // If the chest can award duplicates and the player cannot be given the reward, give a shard reward instead. + if (treasure.isDuplicates() && !reward.canGiveReward(player)) + { + return new TreasureShardReward(reward, reward.getRarity()); + } + + return reward; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/AncientTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/AncientTreasure.java new file mode 100644 index 000000000..35efe5c3d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/AncientTreasure.java @@ -0,0 +1,21 @@ +package mineplex.core.treasure.types; + +import mineplex.core.reward.RewardType; +import mineplex.core.treasure.animation.animations.AncientChestAnimation; + +public class AncientTreasure extends NormalTreasure +{ + + public AncientTreasure() + { + super(TreasureType.ANCIENT); + + setAnimation(treasureLocation -> new AncientChestAnimation(this, treasureLocation)); + setRewards(RewardType.ANCIENT_CHEST); + setRewardsPerChest(4); + allowDuplicates(); + setPurchasable(5000); + purchasableFromStore(); + enabledByDefault(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/CarlTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/CarlTreasure.java new file mode 100644 index 000000000..6ffab18a0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/CarlTreasure.java @@ -0,0 +1,33 @@ +package mineplex.core.treasure.types; + +import org.bukkit.entity.Player; + +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardType; + +public class CarlTreasure extends NormalTreasure +{ + + public CarlTreasure() + { + super(TreasureType.CARL_SPINNER); + + setRewardsPerChest(1); + allowDuplicates(); + enabledByDefault(); + } + + public Reward nextReward(Player player, boolean filler) + { + if (filler) + { + setRewards(RewardType.SPINNER_FILLER); + } + else + { + setRewards(RewardType.SPINNER_REAL); + } + + return Treasure.getRewardManager().getRewards(player, this).get(0); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/GameLootTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/GameLootTreasure.java new file mode 100644 index 000000000..8edfeed5b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/GameLootTreasure.java @@ -0,0 +1,24 @@ +package mineplex.core.treasure.types; + +import org.bukkit.entity.Player; + +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardType; + +public class GameLootTreasure extends NormalTreasure +{ + + public GameLootTreasure() + { + super(TreasureType.GAME_LOOT); + + setRewardsPerChest(1); + allowDuplicates(); + enabledByDefault(); + } + + public Reward nextReward(Player player) + { + return Treasure.getRewardManager().getRewards(player, this).get(0); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/IlluminatedTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/IlluminatedTreasure.java new file mode 100644 index 000000000..dbb480a6a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/IlluminatedTreasure.java @@ -0,0 +1,53 @@ +package mineplex.core.treasure.types; + +import mineplex.core.gadget.gadgets.kitselector.HaloKitSelector; +import mineplex.core.gadget.gadgets.kitselector.RainbowDanceKitSelector; +import mineplex.core.gadget.gadgets.kitselector.ShimmeringRingKitSelector; +import mineplex.core.gadget.gadgets.kitselector.SingleParticleKitSelector; +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardType; +import mineplex.core.reward.rewards.InventoryReward; +import mineplex.core.treasure.animation.animations.IlluminatedChestAnimation; +import mineplex.core.treasure.reward.RewardRarity; + +public class IlluminatedTreasure extends NormalTreasure +{ + + public IlluminatedTreasure() + { + super(TreasureType.ILLUMINATED); + + setAnimation(treasureLocation -> new IlluminatedChestAnimation(this, treasureLocation)); + setRewards(RewardType.ILLUMINATED_CHEST); + setRewardsPerChest(1); + setPurchasable(20000); + purchasableFromStore(); + enabledByDefault(); + } + + @Override + protected void addRare(RewardRarity rarity) + { + // Kit Selectors + addGadgetReward(getGadget(HaloKitSelector.class), rarity, 100); + addGadgetReward(getGadget(RainbowDanceKitSelector.class), rarity, 100); + addGadgetReward(getGadget(ShimmeringRingKitSelector.class), rarity, 150); + addGadgetReward(getKitSelector(SingleParticleKitSelector.SingleParticleSelectors.FLAMES_OF_FURY), rarity, 150); + addGadgetReward(getKitSelector(SingleParticleKitSelector.SingleParticleSelectors.EMBER), rarity, 100); + addGadgetReward(getKitSelector(SingleParticleKitSelector.SingleParticleSelectors.LOVE), rarity, 100); + } + + @Override + protected void addReward(Reward reward, int weight) + { + // Illuminated chests have everything in the normal pool expect item gadgets. + // To avoid copying code and making it easy to maintain, we can just ignore all + // inventory rewards here. + if (reward instanceof InventoryReward) + { + return; + } + + super.addReward(reward, weight); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/MOBATreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/MOBATreasure.java new file mode 100644 index 000000000..3a7c5b62d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/MOBATreasure.java @@ -0,0 +1,125 @@ +package mineplex.core.treasure.types; + +import mineplex.core.gadget.gadgets.gamemodifiers.moba.shopmorph.ShopMorphType; +import mineplex.core.gadget.gadgets.gamemodifiers.moba.skins.HeroSkinGadget; +import mineplex.core.gadget.gadgets.morph.moba.MorphAnath; +import mineplex.core.gadget.gadgets.morph.moba.MorphBardolf; +import mineplex.core.gadget.gadgets.morph.moba.MorphBiff; +import mineplex.core.gadget.gadgets.morph.moba.MorphDana; +import mineplex.core.gadget.gadgets.morph.moba.MorphDevon; +import mineplex.core.gadget.gadgets.morph.moba.MorphHattori; +import mineplex.core.gadget.gadgets.morph.moba.MorphIvy; +import mineplex.core.gadget.gadgets.morph.moba.MorphLarissa; +import mineplex.core.gadget.gadgets.morph.moba.MorphRowena; +import mineplex.core.reward.RewardType; +import mineplex.core.reward.rewards.GadgetReward; +import mineplex.core.treasure.animation.animations.MOBAChestAnimation; +import mineplex.core.treasure.animation.animations.TrickOrTreatChestAnimation; +import mineplex.core.treasure.reward.RewardRarity; + +public class MOBATreasure extends Treasure +{ + + public MOBATreasure() + { + super(TreasureType.MOBA); + + setAnimation(treasureLocation -> new MOBAChestAnimation(this, treasureLocation)); + setRewards(RewardType.MOBA); + setRewardsPerChest(4); + setPurchasable(20000); + purchasableFromStore(); + enabledByDefault(); + allowDuplicates(); + } + + @Override + protected void addUncommon(RewardRarity rarity) + { + for (ShopMorphType shopMorphType : ShopMorphType.values()) + { + if (shopMorphType.getRarity() == rarity) + { + addMOBAShopSkin(shopMorphType, rarity, 1); + } + } + + addAllMOBASkins(rarity); + } + + @Override + protected void addRare(RewardRarity rarity) + { + for (ShopMorphType shopMorphType : ShopMorphType.values()) + { + if (shopMorphType.getRarity() == rarity) + { + addMOBAShopSkin(shopMorphType, rarity, 1); + } + } + + addAllMOBASkins(rarity); + } + + @Override + protected void addLegendary(RewardRarity rarity) + { + addGadgetReward(getGadget(MorphHattori.class), rarity, 1); + addGadgetReward(getGadget(MorphDevon.class), rarity, 1); + addGadgetReward(getGadget(MorphAnath.class), rarity, 1); + addGadgetReward(getGadget(MorphDana.class), rarity, 1); + addGadgetReward(getGadget(MorphBardolf.class), rarity, 1); + addGadgetReward(getGadget(MorphRowena.class), rarity, 1); + addGadgetReward(getGadget(MorphLarissa.class), rarity, 1); + addGadgetReward(getGadget(MorphBiff.class), rarity, 1); + addGadgetReward(getGadget(MorphIvy.class), rarity, 1); + + addAllMOBASkins(rarity); + } + + @Override + protected void addMythical(RewardRarity rarity) + { + } + + private void addAllMOBASkins(RewardRarity rarity) + { + HeroSkinGadget.getSkins().forEach((name, dataList) -> + { + if (name.equals("Bardolf-Werewolf")) + { + return; + } + + dataList.forEach(data -> + { + if (data.getRarity() != rarity) + { + return; + } + + addMOBASkin(data.getGadget(), rarity, 1); + }); + }); + } + + public GadgetReward addMOBASkin(HeroSkinGadget gadget, RewardRarity rarity, int weight) + { + return addMOBASkin(gadget, rarity, weight, getShards(rarity)); + } + + public GadgetReward addMOBASkin(HeroSkinGadget gadget, RewardRarity rarity, int weight, int shards) + { + return addGadgetReward(gadget, rarity, weight, shards); + } + + public GadgetReward addMOBAShopSkin(ShopMorphType morphType, RewardRarity rarity, int weight) + { + return addMOBAShopSkin(morphType, rarity, weight, getShards(rarity)); + } + + public GadgetReward addMOBAShopSkin(ShopMorphType morphType, RewardRarity rarity, int weight, int shards) + { + return addGadgetReward(GADGET_MANAGER.getGameCosmeticManager().getGadgetFrom(morphType.getName()), rarity, weight, shards); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/MinestrikeTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/MinestrikeTreasure.java new file mode 100644 index 000000000..14b28c57e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/MinestrikeTreasure.java @@ -0,0 +1,66 @@ +package mineplex.core.treasure.types; + +import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.MineStrikeSkin; +import mineplex.core.reward.RewardType; +import mineplex.core.reward.rewards.GadgetReward; +import mineplex.core.treasure.animation.animations.MinestrikeChestAnimation; +import mineplex.core.treasure.reward.RewardRarity; + +public class MinestrikeTreasure extends Treasure +{ + + public MinestrikeTreasure() + { + super(TreasureType.MINESTRIKE); + + setAnimation(treasureLocation -> new MinestrikeChestAnimation(this, treasureLocation)); + setRewards(RewardType.MINESTRIKE_CHEST); + setRewardsPerChest(2); + setPurchasable(10000); + purchasableFromStore(); + enabledByDefault(); + allowDuplicates(); + } + + @Override + protected void addRare(RewardRarity rarity) + { + addMineStrikeSkinReward(MineStrikeSkin.SSG_08_Blood_in_the_Water, rarity, 150, 1000); + addMineStrikeSkinReward(MineStrikeSkin.Galil_AR_Eco, rarity, 150, 1000); + addMineStrikeSkinReward(MineStrikeSkin.Nova_Koi, rarity, 100, 1000); + addMineStrikeSkinReward(MineStrikeSkin.Knife_M9_Bayonette_Fade, rarity, 30, 2500); + addMineStrikeSkinReward(MineStrikeSkin.PP_Bizon_Streak, rarity, 150, 1000); + addMineStrikeSkinReward(MineStrikeSkin.CZ75_Auto_Tigris, rarity, 100, 1000); + addMineStrikeSkinReward(MineStrikeSkin.XM1014_Tranquility, rarity, 100, 1000); + addMineStrikeSkinReward(MineStrikeSkin.Desert_Eagle_Golden_Gun, rarity, 30, 2500); + addMineStrikeSkinReward(MineStrikeSkin.P90_Asiimov, rarity, 100, 1000); + addMineStrikeSkinReward(MineStrikeSkin.SG553_Pulse, rarity, 100, 1000); + } + + @Override + protected void addLegendary(RewardRarity rarity) + { + addMineStrikeSkinReward(MineStrikeSkin.Desert_Eagle_Blaze, rarity, 100, 5000); + addMineStrikeSkinReward(MineStrikeSkin.Glock_18_Fade, rarity, 100, 5000); + addMineStrikeSkinReward(MineStrikeSkin.P250_Muertos, rarity, 100, 5000); + addMineStrikeSkinReward(MineStrikeSkin.AK_47_Vulcan, rarity, 100, 5000); + addMineStrikeSkinReward(MineStrikeSkin.Knife_Counter_Terrorist_Sword, rarity, 50, 6500); + addMineStrikeSkinReward(MineStrikeSkin.Knife_Terrorist_Sword, rarity, 50, 6500); + addMineStrikeSkinReward(MineStrikeSkin.Knife_M9_Bayonette_Glass, rarity, 50, 6500); + addMineStrikeSkinReward(MineStrikeSkin.AK_47_Guardian, rarity, 10, 7500); + addMineStrikeSkinReward(MineStrikeSkin.AWP_Asiimov, rarity, 100, 5000); + addMineStrikeSkinReward(MineStrikeSkin.FAMAS_Pulse, rarity, 100, 5000); + addMineStrikeSkinReward(MineStrikeSkin.XM1014_Pig_Gun, rarity, 10, 7500); + addMineStrikeSkinReward(MineStrikeSkin.M4A4_Enderman, rarity, 10, 7500); + } + + @Override + protected void addMythical(RewardRarity rarity) + { + } + + private GadgetReward addMineStrikeSkinReward(MineStrikeSkin skin, RewardRarity rarity, int weight, int shards) + { + return addGadgetReward(GADGET_MANAGER.getGameCosmeticManager().getGadgetFrom(skin.getSkinName()), rarity, weight, shards); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/MythicalTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/MythicalTreasure.java new file mode 100644 index 000000000..27ef03578 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/MythicalTreasure.java @@ -0,0 +1,47 @@ +package mineplex.core.treasure.types; + +import mineplex.core.gadget.gadgets.kitselector.HaloKitSelector; +import mineplex.core.gadget.gadgets.kitselector.RainbowDanceKitSelector; +import mineplex.core.gadget.gadgets.kitselector.ShimmeringRingKitSelector; +import mineplex.core.gadget.gadgets.kitselector.SingleParticleKitSelector; +import mineplex.core.reward.RewardType; +import mineplex.core.treasure.animation.animations.MythicalChestAnimation; +import mineplex.core.treasure.reward.RewardRarity; + +public class MythicalTreasure extends NormalTreasure +{ + + public MythicalTreasure() + { + super(TreasureType.MYTHICAL); + + setAnimation(treasureLocation -> new MythicalChestAnimation(this, treasureLocation)); + setRewards(RewardType.MYTHICAL_CHEST); + setRewardsPerChest(4); + allowDuplicates(); + setPurchasable(10000); + purchasableFromStore(); + enabledByDefault(); + } + + @Override + protected void addRare(RewardRarity rarity) + { + super.addRare(rarity); + + // Kit Selectors + addGadgetReward(getGadget(HaloKitSelector.class), rarity, 100); + addGadgetReward(getGadget(RainbowDanceKitSelector.class), rarity, 100); + addGadgetReward(getGadget(ShimmeringRingKitSelector.class), rarity, 150); + addGadgetReward(getKitSelector(SingleParticleKitSelector.SingleParticleSelectors.FLAMES_OF_FURY), rarity, 150); + addGadgetReward(getKitSelector(SingleParticleKitSelector.SingleParticleSelectors.EMBER), rarity, 100); + addGadgetReward(getKitSelector(SingleParticleKitSelector.SingleParticleSelectors.LOVE), rarity, 100); + } + + @Override + protected void addMythical(RewardRarity rarity) + { + // Rank + addRankReward(rarity, true, 100); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/NormalTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/NormalTreasure.java new file mode 100644 index 000000000..a523ad2a8 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/NormalTreasure.java @@ -0,0 +1,275 @@ +package mineplex.core.treasure.types; + +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailBlood; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailConfetti; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailEmerald; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailEnchant; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailMusic; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailShadow; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailStorm; +import mineplex.core.gadget.gadgets.balloons.BalloonType; +import mineplex.core.gadget.gadgets.death.DeathBlood; +import mineplex.core.gadget.gadgets.death.DeathEmerald; +import mineplex.core.gadget.gadgets.death.DeathEnchant; +import mineplex.core.gadget.gadgets.death.DeathMusic; +import mineplex.core.gadget.gadgets.death.DeathPinataBurst; +import mineplex.core.gadget.gadgets.death.DeathShadow; +import mineplex.core.gadget.gadgets.death.DeathStorm; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpBlood; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpEmerald; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpEnchant; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpFirecracker; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpMusic; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpShadow; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpStorm; +import mineplex.core.gadget.gadgets.item.ItemBatGun; +import mineplex.core.gadget.gadgets.item.ItemEtherealPearl; +import mineplex.core.gadget.gadgets.item.ItemFirework; +import mineplex.core.gadget.gadgets.item.ItemFleshHook; +import mineplex.core.gadget.gadgets.item.ItemMelonLauncher; +import mineplex.core.gadget.gadgets.item.ItemPaintballGun; +import mineplex.core.gadget.gadgets.item.ItemTNT; +import mineplex.core.gadget.gadgets.morph.MorphBat; +import mineplex.core.gadget.gadgets.morph.MorphBlock; +import mineplex.core.gadget.gadgets.morph.MorphChicken; +import mineplex.core.gadget.gadgets.morph.MorphCow; +import mineplex.core.gadget.gadgets.morph.MorphEnderman; +import mineplex.core.gadget.gadgets.morph.MorphSlime; +import mineplex.core.gadget.gadgets.morph.MorphVillager; +import mineplex.core.gadget.gadgets.mount.types.MountCart; +import mineplex.core.gadget.gadgets.mount.types.MountFrost; +import mineplex.core.gadget.gadgets.mount.types.MountMule; +import mineplex.core.gadget.gadgets.mount.types.MountSlime; +import mineplex.core.gadget.gadgets.mount.types.MountUndead; +import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitBoots; +import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitChestplate; +import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitHelmet; +import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitLeggings; +import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitBoots; +import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitChestplate; +import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitHelmet; +import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitLeggings; +import mineplex.core.gadget.gadgets.particle.ParticleBlood; +import mineplex.core.gadget.gadgets.particle.ParticleEmerald; +import mineplex.core.gadget.gadgets.particle.ParticleEnchant; +import mineplex.core.gadget.gadgets.particle.ParticleFairy; +import mineplex.core.gadget.gadgets.particle.ParticleFireRings; +import mineplex.core.gadget.gadgets.particle.ParticleFoot; +import mineplex.core.gadget.gadgets.particle.ParticleHeart; +import mineplex.core.gadget.gadgets.particle.ParticleMusic; +import mineplex.core.gadget.gadgets.particle.ParticlePartyTime; +import mineplex.core.gadget.gadgets.particle.ParticleRain; +import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel; +import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons; +import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal; +import mineplex.core.gadget.gadgets.particle.ParticleWingsPixie; +import mineplex.core.gadget.gadgets.particle.ParticleYinYang; +import mineplex.core.gadget.gadgets.wineffect.WinEffectBabyChicken; +import mineplex.core.gadget.gadgets.wineffect.WinEffectLavaTrap; +import mineplex.core.gadget.gadgets.wineffect.WinEffectLightningStrike; +import mineplex.core.gadget.gadgets.wineffect.WinEffectMrPunchMan; +import mineplex.core.gadget.gadgets.wineffect.WinEffectRiseOfTheElderGuardian; +import mineplex.core.pet.PetType; +import mineplex.core.treasure.reward.RewardRarity; + +public class NormalTreasure extends Treasure +{ + + NormalTreasure(TreasureType treasureType) + { + super(treasureType); + } + + @Override + protected void addCommon(RewardRarity rarity) + { + // Gadgets + addGadgetReward(getGadget(ItemBatGun.class), rarity, 10, 4, 10); + addGadgetReward(getGadget(ItemEtherealPearl.class), rarity, 10, 6, 15); + addGadgetReward(getGadget(ItemFirework.class), rarity, 10, 10, 25); + addGadgetReward(getGadget(ItemFleshHook.class), rarity, 10, 8, 20); + addGadgetReward(getGadget(ItemMelonLauncher.class), rarity, 10, 10, 25); + addGadgetReward(getGadget(ItemPaintballGun.class), rarity, 10, 20, 50); + addGadgetReward(getGadget(ItemTNT.class), rarity, 10, 4, 10); + } + + @Override + protected void addUncommon(RewardRarity rarity) + { + // Gadgets + addGadgetReward(getGadget(ItemBatGun.class), rarity, 250, 20, 40); + addGadgetReward(getGadget(ItemEtherealPearl.class), rarity, 250, 30, 60); + addGadgetReward(getGadget(ItemFirework.class), rarity, 250, 25, 50); + addGadgetReward(getGadget(ItemFleshHook.class), rarity, 250, 40, 80); + addGadgetReward(getGadget(ItemMelonLauncher.class), rarity, 250, 25, 50); + addGadgetReward(getGadget(ItemPaintballGun.class), rarity, 250, 100, 200); + addGadgetReward(getGadget(ItemTNT.class), rarity, 250, 20, 40); + + // Pets + addPetReward(PetType.CHICKEN, rarity, 143); + addPetReward(PetType.COW, rarity, 500); + addPetReward(PetType.MUSHROOM_COW, rarity, 200); + addPetReward(PetType.OCELOT, rarity, 167); + addPetReward(PetType.PIG, rarity, 200); + addPetReward(PetType.SHEEP, rarity, 333); + addPetReward(PetType.WOLF, rarity, 125); + + // Music Discs + addMusicReward("Blocks", rarity, 25); + addMusicReward("Cat", rarity, 25); + addMusicReward("Chirp", rarity, 25); + addMusicReward("Far", rarity, 25); + addMusicReward("Mall", rarity, 25); + addMusicReward("Mellohi", rarity, 25); + addMusicReward("Stal", rarity, 25); + addMusicReward("Strad", rarity, 25); + addMusicReward("Wait", rarity, 25); + addMusicReward("Ward", rarity, 25); + + // Balloons + addBalloonReward(BalloonType.BABY_COW, rarity, 10, 100); + addBalloonReward(BalloonType.BABY_PIG, rarity, 10, 100); + addBalloonReward(BalloonType.BABY_SHEEP, rarity, 15, 100); + } + + @Override + protected void addRare(RewardRarity rarity) + { + //Morphs + addGadgetReward(getGadget(MorphVillager.class), rarity, 83); + addGadgetReward(getGadget(MorphCow.class), rarity, 167); + addGadgetReward(getGadget(MorphChicken.class), rarity, 50); + addGadgetReward(getGadget(MorphEnderman.class), rarity, 33); + + //Mounts + addGadgetReward(getGadget(MountFrost.class), rarity, 50); + addGadgetReward(getGadget(MountSlime.class), rarity, 67); + addGadgetReward(getGadget(MountCart.class), rarity, 100); + addGadgetReward(getGadget(MountMule.class), rarity, 200); + + // Outfit Rave + addGadgetReward(getGadget(OutfitRaveSuitHelmet.class), rarity, 30); + addGadgetReward(getGadget(OutfitRaveSuitChestplate.class), rarity, 30); + addGadgetReward(getGadget(OutfitRaveSuitLeggings.class), rarity, 30); + addGadgetReward(getGadget(OutfitRaveSuitBoots.class), rarity, 30); + // Outfit Space + addGadgetReward(getGadget(OutfitSpaceSuitHelmet.class), rarity, 50); + addGadgetReward(getGadget(OutfitSpaceSuitChestplate.class), rarity, 50); + addGadgetReward(getGadget(OutfitSpaceSuitLeggings.class), rarity, 50); + addGadgetReward(getGadget(OutfitSpaceSuitBoots.class), rarity, 50); + + // Arrow Trails + addGadgetReward(getGadget(ArrowTrailConfetti.class), rarity, 27); + addGadgetReward(getGadget(ArrowTrailBlood.class), rarity, 50); + addGadgetReward(getGadget(ArrowTrailEmerald.class), rarity, 25); + addGadgetReward(getGadget(ArrowTrailMusic.class), rarity, 27); + addGadgetReward(getGadget(ArrowTrailStorm.class), rarity, 30); + addGadgetReward(getGadget(ArrowTrailShadow.class), rarity, 15); + + // Double Jumps + addGadgetReward(getGadget(DoubleJumpFirecracker.class), rarity, 33); + addGadgetReward(getGadget(DoubleJumpEmerald.class), rarity, 25); + addGadgetReward(getGadget(DoubleJumpShadow.class), rarity, 15); + addGadgetReward(getGadget(DoubleJumpStorm.class), rarity, 30); + addGadgetReward(getGadget(DoubleJumpBlood.class), rarity, 50); + addGadgetReward(getGadget(DoubleJumpMusic.class), rarity, 20); + + // Death Effects + addGadgetReward(getGadget(DeathPinataBurst.class), rarity, 27); + addGadgetReward(getGadget(DeathEmerald.class), rarity, 25); + addGadgetReward(getGadget(DeathShadow.class), rarity, 15); + addGadgetReward(getGadget(DeathStorm.class), rarity, 30); + addGadgetReward(getGadget(DeathBlood.class), rarity, 50); + addGadgetReward(getGadget(DeathMusic.class), rarity, 20); + + // Particles + addGadgetReward(getGadget(ParticlePartyTime.class), rarity, 12); + + // Titles + addTitleReward("shrug", rarity, 10, 500); + addTitleReward("tableflip", rarity, 10, 500); + addTitleReward("tablerespecter", rarity, 15, 500); + addTitleReward("tableflip-disgusted", rarity, 15, 500); + addTitleReward("tableflip-enraged", rarity, 15, 500); + addTitleReward("tableflip-riot", rarity, 10, 500); + addTitleReward("teddy-bear", rarity, 10, 500); + addTitleReward("disgust", rarity, 10, 500); + addTitleReward("old-man", rarity, 5, 500); + addTitleReward("jake", rarity, 5, 500); + addTitleReward("finn", rarity, 5, 500); + addTitleReward("finn-and-jake", rarity, 5, 500); + addTitleReward("boxer", rarity, 5, 500); + addTitleReward("zoidberg", rarity, 5, 500); + + // Balloons + addBalloonReward(BalloonType.BABY_ZOMBIE, rarity, 25, 500); + addBalloonReward(BalloonType.BABY_MUSHROOM, rarity, 50, 500); + addBalloonReward(BalloonType.BABY_OCELOT, rarity, 50, 500); + addBalloonReward(BalloonType.BABY_WOLF, rarity, 75, 500); + addBalloonReward(BalloonType.BABY_VILLAGER, rarity, 25, 500); + addBalloonReward(BalloonType.BABY_SLIME, rarity, 25, 500); + addBalloonReward(BalloonType.BAT, rarity, 50, 500); + } + + @Override + protected void addLegendary(RewardRarity rarity) + { + // Enchant set + addGadgetReward(getGadget(ArrowTrailEnchant.class), rarity, 10); + addGadgetReward(getGadget(DeathEnchant.class), rarity, 10); + addGadgetReward(getGadget(DoubleJumpEnchant.class), rarity, 10); + + // Morphs + addGadgetReward(getGadget(MorphSlime.class), rarity, 10); + addGadgetReward(getGadget(MorphBat.class), rarity, 25); + addGadgetReward(getGadget(MorphBlock.class), rarity, 20); + + // Mounts + addGadgetReward(getGadget(MountUndead.class), rarity, 33); + + // Particle Trails + addGadgetReward(getGadget(ParticleWingsAngel.class), rarity, 15); + addGadgetReward(getGadget(ParticleBlood.class), rarity, 10); + addGadgetReward(getGadget(ParticleWingsDemons.class), rarity, 15); + addGadgetReward(getGadget(ParticleEnchant.class), rarity, 25); + addGadgetReward(getGadget(ParticleFairy.class), rarity, 4); + addGadgetReward(getGadget(ParticleFireRings.class), rarity, 17); + addGadgetReward(getGadget(ParticleEmerald.class), rarity, 8); + addGadgetReward(getGadget(ParticleHeart.class), rarity, 2); + addGadgetReward(getGadget(ParticleWingsInfernal.class), rarity, 4); + addGadgetReward(getGadget(ParticleMusic.class), rarity, 15); + addGadgetReward(getGadget(ParticleWingsPixie.class), rarity, 4); + addGadgetReward(getGadget(ParticleRain.class), rarity, 13); + addGadgetReward(getGadget(ParticleFoot.class), rarity, 33); + addGadgetReward(getGadget(ParticleYinYang.class), rarity, 20); + + // Win Effects + addGadgetReward(getGadget(WinEffectBabyChicken.class), rarity, 10); + addGadgetReward(getGadget(WinEffectLavaTrap.class), rarity, 20); + addGadgetReward(getGadget(WinEffectLightningStrike.class), rarity, 20); + addGadgetReward(getGadget(WinEffectMrPunchMan.class), rarity, 33); + addGadgetReward(getGadget(WinEffectRiseOfTheElderGuardian.class), rarity, 4); + + // Titles + addTitleReward("ayyye", rarity, 25); + addTitleReward("ameno", rarity, 15); + addTitleReward("magician", rarity, 25); + addTitleReward("fireball", rarity, 75); + addTitleReward("magic-missile", rarity, 75); + addTitleReward("pewpewpew", rarity, 75); + addTitleReward("stardust", rarity, 60); + addTitleReward("blow-a-kiss", rarity, 60); + addTitleReward("cool-guy", rarity, 60); + addTitleReward("deal-with-it", rarity, 60); + addTitleReward("party-time", rarity, 55); + addTitleReward("lalala", rarity, 30); + addTitleReward("gotta-go", rarity, 30); + addTitleReward("whaaat", rarity, 30); + + // Balloons + addBalloonReward(BalloonType.SQUID, rarity, 10); + addBalloonReward(BalloonType.SILVERFISH, rarity, 30); + addBalloonReward(BalloonType.GUARDIAN, rarity, 30); + addBalloonReward(BalloonType.EMERALD_BLOCK, rarity, 15); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/OldTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/OldTreasure.java new file mode 100644 index 000000000..0ea7f45e3 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/OldTreasure.java @@ -0,0 +1,21 @@ +package mineplex.core.treasure.types; + +import mineplex.core.reward.RewardType; +import mineplex.core.treasure.animation.animations.OldChestAnimation; + +public class OldTreasure extends NormalTreasure +{ + + public OldTreasure() + { + super(TreasureType.OLD); + + setAnimation(treasureLocation -> new OldChestAnimation(this, treasureLocation)); + setRewards(RewardType.OLD_CHEST); + setRewardsPerChest(4); + allowDuplicates(); + setPurchasable(1000); + purchasableFromStore(); + enabledByDefault(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/OmegaTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/OmegaTreasure.java new file mode 100644 index 000000000..ed5b8f2c1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/OmegaTreasure.java @@ -0,0 +1,399 @@ +package mineplex.core.treasure.types; + +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailBlood; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailCandyCane; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailConfetti; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailCupid; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailEmerald; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailEnchant; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailFreedom; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailFrostLord; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailHalloween; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailMusic; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailRedWhite; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailShadow; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailSpring; +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailStorm; +import mineplex.core.gadget.gadgets.balloons.BalloonType; +import mineplex.core.gadget.gadgets.death.DeathBlood; +import mineplex.core.gadget.gadgets.death.DeathCandyCane; +import mineplex.core.gadget.gadgets.death.DeathCupidsBrokenHeart; +import mineplex.core.gadget.gadgets.death.DeathEmerald; +import mineplex.core.gadget.gadgets.death.DeathEnchant; +import mineplex.core.gadget.gadgets.death.DeathFreedom; +import mineplex.core.gadget.gadgets.death.DeathFrostLord; +import mineplex.core.gadget.gadgets.death.DeathMapleLeaf; +import mineplex.core.gadget.gadgets.death.DeathMusic; +import mineplex.core.gadget.gadgets.death.DeathPinataBurst; +import mineplex.core.gadget.gadgets.death.DeathPresentDanger; +import mineplex.core.gadget.gadgets.death.DeathShadow; +import mineplex.core.gadget.gadgets.death.DeathSpring; +import mineplex.core.gadget.gadgets.death.DeathStorm; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpBlood; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpCandyCane; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpCupidsWings; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpEmerald; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpEnchant; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpFirecracker; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpFreedom; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpFrostLord; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpHalloween; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpMaple; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpMusic; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpShadow; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpSpring; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpStorm; +import mineplex.core.gadget.gadgets.hat.HatType; +import mineplex.core.gadget.gadgets.kitselector.HaloKitSelector; +import mineplex.core.gadget.gadgets.kitselector.RainbowDanceKitSelector; +import mineplex.core.gadget.gadgets.kitselector.ShimmeringRingKitSelector; +import mineplex.core.gadget.gadgets.kitselector.SingleParticleKitSelector.SingleParticleSelectors; +import mineplex.core.gadget.gadgets.morph.MorphAwkwardRabbit; +import mineplex.core.gadget.gadgets.morph.MorphBat; +import mineplex.core.gadget.gadgets.morph.MorphBlock; +import mineplex.core.gadget.gadgets.morph.MorphBunny; +import mineplex.core.gadget.gadgets.morph.MorphChicken; +import mineplex.core.gadget.gadgets.morph.MorphCow; +import mineplex.core.gadget.gadgets.morph.MorphEnderman; +import mineplex.core.gadget.gadgets.morph.MorphGrimReaper; +import mineplex.core.gadget.gadgets.morph.MorphLoveDoctor; +import mineplex.core.gadget.gadgets.morph.MorphPumpkinKing; +import mineplex.core.gadget.gadgets.morph.MorphSlime; +import mineplex.core.gadget.gadgets.morph.MorphSnowman; +import mineplex.core.gadget.gadgets.morph.MorphUncleSam; +import mineplex.core.gadget.gadgets.morph.MorphVillager; +import mineplex.core.gadget.gadgets.mount.types.MountBabyReindeer; +import mineplex.core.gadget.gadgets.mount.types.MountCake; +import mineplex.core.gadget.gadgets.mount.types.MountCart; +import mineplex.core.gadget.gadgets.mount.types.MountChicken; +import mineplex.core.gadget.gadgets.mount.types.MountFreedomHorse; +import mineplex.core.gadget.gadgets.mount.types.MountFrost; +import mineplex.core.gadget.gadgets.mount.types.MountLoveTrain; +import mineplex.core.gadget.gadgets.mount.types.MountMule; +import mineplex.core.gadget.gadgets.mount.types.MountNightmareSteed; +import mineplex.core.gadget.gadgets.mount.types.MountSlime; +import mineplex.core.gadget.gadgets.mount.types.MountSpider; +import mineplex.core.gadget.gadgets.mount.types.MountStPatricksHorse; +import mineplex.core.gadget.gadgets.mount.types.MountUndead; +import mineplex.core.gadget.gadgets.mount.types.MountValentinesSheep; +import mineplex.core.gadget.gadgets.mount.types.MountZombie; +import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuitBoots; +import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuitChestplate; +import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuitHelmet; +import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuitLeggings; +import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitBoots; +import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitChestplate; +import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitHelmet; +import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitLeggings; +import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitBoots; +import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitChestplate; +import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitHelmet; +import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitLeggings; +import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksBoots; +import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksChestplate; +import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksHat; +import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksLeggings; +import mineplex.core.gadget.gadgets.particle.ParticleBlood; +import mineplex.core.gadget.gadgets.particle.ParticleCandyCane; +import mineplex.core.gadget.gadgets.particle.ParticleChristmasTree; +import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes; +import mineplex.core.gadget.gadgets.particle.ParticleEmerald; +import mineplex.core.gadget.gadgets.particle.ParticleEnchant; +import mineplex.core.gadget.gadgets.particle.ParticleFairy; +import mineplex.core.gadget.gadgets.particle.ParticleFireRings; +import mineplex.core.gadget.gadgets.particle.ParticleFoot; +import mineplex.core.gadget.gadgets.particle.ParticleFrostLord; +import mineplex.core.gadget.gadgets.particle.ParticleHeart; +import mineplex.core.gadget.gadgets.particle.ParticleMusic; +import mineplex.core.gadget.gadgets.particle.ParticlePartyTime; +import mineplex.core.gadget.gadgets.particle.ParticleRain; +import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel; +import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons; +import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal; +import mineplex.core.gadget.gadgets.particle.ParticleWingsLove; +import mineplex.core.gadget.gadgets.particle.ParticleWingsPixie; +import mineplex.core.gadget.gadgets.particle.ParticleYinYang; +import mineplex.core.gadget.gadgets.particle.freedom.ParticleAuraNiceness; +import mineplex.core.gadget.gadgets.particle.freedom.ParticleCanadian; +import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedom; +import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedomFireworks; +import mineplex.core.gadget.gadgets.particle.freedom.ParticleStarSpangled; +import mineplex.core.gadget.gadgets.particle.spring.ParticleSpringHalo; +import mineplex.core.gadget.gadgets.taunts.BlowAKissTaunt; +import mineplex.core.gadget.gadgets.taunts.RainbowTaunt; +import mineplex.core.gadget.gadgets.wineffect.WinEffectBabyChicken; +import mineplex.core.gadget.gadgets.wineffect.WinEffectFlames; +import mineplex.core.gadget.gadgets.wineffect.WinEffectHalloween; +import mineplex.core.gadget.gadgets.wineffect.WinEffectLavaTrap; +import mineplex.core.gadget.gadgets.wineffect.WinEffectLightningStrike; +import mineplex.core.gadget.gadgets.wineffect.WinEffectMrPunchMan; +import mineplex.core.gadget.gadgets.wineffect.WinEffectRiseOfTheElderGuardian; +import mineplex.core.gadget.gadgets.wineffect.WinEffectSnowTrails; +import mineplex.core.pet.PetType; +import mineplex.core.reward.RewardType; +import mineplex.core.treasure.animation.animations.OmegaChestAnimation; +import mineplex.core.treasure.reward.RewardRarity; + +public class OmegaTreasure extends Treasure +{ + + public OmegaTreasure() + { + super(TreasureType.OMEGA); + + setAnimation(treasureLocation -> new OmegaChestAnimation(this, treasureLocation)); + setRewards(RewardType.OMEGA_CHEST); + setRewardsPerChest(1); + enabledByDefault(); + } + + @Override + protected void addUncommon(RewardRarity rarity) + { + addGadgetReward(getGadget(ArrowTrailRedWhite.class), rarity, 2); + addGadgetReward(getGadget(ArrowTrailFreedom.class), rarity, 2); + + addMusicReward("Blocks Disc", rarity, 25); + addMusicReward("Cat Disc", rarity, 25); + addMusicReward("Chirp Disc", rarity, 25); + addMusicReward("Far Disc", rarity, 25); + addMusicReward("Mall Disc", rarity, 25); + addMusicReward("Mellohi Disc", rarity, 25); + addMusicReward("Stal Disc", rarity, 25); + addMusicReward("Strad Disc", rarity, 25); + addMusicReward("Wait Disc", rarity, 25); + addMusicReward("Ward Disc", rarity, 25); + + addGadgetReward(getGadget(ArrowTrailHalloween.class), rarity, 50); + + addHatReward(HatType.PUMPKIN, rarity, 75); + addHatReward(HatType.PRESENT, rarity, 5); + addHatReward(HatType.SNOWMAN, rarity, 5); + + addBalloonReward(BalloonType.BABY_COW, rarity, 10, 100); + addBalloonReward(BalloonType.BABY_PIG, rarity, 10, 100); + addBalloonReward(BalloonType.BABY_SHEEP, rarity, 15, 100); + } + + @Override + protected void addRare(RewardRarity rarity) + { + addTitleReward("shrug", rarity, 10, 500); + addTitleReward("tableflip", rarity, 10, 500); + addTitleReward("tablerespecter", rarity, 15, 500); + addTitleReward("tableflip-disgusted", rarity, 15, 500); + addTitleReward("tableflip-enraged", rarity, 15, 500); + addTitleReward("tableflip-riot", rarity, 10, 500); + addTitleReward("teddy-bear", rarity, 10, 500); + addTitleReward("disgust", rarity, 10, 500); + addTitleReward("old-man", rarity, 5, 500); + addTitleReward("jake", rarity, 5, 500); + addTitleReward("finn", rarity, 5, 500); + addTitleReward("finn-and-jake", rarity, 5, 500); + addTitleReward("boxer", rarity, 5, 500); + addTitleReward("zoidberg", rarity, 5, 500); + + addGadgetReward(getGadget(DoubleJumpFreedom.class), rarity, 5); + addGadgetReward(getGadget(DoubleJumpBlood.class), rarity, 50); + addGadgetReward(getGadget(DoubleJumpFirecracker.class), rarity, 33); + addGadgetReward(getGadget(DoubleJumpEmerald.class), rarity, 25); + addGadgetReward(getGadget(DoubleJumpMusic.class), rarity, 20); + addGadgetReward(getGadget(DoubleJumpShadow.class), rarity, 15); + addGadgetReward(getGadget(DoubleJumpStorm.class), rarity, 30); + addGadgetReward(getGadget(DoubleJumpCandyCane.class), rarity, 20); + addGadgetReward(getGadget(DoubleJumpHalloween.class), rarity, 50); + addGadgetReward(getGadget(DoubleJumpSpring.class), rarity, 40); + addGadgetReward(getGadget(DoubleJumpFreedom.class), rarity, 50); + addGadgetReward(getGadget(DoubleJumpMaple.class), rarity, 50); + + addGadgetReward(getGadget(DeathFreedom.class), rarity, 15); + addGadgetReward(getGadget(DeathStorm.class), rarity, 30); + addGadgetReward(getGadget(DeathBlood.class), rarity, 50); + addGadgetReward(getGadget(DeathEmerald.class), rarity, 25); + addGadgetReward(getGadget(DeathMusic.class), rarity, 20); + addGadgetReward(getGadget(DeathPinataBurst.class), rarity, 27); + addGadgetReward(getGadget(DeathShadow.class), rarity, 15); + addGadgetReward(getGadget(DeathCandyCane.class), rarity, 25); + addGadgetReward(getGadget(DeathSpring.class), rarity, 60); + addGadgetReward(getGadget(DeathMapleLeaf.class), rarity, 10); + + addGadgetReward(getGadget(ArrowTrailFreedom.class), rarity, 10); + addGadgetReward(getGadget(ArrowTrailConfetti.class), rarity, 27); + addGadgetReward(getGadget(ArrowTrailBlood.class), rarity, 50); + addGadgetReward(getGadget(ArrowTrailEmerald.class), rarity, 25); + addGadgetReward(getGadget(ArrowTrailMusic.class), rarity, 27); + addGadgetReward(getGadget(ArrowTrailStorm.class), rarity, 30); + addGadgetReward(getGadget(ArrowTrailShadow.class), rarity, 15); + addGadgetReward(getGadget(ArrowTrailCandyCane.class), rarity, 10); + addGadgetReward(getGadget(ArrowTrailSpring.class), rarity, 60); + + addHatReward(HatType.UNCLE_SAM, rarity, 25); + addHatReward(HatType.COMPANION_BLOCK, rarity, 15); + addHatReward(HatType.LOVESTRUCK, rarity, 20); + addHatReward(HatType.SECRET_PACKAGE, rarity, 25); + addHatReward(HatType.TEDDY_BEAR, rarity, 25); + addHatReward(HatType.SANTA, rarity, 25); + addHatReward(HatType.RUDOLPH, rarity, 25); + addHatReward(HatType.COAL, rarity, 25); + addHatReward(HatType.AMERICA, rarity, 50); + addHatReward(HatType.CANADA, rarity, 50); + + addGadgetReward(getGadget(MorphChicken.class), rarity, 50); + addGadgetReward(getGadget(MorphCow.class), rarity, 167); + addGadgetReward(getGadget(MorphEnderman.class), rarity, 33); + addGadgetReward(getGadget(MorphVillager.class), rarity, 83); + + addGadgetReward(getGadget(WinEffectFlames.class), rarity, 100); + addGadgetReward(getGadget(WinEffectSnowTrails.class), rarity, 100); + + addGadgetReward(getGadget(MountFrost.class), rarity, 50); + addGadgetReward(getGadget(MountCart.class), rarity, 100); + addGadgetReward(getGadget(MountMule.class), rarity, 200); + addGadgetReward(getGadget(MountSlime.class), rarity, 67); + addGadgetReward(getGadget(MountLoveTrain.class), rarity, 20); + + addGadgetReward(getGadget(OutfitRaveSuitBoots.class), rarity, 30); + addGadgetReward(getGadget(OutfitRaveSuitChestplate.class), rarity, 30); + addGadgetReward(getGadget(OutfitRaveSuitLeggings.class), rarity, 30); + addGadgetReward(getGadget(OutfitRaveSuitHelmet.class), rarity, 30); + addGadgetReward(getGadget(OutfitSpaceSuitBoots.class), rarity, 50); + addGadgetReward(getGadget(OutfitSpaceSuitChestplate.class), rarity, 50); + addGadgetReward(getGadget(OutfitSpaceSuitLeggings.class), rarity, 50); + addGadgetReward(getGadget(OutfitSpaceSuitHelmet.class), rarity, 50); + addGadgetReward(getGadget(OutfitStPatricksChestplate.class), rarity, 50); + addGadgetReward(getGadget(OutfitStPatricksLeggings.class), rarity, 50); + addGadgetReward(getGadget(OutfitStPatricksBoots.class), rarity, 50); + addGadgetReward(getGadget(OutfitFreezeSuitChestplate.class), rarity, 50); + addGadgetReward(getGadget(OutfitFreezeSuitLeggings.class), rarity, 50); + addGadgetReward(getGadget(OutfitFreezeSuitBoots.class), rarity, 50); + + addGadgetReward(getGadget(ParticleCandyCane.class), rarity, 20); + addGadgetReward(getGadget(ParticleChristmasTree.class), rarity, 40); + + addBalloonReward(BalloonType.BABY_ZOMBIE, rarity, 25, 500); + addBalloonReward(BalloonType.BABY_MUSHROOM, rarity, 50, 500); + addBalloonReward(BalloonType.BABY_OCELOT, rarity, 50, 500); + addBalloonReward(BalloonType.BABY_WOLF, rarity, 75, 500); + addBalloonReward(BalloonType.BABY_VILLAGER, rarity, 25, 500); + addBalloonReward(BalloonType.BABY_SLIME, rarity, 25, 500); + addBalloonReward(BalloonType.BAT, rarity, 50, 500); + + addGadgetReward(getGadget(HaloKitSelector.class), rarity, 100); + addGadgetReward(getGadget(RainbowDanceKitSelector.class), rarity, 100); + addGadgetReward(getGadget(ShimmeringRingKitSelector.class), rarity, 100); + addGadgetReward(getKitSelector(SingleParticleSelectors.FLAMES_OF_FURY), rarity, 100); + } + + @Override + protected void addLegendary(RewardRarity rarity) + { + addTitleReward("ayyye", rarity, 25, 500); + addTitleReward("ameno", rarity, 15, 5000); + addTitleReward("magician", rarity, 25, 5000); + addTitleReward("fireball", rarity, 75, 5000); + addTitleReward("magic-missile", rarity, 75, 5000); + addTitleReward("pewpewpew", rarity, 75, 5000); + addTitleReward("stardust", rarity, 60, 5000); + addTitleReward("blow-a-kiss", rarity, 60, 5000); + addTitleReward("cool-guy", rarity, 60, 5000); + addTitleReward("deal-with-it", rarity, 60, 5000); + addTitleReward("party-time", rarity, 55, 5000); + addTitleReward("lalala", rarity, 30, 5000); + addTitleReward("gotta-go", rarity, 30, 5000); + addTitleReward("whaaat", rarity, 30, 5000); + + addPetReward(PetType.VILLAGER, rarity, 1); + addPetReward(PetType.ZOMBIE, rarity, 10); + addPetReward(PetType.PIG_ZOMBIE, rarity, 1); + addPetReward(PetType.BLAZE, rarity, 2); + addPetReward(PetType.RABBIT, rarity, 10); + addPetReward(PetType.KILLER_BUNNY, rarity, 3); + addPetReward(PetType.CUPID_PET, rarity, 40); + addPetReward(PetType.LEPRECHAUN, rarity, 8); + + addGadgetReward(getGadget(MorphBunny.class), rarity, 1); + addGadgetReward(getGadget(MorphUncleSam.class), rarity, 5); + addGadgetReward(getGadget(MorphPumpkinKing.class), rarity, 1); + addGadgetReward(getGadget(MorphBat.class), rarity, 25); + addGadgetReward(getGadget(MorphSlime.class), rarity, 10); + addGadgetReward(getGadget(MorphBlock.class), rarity, 20); + addGadgetReward(getGadget(MorphSnowman.class), rarity, 10); + addGadgetReward(getGadget(MorphGrimReaper.class), rarity, 25); + addGadgetReward(getGadget(MorphAwkwardRabbit.class), rarity, 30); + addGadgetReward(getGadget(MorphLoveDoctor.class), rarity, 40); + + addGadgetReward(getGadget(ParticleFreedom.class), rarity, 15); + addGadgetReward(getGadget(ParticleWingsAngel.class), rarity, 15); + addGadgetReward(getGadget(ParticleBlood.class), rarity, 10); + addGadgetReward(getGadget(ParticleWingsDemons.class), rarity, 15); + addGadgetReward(getGadget(ParticleEnchant.class), rarity, 25); + addGadgetReward(getGadget(ParticleFairy.class), rarity, 4); + addGadgetReward(getGadget(ParticleFireRings.class), rarity, 17); + addGadgetReward(getGadget(ParticleEmerald.class), rarity, 8); + addGadgetReward(getGadget(ParticleHeart.class), rarity, 2); + addGadgetReward(getGadget(ParticleWingsInfernal.class), rarity, 4); + addGadgetReward(getGadget(ParticleMusic.class), rarity, 15); + addGadgetReward(getGadget(ParticleWingsPixie.class), rarity, 4); + addGadgetReward(getGadget(ParticleRain.class), rarity, 13); + addGadgetReward(getGadget(ParticleFoot.class), rarity, 33); + addGadgetReward(getGadget(ParticleYinYang.class), rarity, 20); + addGadgetReward(getGadget(ParticleCoalFumes.class), rarity, 1); + addGadgetReward(getGadget(ParticleFrostLord.class), rarity, 10); + addGadgetReward(getGadget(ParticlePartyTime.class), rarity, 25); + addGadgetReward(getGadget(ParticleSpringHalo.class), rarity, 8); + addGadgetReward(getGadget(ParticleWingsLove.class), rarity, 10); + addGadgetReward(getGadget(ParticleFreedomFireworks.class), rarity, 24); + addGadgetReward(getGadget(ParticleAuraNiceness.class), rarity, 4); + addGadgetReward(getGadget(ParticleCanadian.class), rarity, 1); + addGadgetReward(getGadget(ParticleStarSpangled.class), rarity, 1); + + addGadgetReward(getGadget(MountFreedomHorse.class), rarity, 5); + addGadgetReward(getGadget(MountZombie.class), rarity, 1); + addGadgetReward(getGadget(MountSpider.class), rarity, 1); + addGadgetReward(getGadget(MountUndead.class), rarity, 1); + addGadgetReward(getGadget(MountValentinesSheep.class), rarity, 20); + addGadgetReward(getGadget(MountBabyReindeer.class), rarity, 1); + addGadgetReward(getGadget(MountNightmareSteed.class), rarity, 10); + addGadgetReward(getGadget(MountChicken.class), rarity, 5); + addGadgetReward(getGadget(MountCake.class), rarity, 10); + addGadgetReward(getGadget(MountStPatricksHorse.class), rarity, 3); + + addGadgetReward(getGadget(WinEffectBabyChicken.class), rarity, 10); + addGadgetReward(getGadget(WinEffectLavaTrap.class), rarity, 20); + addGadgetReward(getGadget(WinEffectRiseOfTheElderGuardian.class), rarity, 4); + addGadgetReward(getGadget(WinEffectLightningStrike.class), rarity, 20); + addGadgetReward(getGadget(WinEffectMrPunchMan.class), rarity, 33); + addGadgetReward(getGadget(WinEffectHalloween.class), rarity, 75); + + addGadgetReward(getGadget(DeathEnchant.class), rarity, 10); + addGadgetReward(getGadget(DeathCupidsBrokenHeart.class), rarity, 25); + addGadgetReward(getGadget(DeathFrostLord.class), rarity, 15); + addGadgetReward(getGadget(DeathPresentDanger.class), rarity, 27); + + addGadgetReward(getGadget(DoubleJumpEnchant.class), rarity, 10); + addGadgetReward(getGadget(DoubleJumpCupidsWings.class), rarity, 5); + addGadgetReward(getGadget(DoubleJumpFrostLord.class), rarity, 10); + + addGadgetReward(getGadget(ArrowTrailEnchant.class), rarity, 10); + addGadgetReward(getGadget(ArrowTrailFrostLord.class), rarity, 20); + addGadgetReward(getGadget(ArrowTrailCupid.class), rarity, 15); + + addHatReward(HatType.GRINCH, rarity, 25); + + addGadgetReward(getGadget(OutfitStPatricksHat.class), rarity, 5); + addGadgetReward(getGadget(OutfitFreezeSuitHelmet.class), rarity, 2); + + addBalloonReward(BalloonType.SQUID, rarity, 10, 5000); + addBalloonReward(BalloonType.SILVERFISH, rarity, 30, 5000); + addBalloonReward(BalloonType.GUARDIAN, rarity, 30, 5000); + addBalloonReward(BalloonType.EMERALD_BLOCK, rarity, 15, 5000); + + addGadgetReward(getGadget(BlowAKissTaunt.class), rarity, 7); + addGadgetReward(getGadget(RainbowTaunt.class), rarity, 1); + } + + @Override + protected void addMythical(RewardRarity rarity) + { + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/Treasure.java new file mode 100644 index 000000000..0e1c35949 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/Treasure.java @@ -0,0 +1,316 @@ +package mineplex.core.treasure.types; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +import org.bukkit.inventory.ItemStack; + +import com.google.common.collect.ImmutableMap; + +import mineplex.core.Managers; +import mineplex.core.common.util.C; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.gadgets.balloons.BalloonType; +import mineplex.core.gadget.gadgets.hat.HatType; +import mineplex.core.gadget.gadgets.kitselector.SingleParticleKitSelector; +import mineplex.core.gadget.types.Gadget; +import mineplex.core.gadget.types.GadgetType; +import mineplex.core.gadget.types.ItemGadget; +import mineplex.core.pet.PetType; +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardType; +import mineplex.core.reward.rewards.GadgetReward; +import mineplex.core.reward.rewards.InventoryReward; +import mineplex.core.reward.rewards.PetReward; +import mineplex.core.reward.rewards.RankReward; +import mineplex.core.reward.rewards.TitleReward; +import mineplex.core.titles.tracks.TrackManager; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.animation.TreasureAnimation; +import mineplex.core.treasure.reward.RewardRarity; +import mineplex.core.treasure.reward.TreasureRewardManager; + +/** + * + */ +public class Treasure +{ + + private static final String PURCHASABLE_FROM_STORE = "Purchase at mineplex.com/shop"; + private static final Map SHARD_WORTH = ImmutableMap.builder() + .put(RewardRarity.UNCOMMON, 100) + .put(RewardRarity.RARE, 500) + .put(RewardRarity.LEGENDARY, 5000) + .build(); + + private static final TreasureRewardManager TREASURE_REWARD_MANAGER = Managers.require(TreasureRewardManager.class); + + public static TreasureRewardManager getRewardManager() + { + return TREASURE_REWARD_MANAGER; + } + + protected static final GadgetManager GADGET_MANAGER = Managers.require(GadgetManager.class); + private static final TrackManager TRACK_MANAGER = Managers.require(TrackManager.class); + + private final TreasureType _treasureType; + private final List _purchaseMethods; + + private RewardType _rewardType; + private Function _animationFunction; + + private boolean _duplicates; + private int _rewardsPerChest; + private boolean _purchasable; + private int _purchasePrice; + private boolean _enabledDefault; + + Treasure(TreasureType treasureType) + { + _treasureType = treasureType; + _purchaseMethods = new ArrayList<>(2); + + addCommon(RewardRarity.COMMON); + addUncommon(RewardRarity.UNCOMMON); + addRare(RewardRarity.RARE); + addLegendary(RewardRarity.LEGENDARY); + addMythical(RewardRarity.MYTHICAL); + } + + protected void addCommon(RewardRarity rarity) + { + } + + protected void addUncommon(RewardRarity rarity) + { + } + + protected void addRare(RewardRarity rarity) + { + } + + protected void addLegendary(RewardRarity rarity) + { + } + + protected void addMythical(RewardRarity rarity) + { + } + + public TreasureType getTreasureType() + { + return _treasureType; + } + + public RewardType getRewardType() + { + return _rewardType; + } + + public void allowDuplicates() + { + _duplicates = true; + } + + public boolean isDuplicates() + { + return _duplicates; + } + + public void setRewardsPerChest(int rewardsPerChest) + { + _rewardsPerChest = rewardsPerChest; + } + + public int getRewardsPerChest() + { + return _rewardsPerChest; + } + + protected void purchasableFromStore() + { + addPurchaseMethod(PURCHASABLE_FROM_STORE); + } + + protected void addPurchaseMethod(String method) + { + _purchaseMethods.add(C.cBlue + method); + } + + protected void setRewards(RewardType rewardType) + { + _rewardType = rewardType; + } + + protected void setAnimation(Function animations) + { + _animationFunction = animations; + } + + public TreasureAnimation getAnimations(TreasureLocation location) + { + return _animationFunction.apply(location); + } + + public boolean hasAnimations() + { + return _animationFunction != null; + } + + public boolean isPurchasable() + { + return _purchasable; + } + + public int getPurchasePrice() + { + return _purchasePrice; + } + + public void setPurchasable(boolean purchasable) + { + _purchasable = purchasable; + } + + protected void setPurchasable(int purchasePrice) + { + _purchasable = true; + _purchasePrice = purchasePrice; + + addPurchaseMethod("Craftable for " + C.cAqua + _purchasePrice + " Treasure Shards"); + } + + public List getPurchaseMethods() + { + return _purchaseMethods; + } + + protected void enabledByDefault() + { + _enabledDefault = true; + } + + protected final T getGadget(Class clazz) + { + return GADGET_MANAGER.getGadget(clazz); + } + + protected final InventoryReward addGadgetReward(ItemGadget gadget, RewardRarity rarity, int weight, int minAmmo, int maxAmmo) + { + return addGadgetReward(gadget, rarity, weight, getShards(rarity), minAmmo, maxAmmo); + } + + protected final InventoryReward addGadgetReward(ItemGadget gadget, RewardRarity rarity, int weight, int shards, int minAmmo, int maxAmmo) + { + InventoryReward reward = new InventoryReward( + gadget.getDisplayName(), + gadget.getName(), + "Gadget", + minAmmo, + maxAmmo, + new ItemStack(gadget.getDisplayMaterial(), 1, (short) 0, gadget.getDisplayData()), + rarity, + shards + ); + addReward(reward, weight); + return reward; + } + + protected final GadgetReward addGadgetReward(Gadget gadget, RewardRarity rarity, int weight) + { + return addGadgetReward(gadget, rarity, weight, getShards(rarity)); + } + + protected final GadgetReward addGadgetReward(Gadget gadget, RewardRarity rarity, int weight, int shards) + { + GadgetReward reward = new GadgetReward(gadget, rarity, shards); + addReward(reward, weight); + return reward; + } + + protected PetReward addPetReward(PetType petType, RewardRarity rarity, int weight) + { + return addPetReward(petType, rarity, weight, getShards(rarity)); + } + + protected PetReward addPetReward(PetType petType, RewardRarity rarity, int weight, int shards) + { + PetReward reward = new PetReward(petType.getName(), petType, rarity, shards); + addReward(reward, weight); + return reward; + } + + protected GadgetReward addMusicReward(String disc, RewardRarity rarity, int weight) + { + return addMusicReward(disc, rarity, weight, getShards(rarity)); + } + + protected GadgetReward addMusicReward(String disc, RewardRarity rarity, int weight, int shards) + { + for (Gadget gadget : GADGET_MANAGER.getGadgets(GadgetType.MUSIC_DISC)) + { + if (gadget.getName().equals(disc + " Disc")) + { + return addGadgetReward(gadget, rarity, weight, shards); + } + } + + return null; + } + + protected GadgetReward addBalloonReward(BalloonType type, RewardRarity rarity, int weight) + { + return addBalloonReward(type, rarity, weight, getShards(rarity)); + } + + protected GadgetReward addBalloonReward(BalloonType type, RewardRarity rarity, int weight, int shards) + { + return addGadgetReward(GADGET_MANAGER.getBalloonGadget(type), rarity, weight, shards); + } + + protected TitleReward addTitleReward(String id, RewardRarity rarity, int weight) + { + return addTitleReward(id, rarity, weight, getShards(rarity)); + } + + protected TitleReward addTitleReward(String id, RewardRarity rarity, int weight, int shards) + { + TitleReward reward = new TitleReward(TRACK_MANAGER.getTrackById(id), rarity, shards); + addReward(reward, weight); + return reward; + } + + protected RankReward addRankReward(RewardRarity rarity, boolean canPassLegend, int weight) + { + RankReward reward = new RankReward(rarity, 0, canPassLegend); + addReward(reward, weight); + return reward; + } + + protected GadgetReward addHatReward(HatType type, RewardRarity rarity, int weight) + { + return addHatReward(type, rarity, weight, getShards(rarity)); + } + + protected GadgetReward addHatReward(HatType type, RewardRarity rarity, int weight, int shards) + { + return addGadgetReward(GADGET_MANAGER.getHatGadget(type), rarity, weight, shards); + } + + protected SingleParticleKitSelector getKitSelector(SingleParticleKitSelector.SingleParticleSelectors singleParticleSelectors) + { + return GADGET_MANAGER.getSingleParticleKitSelector(singleParticleSelectors); + } + + protected int getShards(RewardRarity rarity) + { + return SHARD_WORTH.getOrDefault(rarity, 0); + } + + protected void addReward(Reward reward, int weight) + { + TREASURE_REWARD_MANAGER.addReward(this, reward, weight); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/TreasureType.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/TreasureType.java new file mode 100644 index 000000000..d5a2415f6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/TreasureType.java @@ -0,0 +1,136 @@ +package mineplex.core.treasure.types; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.skin.SkinData; +import mineplex.core.common.util.C; + +public enum TreasureType +{ + + OLD( + C.cYellow + "Old Treasure", + "Old Chest", + "Old", + new ItemStack(Material.CHEST), + "We've scoured the lands of Minecraft", + "and found these abandoned chests.", + "The contents are unknown, but", + "according to the inscriptions on the", + "the straps they appear to contain", + "many kinds of loot." + ), + ANCIENT( + C.cGold + "Ancient Treasure", + "Ancient Chest", + "Ancient", + new ItemStack(Material.TRAPPED_CHEST), + "Some of our bravest adventurers", + "have discovered these chests within ", + "temples hidden in Minecrafts worlds." + ), + MYTHICAL( + C.cRed + "Mythical Treasure", + "Mythical Chest", + "Mythical", + new ItemStack(Material.ENDER_CHEST), + "All our previous adventurers have", + "perished in search of these chests.", + "However, legends of their existence", + "convinced Sterling, Chiss and Defek7", + "to venture out and discover the", + "location of these chests on their own." + ), + ILLUMINATED( + C.cAqua + "Illuminated Treasure", + "Illuminated Chest", + "Illuminated", + new ItemStack(Material.SEA_LANTERN), + "The illuminated chest shines brightly", + "in the depths, always bringing a new", + "treasure from the darkness." + ), + OMEGA( + C.cAqua + "Omega Chest", + "Omega Chest", + "Omega", + SkinData.OMEGA_CHEST.getSkull(), + "The most powerful of all chests,", + "it is able to go back in time to find", + "loot that has been lost..." + ), + MINESTRIKE( + C.cGold + "MineStrike Treasure", + "Minestrike Chest", + "MinestrikeChest", + new ItemStack(Material.TNT), + "The Minestrike Chest is the only place to get", + "the unique skins for Minestrike weapons!" + ), + MOBA( + C.cAqua + "GWEN's Treasure", + "HOG Chest", + "HOGChest", + new ItemStack(Material.PRISMARINE), + "Heroes of GWEN exclusive cosmetics!", + "Each chest contains 4 exclusive items to the game!" + ), + TRICK_OR_TREAT( + C.cGold + "Trick or Treat Bag", + "Trick or Treat Chest", + "TrickOrTreat", + new ItemStack(Material.JACK_O_LANTERN), + "It's that time of year again!", + "Where the ghosts and ghouls roam", + "free! Hahahaha" + ), + CARL_SPINNER(), + GAME_LOOT(), + ; + + private final String _name; + private final String _itemName; + private final String _statName; + private final ItemStack _itemStack; + private final String[] _description; + + TreasureType() + { + this(null, null, null, null); + } + + TreasureType(String name, String itemName, String statName, ItemStack itemStack, String... description) + { + _name = name; + _itemName = itemName; + _statName = statName; + _itemStack = itemStack; + _description = description; + } + + public String getName() + { + return _name; + } + + public String getItemName() + { + return _itemName; + } + + public String getStatName() + { + return _statName; + } + + public ItemStack getItemStack() + { + return _itemStack; + } + + public String[] getDescription() + { + return _description; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/TrickOrTreatTreasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/TrickOrTreatTreasure.java new file mode 100644 index 000000000..7d9eb55c3 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/types/TrickOrTreatTreasure.java @@ -0,0 +1,65 @@ +package mineplex.core.treasure.types; + +import mineplex.core.gadget.gadgets.arrowtrail.ArrowTrailHalloween; +import mineplex.core.gadget.gadgets.death.DeathHalloween; +import mineplex.core.gadget.gadgets.doublejump.DoubleJumpHalloween; +import mineplex.core.gadget.gadgets.item.ItemCandy; +import mineplex.core.gadget.gadgets.kitselector.HalloweenKitSelector; +import mineplex.core.gadget.gadgets.kitselector.SingleParticleKitSelector.SingleParticleSelectors; +import mineplex.core.gadget.gadgets.morph.MorphGrimReaper; +import mineplex.core.gadget.gadgets.mount.types.MountNightmareSteed; +import mineplex.core.gadget.gadgets.particle.ParticleHalloween; +import mineplex.core.gadget.gadgets.taunts.InfernalTaunt; +import mineplex.core.gadget.gadgets.wineffect.WinEffectHalloween; +import mineplex.core.pet.PetType; +import mineplex.core.reward.RewardType; +import mineplex.core.treasure.animation.animations.TrickOrTreatChestAnimation; +import mineplex.core.treasure.reward.RewardRarity; + +public class TrickOrTreatTreasure extends Treasure +{ + + public TrickOrTreatTreasure() + { + super(TreasureType.TRICK_OR_TREAT); + + setAnimation(treasureLocation -> new TrickOrTreatChestAnimation(this, treasureLocation)); + setRewards(RewardType.TRICK_OR_TREAT_CHEST); + setRewardsPerChest(1); + setPurchasable(20000); + purchasableFromStore(); + enabledByDefault(); + } + + @Override + protected void addUncommon(RewardRarity rarity) + { + addGadgetReward(getGadget(ItemCandy.class), rarity, 10, 5, 10); + } + + @Override + protected void addRare(RewardRarity rarity) + { + addGadgetReward(getGadget(ArrowTrailHalloween.class), rarity, 10); + addGadgetReward(getGadget(DeathHalloween.class), rarity, 10); + addGadgetReward(getGadget(DoubleJumpHalloween.class), rarity, 10); + addGadgetReward(getGadget(HalloweenKitSelector.class), rarity, 10); + addPetReward(PetType.BLAZE, rarity, 10); + addPetReward(PetType.ZOMBIE, rarity, 10); + } + + @Override + protected void addLegendary(RewardRarity rarity) + { + addGadgetReward(getGadget(ParticleHalloween.class), rarity, 10); + addGadgetReward(getGadget(InfernalTaunt.class), rarity, 10); + addGadgetReward(getGadget(MorphGrimReaper.class), rarity, 10); + addGadgetReward(getGadget(WinEffectHalloween.class), rarity, 10); + addGadgetReward(getGadget(MountNightmareSteed.class), rarity, 10); + } + + @Override + protected void addMythical(RewardRarity rarity) + { + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/ui/PurchaseTreasurePage.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/ui/PurchaseTreasurePage.java new file mode 100644 index 000000000..991260ae7 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/ui/PurchaseTreasurePage.java @@ -0,0 +1,150 @@ +package mineplex.core.treasure.ui; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.confirmation.ConfirmationPage; +import mineplex.core.shop.item.IButton; +import mineplex.core.shop.item.SalesPackageBase; +import mineplex.core.shop.item.SalesPackageProcessor; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.core.treasure.ChestPackage; +import mineplex.core.treasure.TreasureManager; +import mineplex.core.treasure.types.Treasure; + +public class PurchaseTreasurePage extends ShopPageBase +{ + + private static final ItemStack GO_BACK = new ItemBuilder(Material.BED) + .setTitle(C.cGreen + "Go Back") + .build(); + private static final ItemStack NO_REWARDS = new ItemBuilder(Material.REDSTONE_BLOCK) + .setTitle(C.cRedB + "No Rewards") + .addLore("", "You already own all of the items that", "can appear in this chest.", "Thus you cannot purchase this chest anymore.") + .build(); + + private final Treasure _treasure; + private final TreasurePage _previous; + private final int _available; + + PurchaseTreasurePage(TreasureManager plugin, TreasureShop shop, Player player, Treasure treasure, TreasurePage previous) + { + super(plugin, shop, plugin.getClientManager(), plugin.getDonationManager(), "Purchase " + treasure.getTreasureType().getName(), player); + + _treasure = treasure; + _previous = previous; + _available = treasure.isDuplicates() + ? Integer.MAX_VALUE + : plugin.getRewardManager().getTotalItems(treasure) - plugin.getRewardManager().getOwnedItems(player, treasure) - plugin.getChestsToOpen(player, treasure); + + buildPage(); + } + + @Override + protected void buildPage() + { + addButton(4, GO_BACK, (player, clickType) -> getShop().openPageForPlayer(player, _previous)); + + int purchaseAmount = 1; + + if (addButton(20, purchaseAmount)) + { + addButtonNoAction(22, NO_REWARDS); + removeButton(20); + return; + } + + purchaseAmount = 5; + + if (addButton(22, purchaseAmount)) + { + return; + } + + purchaseAmount = 10; + + addButton(24, purchaseAmount); + } + + private boolean addButton(int slot, int purchaseAmount) + { + boolean overflow = false; + + if (purchaseAmount > _available) + { + purchaseAmount = _available; + overflow = true; + } + + addButton(slot, getPurchaseItem(purchaseAmount), new PurchaseChestButton(purchaseAmount)); + return overflow; + } + + private ItemStack getPurchaseItem(int amount) + { + ItemStack itemStack = _treasure.getTreasureType().getItemStack().clone(); + ItemMeta meta = itemStack.getItemMeta(); + List lore = new ArrayList<>(); + + lore.add(""); + lore.add(C.cGray + (amount == 1 ? "Buy" : "Bulk buy") + " " + F.elem(amount) + " chest" + (amount == 1 ? "" : "s") + "."); + lore.add(C.cGray + "This will cost " + F.currency(GlobalCurrency.TREASURE_SHARD, _treasure.getPurchasePrice() * amount) + "!"); + lore.add(""); + lore.add(C.cGreen + "Click to purchase!"); + + meta.setDisplayName(_treasure.getTreasureType().getName()); + meta.setLore(lore); + itemStack.setItemMeta(meta); + itemStack.setAmount(amount); + + return itemStack; + } + + private class PurchaseChestButton implements IButton + { + + private final int _amount; + + PurchaseChestButton(int amount) + { + _amount = amount; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + getPlugin().purchase(newAmount -> + { + SalesPackageBase salesPackage = new ChestPackage(_treasure.getTreasureType().getItemName(), Material.CHEST, _treasure.getPurchasePrice() * newAmount); + + getShop().openPageForPlayer( + player, + new ConfirmationPage<>( + player, + _previous, + new SalesPackageProcessor( + player, + GlobalCurrency.TREASURE_SHARD, + salesPackage, + getDonationManager(), + () -> + { + getPlugin().giveTreasure(player, _treasure, newAmount); + _previous.buildPage(); + player.sendMessage(F.main(getPlugin().getName(), "Purchased " + F.elem(newAmount) + " " + F.name(_treasure.getTreasureType().getName()) + ".")); + }), + salesPackage.buildIcon())); + }, player, _treasure, _amount); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/ui/TreasurePage.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/ui/TreasurePage.java new file mode 100644 index 000000000..50d9eb917 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/ui/TreasurePage.java @@ -0,0 +1,136 @@ +package mineplex.core.treasure.ui; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilUI; +import mineplex.core.shop.item.IButton; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.TreasureManager; +import mineplex.core.treasure.reward.TreasureRewardManager; +import mineplex.core.treasure.types.Treasure; + +public class TreasurePage extends ShopPageBase +{ + + private final TreasureLocation _treasureLocation; + + TreasurePage(TreasureManager plugin, TreasureShop shop, Player player, TreasureLocation treasureLocation) + { + super(plugin, shop, plugin.getClientManager(), plugin.getDonationManager(), "Treasure Chest", player); + + _treasureLocation = treasureLocation; + + buildPage(); + } + + @Override + protected void buildPage() + { + List treasures = _treasureLocation.getManager().getTreasures(); + int[] slots = UtilUI.getIndicesFor(treasures.size(), 2, 5, 1); + int index = 0; + + for (Treasure treasure : _treasureLocation.getManager().getTreasures()) + { + addButton(slots[index++], prettifyItem(getPlayer(), treasure), new TreasureButton(treasure)); + } + } + + private ItemStack prettifyItem(Player player, Treasure treasure) + { + int toOpen = _treasureLocation.getManager().getChestsToOpen(player, treasure); + boolean canOpen = toOpen > 0; + ItemStack itemStack = treasure.getTreasureType().getItemStack().clone(); + ItemMeta meta = itemStack.getItemMeta(); + List lore = new ArrayList<>(); + + lore.add(""); + lore.add(C.cGray + ChatColor.stripColor(treasure.getTreasureType().getName()) + "s Owned: " + F.elem(toOpen)); + lore.add(""); + + for (String description : treasure.getTreasureType().getDescription()) + { + lore.add(C.cGray + description); + } + + if (treasure.isPurchasable()) + { + lore.add(""); + lore.addAll(treasure.getPurchaseMethods()); + } + + if (!treasure.isDuplicates()) + { + TreasureRewardManager rewardManager = _treasureLocation.getManager().getRewardManager(); + int total = rewardManager.getTotalItems(treasure); + int available = total - rewardManager.getOwnedItems(player, treasure); + + lore.add(""); + lore.add(C.cGray + "Available Items: " + F.elem(available) + "/" + F.elem(total)); + } + + if (canOpen) + { + lore.add(""); + lore.add(C.cGreen + "Left-Click to open!"); + } + if (treasure.isPurchasable()) + { + if (!canOpen) + { + lore.add(""); + } + + lore.add(C.cGreen + "Right-Click to purchase!"); + } + + meta.setDisplayName(treasure.getTreasureType().getName()); + meta.setLore(lore); + itemStack.setItemMeta(meta); + + return itemStack; + } + + private class TreasureButton implements IButton + { + + private final Treasure _treasure; + + TreasureButton(Treasure treasure) + { + _treasure = treasure; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + // Open + if (clickType.isLeftClick()) + { + if (_treasureLocation.openChest(player, _treasure)) + { + playAcceptSound(player); + } + else + { + playDenySound(player); + } + } + // Purchase + else if (_treasure.isPurchasable()) + { + getShop().openPageForPlayer(player, new PurchaseTreasurePage(getPlugin(), getShop(), getPlayer(), _treasure, TreasurePage.this)); + } + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/ui/TreasureShop.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/ui/TreasureShop.java new file mode 100644 index 000000000..59a67019f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/ui/TreasureShop.java @@ -0,0 +1,29 @@ +package mineplex.core.treasure.ui; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.TreasureManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; + +public class TreasureShop extends ShopBase +{ + + private final TreasureLocation _treasureLocation; + + public TreasureShop(TreasureManager plugin, CoreClientManager clientManager, DonationManager donationManager, TreasureLocation treasureLocation) + { + super(plugin, clientManager, donationManager, "Treasure Chest"); + + _treasureLocation = treasureLocation; + } + + @Override + protected ShopPageBase> buildPagesFor(Player player) + { + return new TreasurePage(getPlugin(), this, player, _treasureLocation); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/util/TreasureUtil.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/util/TreasureUtil.java new file mode 100644 index 000000000..b3adf9382 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/util/TreasureUtil.java @@ -0,0 +1,61 @@ +package mineplex.core.treasure.util; + +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.TileEntity; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Location; +import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; + +import mineplex.core.common.util.UtilBlock; + +public class TreasureUtil +{ + + public static void playChestOpen(Location location, boolean open) + { + World world = ((CraftWorld) location.getWorld()).getHandle(); + BlockPosition position = new BlockPosition(location.getX(), location.getY(), location.getZ()); + TileEntity tileEntity = world.getTileEntity(position); + world.playBlockAction(position, tileEntity.w(), 1, open ? 1 : 0); + } + + public static byte getChestFacing(float yaw) + { + BlockFace face = UtilBlock.getFace(yaw); + + switch (face) + { + case NORTH: + return 3; + case SOUTH: + return 2; + case WEST: + return 5; + case EAST: + return 4; + } + + return 0; + } + + public static byte getPumpkinFacing(float yaw) + { + BlockFace face = UtilBlock.getFace(yaw); + + switch (face) + { + case NORTH: + return 0; + case SOUTH: + return 2; + case WEST: + return 3; + case EAST: + return 1; + } + + return 0; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/valentines/ValentinesGiftManager.java b/Plugins/Mineplex.Core/src/mineplex/core/valentines/ValentinesGiftManager.java index 042c141a0..132922b83 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/valentines/ValentinesGiftManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/valentines/ValentinesGiftManager.java @@ -18,10 +18,9 @@ import mineplex.core.gadget.GadgetManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.reward.RewardData; -import mineplex.core.reward.RewardManager; -import mineplex.core.reward.RewardPool; import mineplex.core.reward.RewardType; import mineplex.core.stats.StatsManager; +import mineplex.core.treasure.reward.TreasureRewardManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.valentines.event.AttemptGiftEvent; @@ -33,7 +32,7 @@ public class ValentinesGiftManager extends MiniPlugin private final Material ITEM_MATERIAL = Material.RED_ROSE; private CoreClientManager _clientManager; - private RewardManager _rewardManager; + private TreasureRewardManager _rewardManager; private InventoryManager _inventoryManager; private GadgetManager _gadgetManager; private StatsManager _statsManager; @@ -41,7 +40,7 @@ public class ValentinesGiftManager extends MiniPlugin private ValentinesGiftRepository _repository; private LinkedList _effects; - public ValentinesGiftManager(JavaPlugin plugin, CoreClientManager clientManager, RewardManager rewardManager, InventoryManager inventoryManager, GadgetManager gadgetManager, StatsManager statsManager) + public ValentinesGiftManager(JavaPlugin plugin, CoreClientManager clientManager, TreasureRewardManager rewardManager, InventoryManager inventoryManager, GadgetManager gadgetManager, StatsManager statsManager) { super("Valentines", plugin); @@ -76,49 +75,49 @@ public class ValentinesGiftManager extends MiniPlugin */ private void giveGift(Player from, Player to, boolean success) { - if (success) - { - _inventoryManager.addItemToInventory(new Callback() - { - @Override - public void run(Boolean data) - { - if (data) - { - _rewardManager.nextReward(to, RewardPool.Type.VALENTINES_GIFT, null, false, RewardType.VALENTINES_GIFT, false).giveReward(RewardType.VALENTINES_GIFT, to, new Callback() - { - @Override - public void run(RewardData toData) - { - String toGift = ChatColor.stripColor(toData.getFriendlyName()); - - _rewardManager.nextReward(from, RewardPool.Type.VALENTINES_GIFT, null, false, RewardType.VALENTINES_GIFT, false).giveReward(RewardType.VALENTINES_GIFT, from, new Callback() - { - @Override - public void run(RewardData fromData) - { - String fromGift = ChatColor.stripColor(fromData.getFriendlyName()); - _effects.add(new GiftEffect(from, to, fromGift, toGift, UtilAlg.getMidpoint(to.getLocation(), from.getLocation()))); - - incrementStat(from, to); - } - }); - } - }); - - from.getInventory().setItem(_gadgetManager.getActiveItemSlot(), ItemStackFactory.Instance.CreateStack(ITEM_MATERIAL, (byte) 0, 1, F.item(_inventoryManager.Get(from).getItemCount(ITEM_NAME) + " " + ITEM_NAME))); - } - else - { - UtilPlayer.message(from, F.main("Gift", "Error giving gift! Please try again")); - } - } - }, from, ITEM_NAME, -1); - } - else - { - UtilPlayer.message(from, F.main("Gift", "Spread the love! You have already gifted " + F.name(to.getName()))); - } +// if (success) +// { +// _inventoryManager.addItemToInventory(new Callback() +// { +// @Override +// public void run(Boolean data) +// { +// if (data) +// { +// _rewardManager.nextReward(to, RewardPool.Type.VALENTINES_GIFT, null, false, RewardType.VALENTINES_GIFT, false).giveReward(RewardType.VALENTINES_GIFT, to, new Callback() +// { +// @Override +// public void run(RewardData toData) +// { +// String toGift = ChatColor.stripColor(toData.getFriendlyName()); +// +// _rewardManager.nextReward(from, RewardPool.Type.VALENTINES_GIFT, null, false, RewardType.VALENTINES_GIFT, false).giveReward(RewardType.VALENTINES_GIFT, from, new Callback() +// { +// @Override +// public void run(RewardData fromData) +// { +// String fromGift = ChatColor.stripColor(fromData.getFriendlyName()); +// _effects.add(new GiftEffect(from, to, fromGift, toGift, UtilAlg.getMidpoint(to.getLocation(), from.getLocation()))); +// +// incrementStat(from, to); +// } +// }); +// } +// }); +// +// from.getInventory().setItem(_gadgetManager.getActiveItemSlot(), ItemStackFactory.Instance.CreateStack(ITEM_MATERIAL, (byte) 0, 1, F.item(_inventoryManager.Get(from).getItemCount(ITEM_NAME) + " " + ITEM_NAME))); +// } +// else +// { +// UtilPlayer.message(from, F.main("Gift", "Error giving gift! Please try again")); +// } +// } +// }, from, ITEM_NAME, -1); +// } +// else +// { +// UtilPlayer.message(from, F.main("Gift", "Spread the love! You have already gifted " + F.name(to.getName()))); +// } } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/supplydrop/SupplyDrop.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/supplyDrop/SupplyDrop.java similarity index 100% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/supplydrop/SupplyDrop.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/supplyDrop/SupplyDrop.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/supplydrop/SupplyDropManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/supplyDrop/SupplyDropManager.java similarity index 100% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/supplydrop/SupplyDropManager.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/supplyDrop/SupplyDropManager.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/tntgenerator/TntGenerator.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/tntGenerator/TntGenerator.java similarity index 100% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/tntgenerator/TntGenerator.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/tntGenerator/TntGenerator.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/tntgenerator/TntGeneratorManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/tntGenerator/TntGeneratorManager.java similarity index 100% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/tntgenerator/TntGeneratorManager.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/tntGenerator/TntGeneratorManager.java diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java index 60788e367..4e600a733 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java @@ -27,7 +27,6 @@ import mineplex.core.elo.EloManager; import mineplex.core.friend.FriendManager; import mineplex.core.gadget.gadgets.particle.king.CastleManager; import mineplex.core.give.Give; -import mineplex.core.globalpacket.GlobalPacketManager; import mineplex.core.hologram.HologramManager; import mineplex.core.ignore.IgnoreManager; import mineplex.core.incognito.IncognitoManager; @@ -150,7 +149,7 @@ public class ClansHub extends JavaPlugin PartyManager partyManager = new PartyManager(); - CustomDataManager customDataManager = new CustomDataManager(this, clientManager); + CustomDataManager customDataManager = require(CustomDataManager.class); ConditionManager condition = new ConditionManager(this); ThankManager thankManager = new ThankManager(this, clientManager, donationManager); @@ -166,7 +165,6 @@ public class ClansHub extends JavaPlugin new CustomTagFix(this, packetHandler); new PacketsInteractionFix(this, packetHandler); new ResourcePackManager(this, portal); - new GlobalPacketManager(this, clientManager, serverStatusManager, inventoryManager, donationManager, petManager, statsManager, hubManager.getBonusManager().getRewardManager()); AprilFoolsManager.getInstance(); diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansTransferManager.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansTransferManager.java index d1a8d0495..79eeb1d44 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansTransferManager.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansTransferManager.java @@ -51,7 +51,7 @@ public class ClansTransferManager extends MiniDbClientPlugin ALLOW_HARDCORE, } - private static final int[] PERMITTED_VERSIONS = {ProtocolVersion.v1_8, ProtocolVersion.v1_12, ProtocolVersion.v1_12_1, ProtocolVersion.v1_12_2}; + private static final int[] PERMITTED_VERSIONS = {ProtocolVersion.v1_8, ProtocolVersion.v1_12, ProtocolVersion.v1_12_1}; private static final Map VERSION_NAMES = new HashMap<>(); static diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/HubManager.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/HubManager.java index 8e5f8b5ed..b42990ad2 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/HubManager.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/HubManager.java @@ -12,7 +12,6 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.entity.Egg; import org.bukkit.entity.Entity; @@ -78,7 +77,6 @@ import mineplex.core.facebook.FacebookManager; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.event.GadgetCollideEntityEvent; import mineplex.core.gadget.gadgets.morph.MorphWither; -import mineplex.core.gadget.gadgets.mount.Mount; import mineplex.core.gadget.gadgets.mount.types.MountDragon; import mineplex.core.gadget.gadgets.particle.king.CastleManager; import mineplex.core.gadget.types.Gadget; @@ -104,7 +102,6 @@ import mineplex.core.portal.Intent; import mineplex.core.portal.Portal; import mineplex.core.preferences.Preference; import mineplex.core.preferences.PreferencesManager; -import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; import mineplex.core.scoreboard.MineplexScoreboard; import mineplex.core.scoreboard.ScoreboardManager; @@ -113,12 +110,10 @@ import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; import mineplex.core.task.TaskManager; import mineplex.core.thank.ThankManager; -import mineplex.core.treasure.TreasureLocation; import mineplex.core.treasure.TreasureManager; import mineplex.core.twofactor.TwoFactorAuth; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.core.valentines.ValentinesGiftManager; import mineplex.core.youtube.YoutubeManager; import mineplex.minecraft.game.core.combat.DeathMessageType; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; @@ -201,7 +196,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter _inventoryManager = inventoryManager; new BenefitManager(plugin, clientManager, _inventoryManager); - _gadgetManager = new GadgetManager(clientManager, donationManager, _inventoryManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin), achievementManager, packetHandler, hologramManager, incognito, castleManager); + _gadgetManager = require(GadgetManager.class); FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager, inventoryManager); YoutubeManager youtubeManager = new YoutubeManager(plugin, clientManager, donationManager); @@ -209,34 +204,34 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter _bonusManager = new BonusManager(plugin, null, playWireManager, clientManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, facebookManager, youtubeManager, _gadgetManager, thankManager, "Carter"); World world = _spawn.getWorld(); - _treasureManager = new TreasureManager(_plugin, clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, _gadgetManager, _blockRestore, hologramManager, statsManager, _bonusManager.getRewardManager()); - _treasureManager.disable(); - { - Block chestBlock = world.getBlockAt(-1, 178, -9); - Block chestLoc1 = world.getBlockAt(-4, 178, -8); - Block chestLoc2 = world.getBlockAt(-4, 178, -10); - Block chestLoc3 = world.getBlockAt(-2, 178, -12); - Block chestLoc4 = world.getBlockAt(0, 178, -12); - Block chestLoc5 = world.getBlockAt(2, 178, -10); - Block chestLoc6 = world.getBlockAt(2, 178, -8); - Block chestLoc7 = world.getBlockAt(0, 178, -6); - Block chestLoc8 = world.getBlockAt(-2, 178, -6); - TreasureLocation loc = new TreasureLocation(_treasureManager, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, _spawn, hologramManager, _gadgetManager, serverStatusManager); - _treasureManager.addTreasureLocation(loc); - } - { - Block chestBlock = world.getBlockAt(-1, 178, 9); - Block chestLoc1 = world.getBlockAt(-4, 178, 10); - Block chestLoc2 = world.getBlockAt(-4, 178, 8); - Block chestLoc3 = world.getBlockAt(-2, 178, 6); - Block chestLoc4 = world.getBlockAt(0, 178, 6); - Block chestLoc5 = world.getBlockAt(2, 178, 8); - Block chestLoc6 = world.getBlockAt(2, 178, 10); - Block chestLoc7 = world.getBlockAt(0, 178, 12); - Block chestLoc8 = world.getBlockAt(-2, 178, 12); - TreasureLocation loc = new TreasureLocation(_treasureManager, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, _spawn, hologramManager, _gadgetManager, serverStatusManager); - _treasureManager.addTreasureLocation(loc); - } +// _treasureManager = new TreasureManager(_plugin, clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, _gadgetManager, _blockRestore, hologramManager, statsManager, _bonusManager.getRewardManager()); +// _treasureManager.disable(); +// { +// Block chestBlock = world.getBlockAt(-1, 178, -9); +// Block chestLoc1 = world.getBlockAt(-4, 178, -8); +// Block chestLoc2 = world.getBlockAt(-4, 178, -10); +// Block chestLoc3 = world.getBlockAt(-2, 178, -12); +// Block chestLoc4 = world.getBlockAt(0, 178, -12); +// Block chestLoc5 = world.getBlockAt(2, 178, -10); +// Block chestLoc6 = world.getBlockAt(2, 178, -8); +// Block chestLoc7 = world.getBlockAt(0, 178, -6); +// Block chestLoc8 = world.getBlockAt(-2, 178, -6); +// TreasureLocation loc = new TreasureLocation(_treasureManager, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, _spawn, hologramManager, _gadgetManager, serverStatusManager); +// _treasureManager.addTreasureLocation(loc); +// } +// { +// Block chestBlock = world.getBlockAt(-1, 178, 9); +// Block chestLoc1 = world.getBlockAt(-4, 178, 10); +// Block chestLoc2 = world.getBlockAt(-4, 178, 8); +// Block chestLoc3 = world.getBlockAt(-2, 178, 6); +// Block chestLoc4 = world.getBlockAt(0, 178, 6); +// Block chestLoc5 = world.getBlockAt(2, 178, 8); +// Block chestLoc6 = world.getBlockAt(2, 178, 10); +// Block chestLoc7 = world.getBlockAt(0, 178, 12); +// Block chestLoc8 = world.getBlockAt(-2, 178, 12); +// TreasureLocation loc = new TreasureLocation(_treasureManager, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, _spawn, hologramManager, _gadgetManager, serverStatusManager); +// _treasureManager.addTreasureLocation(loc); +// } new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, petManager, _treasureManager, boosterManager, punish); @@ -252,7 +247,6 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter _statsManager = statsManager; _achievementManager = achievementManager; - _achievementManager.setGiveInterfaceItem(true); _packetHandler = packetHandler; new NotificationManager(getPlugin(), clientManager); @@ -260,7 +254,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true; - new ValentinesGiftManager(plugin, clientManager, _bonusManager.getRewardManager(), inventoryManager, _gadgetManager, statsManager); + //new ValentinesGiftManager(plugin, clientManager, _bonusManager.getRewardManager(), inventoryManager, _gadgetManager, statsManager); _playerCountManager = new PlayerCountManager(plugin); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index c4c9d6238..9ce3ea39d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -1,9 +1,6 @@ package mineplex.hub; -import static mineplex.core.Managers.require; - import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -13,9 +10,6 @@ import mineplex.core.TwitchIntegrationFix; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.antihack.AntiHack; -import mineplex.core.antihack.guardians.AntiHackGuardian; -import mineplex.core.antihack.guardians.GuardianManager; -import mineplex.core.aprilfools.AprilFoolsManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.boosters.BoosterManager; import mineplex.core.chat.Chat; @@ -26,7 +20,6 @@ import mineplex.core.command.CommandCenter; import mineplex.core.common.Constants; import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.creature.Creature; -import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; import mineplex.core.elo.EloManager; @@ -34,7 +27,6 @@ import mineplex.core.energy.Energy; import mineplex.core.friend.FriendManager; import mineplex.core.gadget.gadgets.particle.king.CastleManager; import mineplex.core.give.Give; -import mineplex.core.globalpacket.GlobalPacketManager; import mineplex.core.hologram.HologramManager; import mineplex.core.ignore.IgnoreManager; import mineplex.core.incognito.IncognitoManager; @@ -56,8 +48,6 @@ import mineplex.core.preferences.PreferencesManager; import mineplex.core.profileCache.ProfileCacheManager; import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; -import mineplex.core.rankGiveaway.eternal.EternalGiveawayManager; -import mineplex.core.rankGiveaway.titangiveaway.TitanGiveawayManager; import mineplex.core.recharge.Recharge; import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; @@ -65,20 +55,17 @@ import mineplex.core.resourcepack.ResourcePackManager; import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; -import mineplex.core.task.TaskManager; import mineplex.core.teamspeak.TeamspeakManager; import mineplex.core.teleport.Teleport; import mineplex.core.thank.ThankManager; import mineplex.core.titles.Titles; -import mineplex.core.titles.tracks.TrackManager; import mineplex.core.twofactor.TwoFactorAuth; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.velocity.VelocityFix; import mineplex.core.visibility.VisibilityManager; import mineplex.core.website.WebsiteLinkManager; -import mineplex.hub.brawl.fountain.FountainManager; -import mineplex.hub.modules.AprilFoolsTreasureHunt; +import mineplex.hub.brawlfountain.FountainManager; import mineplex.hub.queue.QueueManager; import mineplex.hub.server.ServerManager; import mineplex.minecraft.game.classcombat.Class.ClassManager; @@ -92,9 +79,10 @@ import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; import mineplex.minecraft.game.core.fire.Fire; +import static mineplex.core.Managers.require; + public class Hub extends JavaPlugin implements IRelation { - private NpcManager _npcManager; @Override public void onEnable() @@ -104,18 +92,12 @@ public class Hub extends JavaPlugin implements IRelation getConfig().set(Constants.WEB_CONFIG_KEY, getConfig().getString(Constants.WEB_CONFIG_KEY)); saveConfig(); - //Logger.initialize(this); - - //Velocity Fix - new VelocityFix(this); - //Static Modules require(ProfileCacheManager.class); CommandCenter.Initialize(this); CoreClientManager clientManager = new CoreClientManager(this); CommandCenter.Instance.setClientManager(clientManager); -// new ProfileCacheManager(this); ItemStackFactory.Initialize(this, false); Recharge.Initialize(this); require(VisibilityManager.class); @@ -141,28 +123,18 @@ public class Hub extends JavaPlugin implements IRelation preferenceManager.GiveItem = true; Creature creature = new Creature(this); + creature.SetDisableCustomDrops(true); NpcManager npcManager = new NpcManager(this, creature); - _npcManager = npcManager; InventoryManager inventoryManager = new InventoryManager(this, clientManager); CastleManager castleManager = new CastleManager(this, clientManager, hologramManager, true); PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore); PollManager pollManager = new PollManager(this, clientManager, donationManager); - //new TournamentManager(this, clientManager, donationManager); ProjectileManager throwManager = new ProjectileManager(this); - //Main Modules - new TitanGiveawayManager(this, clientManager, serverStatusManager); - Portal portal = new Portal(); - AntiHack antiHack = require(AntiHack.class); - GuardianManager guardianManager = require(GuardianManager.class); - - for (int i = 0; i < 8; i++) - { - guardianManager.registerGuardian(new AntiHackGuardian(new Location(Bukkit.getWorld("world"), 0, 100, 0), 50, -50, 105, 95, 50, -50)); - } + require(AntiHack.class); IgnoreManager ignoreManager = new IgnoreManager(this, clientManager, preferenceManager, portal); @@ -176,17 +148,15 @@ public class Hub extends JavaPlugin implements IRelation SkillConditionManager conditionManager = new SkillConditionManager(this); - CustomDataManager customDataManager = new CustomDataManager(this, clientManager); - - PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager); + new PersonalServerManager(this, clientManager); String boosterGroup = serverConfiguration.getServerGroup().getBoosterGroup(); ThankManager thankManager = new ThankManager(this, clientManager, donationManager); BoosterManager boosterManager = new BoosterManager(this, boosterGroup, clientManager, donationManager, inventoryManager, thankManager); - HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, hologramManager, npcManager, personalServerManager, packetHandler, punish, serverStatusManager, customDataManager, thankManager, boosterManager, castleManager); + HubManager hubManager = new HubManager(clientManager, donationManager, inventoryManager, disguiseManager, portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, hologramManager, npcManager, punish, thankManager, boosterManager); QueueManager queueManager = new QueueManager(this, clientManager, donationManager, eloManager, partyManager); - ServerManager serverManager = new ServerManager(this, clientManager, donationManager, portal, partyManager, serverStatusManager, hubManager, queueManager, boosterManager); - new FountainManager(this, serverManager); + new ServerManager(this, clientManager, donationManager, portal, partyManager, serverStatusManager, hubManager, queueManager, boosterManager); + require(FountainManager.class); Chat chat = new Chat(this, incognito, clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); @@ -195,16 +165,12 @@ public class Hub extends JavaPlugin implements IRelation new CustomTagFix(this, packetHandler); new PacketsInteractionFix(this, packetHandler); new ResourcePackManager(this, portal); - new GlobalPacketManager(this, clientManager, serverStatusManager, inventoryManager, donationManager, petManager, statsManager, hubManager.getBonusManager().getRewardManager()); - //new Replay(this, packetHandler); SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); ReportManager reportManager = new ReportManager(this, snapshotManager, clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 3); new SnapshotPlugin(this, snapshotManager, clientManager); new ReportPlugin(this, reportManager); - new EternalGiveawayManager(this, clientManager, serverStatusManager); - CombatManager combatManager = new CombatManager(this); DamageManager damage = new DamageManager(this, combatManager, npcManager, disguiseManager, conditionManager); @@ -227,19 +193,16 @@ public class Hub extends JavaPlugin implements IRelation new ClassCombatShop(shopManager, clientManager, donationManager, false, "Knight", classManager.GetClass("Knight"), true); new ClassCombatShop(shopManager, clientManager, donationManager, false, "Assassin", classManager.GetClass("Assassin"), true); - //Updates - getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1); + //Velocity Fix + new VelocityFix(this); + + //Updates + new Updater(this); - require(TrackManager.class); require(Titles.class); require(TwoFactorAuth.class); require(TeamspeakManager.class); new WebsiteLinkManager(this, clientManager); - - if (AprilFoolsManager.getInstance().isEnabled()) - { - require(AprilFoolsTreasureHunt.class); - } require(TwitchIntegrationFix.class); } @@ -248,7 +211,7 @@ public class Hub extends JavaPlugin implements IRelation { getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); } - + @Override public boolean canHurt(Player a, Player b) { @@ -266,9 +229,4 @@ public class Hub extends JavaPlugin implements IRelation { return true; } - - public NpcManager getNpcManager() - { - return _npcManager; - } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubClient.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubClient.java index 247ba32a9..b7201e510 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubClient.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubClient.java @@ -2,24 +2,11 @@ package mineplex.hub; public class HubClient { - public String ScoreboardString = " Hello, I am a big friendly cat!"; - public int ScoreboardIndex = 0; - public String NewsString = " Bridges v2.0 is coming soon! New gameplay, new kits, new maps!"; - public int NewsIndex = 0; + private static final int DISPLAY_LENGTH = 16; - public String PurchaseString = " Purchase Ultra Rank at mineplex.com to unlock all game benefits!"; - public int PurchaseIndex = 0; - - public String UltraString = " Thank you for your support!"; - public int UltraIndex = 0; - - public String StaffString = "None"; - public int StaffIndex = 0; - - public String BestPig = "0-Nobody"; - - public int DisplayLength = 16; + private String ScoreboardString; + private int ScoreboardIndex ; public HubClient(String name) { @@ -34,95 +21,20 @@ public class HubClient public String GetScoreboardText() { - if (ScoreboardString.length() <= DisplayLength) - return ScoreboardString; - - String display = ScoreboardString.substring(ScoreboardIndex, Math.min(ScoreboardIndex + DisplayLength, ScoreboardString.length())); - - if (display.length() < DisplayLength && ScoreboardString.length() > DisplayLength) + if (ScoreboardString.length() <= DISPLAY_LENGTH) { - int add = DisplayLength - display.length(); + return ScoreboardString; + } + + String display = ScoreboardString.substring(ScoreboardIndex, Math.min(ScoreboardIndex + DISPLAY_LENGTH, ScoreboardString.length())); + + if (display.length() < DISPLAY_LENGTH) + { + int add = DISPLAY_LENGTH - display.length(); display += ScoreboardString.substring(0, add); } ScoreboardIndex = (ScoreboardIndex + 1) % ScoreboardString.length(); - - return display; - } - - public String GetPurchaseText(boolean increment) - { - if (PurchaseString.length() <= DisplayLength) - return PurchaseString; - - if (increment) - PurchaseIndex = (PurchaseIndex + 1) % PurchaseString.length(); - - String display = PurchaseString.substring(PurchaseIndex, Math.min(PurchaseIndex + DisplayLength, PurchaseString.length())); - - if (display.length() < DisplayLength && PurchaseString.length() > DisplayLength) - { - int add = DisplayLength - display.length(); - display += PurchaseString.substring(0, add); - } - - return display; - } - - public String GetUltraText(boolean increment) - { - if (UltraString.length() <= DisplayLength) - return UltraString; - - if (increment) - UltraIndex = (UltraIndex + 1) % UltraString.length(); - - String display = UltraString.substring(UltraIndex, Math.min(UltraIndex + DisplayLength, UltraString.length())); - - if (display.length() < DisplayLength) - { - int add = DisplayLength - display.length(); - display += UltraString.substring(0, add); - } - - return display; - } - - public String GetStaffText(boolean increment) - { - if (StaffString.length() <= DisplayLength) - return StaffString; - - if (increment) - StaffIndex = (StaffIndex + 1) % StaffString.length(); - - String display = StaffString.substring(StaffIndex, Math.min(StaffIndex + DisplayLength, StaffString.length())); - - if (display.length() < DisplayLength && StaffString.length() > DisplayLength) - { - int add = DisplayLength - display.length(); - display += StaffString.substring(0, add); - } - - return display; - } - - public String GetNewsText(boolean increment) - { - if (NewsString.length() <= DisplayLength) - return NewsString; - - if (increment) - NewsIndex = (NewsIndex + 1) % NewsString.length(); - - String display = NewsString.substring(NewsIndex, Math.min(NewsIndex + DisplayLength, NewsString.length())); - - if (display.length() < DisplayLength && NewsString.length() > DisplayLength) - { - int add = DisplayLength - display.length(); - display += NewsString.substring(0, add); - } - return display; } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 253ad4bd0..b8c6bc93d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -1,10 +1,5 @@ package mineplex.hub; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; import java.util.UUID; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -16,33 +11,20 @@ import net.minecraft.server.v1_8_R3.EntityPlayer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.GameMode; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.entity.Egg; import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityTargetEvent.TargetReason; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerVelocityEvent; import org.bukkit.event.server.ServerListPingEvent; -import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.Managers; import mineplex.core.MiniClientPlugin; @@ -53,50 +35,35 @@ import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.achievement.AchievementManager; import mineplex.core.antispam.AntiSpamManager; import mineplex.core.benefit.BenefitManager; -import mineplex.core.blockrestore.BlockRestore; import mineplex.core.bonuses.BonusManager; import mineplex.core.boosters.BoosterManager; import mineplex.core.botspam.BotSpamManager; import mineplex.core.chat.ChatFormat; import mineplex.core.chat.IChatMessageFormatter; -import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.C; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTime; import mineplex.core.communities.CommunityManager; import mineplex.core.cosmetic.CosmeticManager; -import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; -import mineplex.core.disguise.disguises.DisguiseSlime; import mineplex.core.disguise.playerdisguise.PlayerDisguiseManager; import mineplex.core.donation.DonationManager; -import mineplex.core.donation.Donor; import mineplex.core.facebook.FacebookManager; import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.event.GadgetCollideEntityEvent; -import mineplex.core.gadget.gadgets.particle.king.CastleManager; import mineplex.core.hologram.HologramManager; -import mineplex.core.incognito.IncognitoManager; import mineplex.core.incognito.events.IncognitoHidePlayerEvent; import mineplex.core.interactions.NewInteractionsManager; import mineplex.core.inventory.InventoryManager; -import mineplex.core.locations.LocationConstants; import mineplex.core.menu.MenuManager; import mineplex.core.message.PrivateMessageEvent; import mineplex.core.noteblock.MusicManager; import mineplex.core.notifier.NotificationManager; import mineplex.core.npc.NpcManager; -import mineplex.core.packethandler.PacketHandler; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; -import mineplex.core.personalServer.PersonalServerManager; import mineplex.core.pet.PetManager; -import mineplex.core.playerCount.PlayerCountManager; import mineplex.core.playwire.PlayWireManager; import mineplex.core.poll.PollManager; import mineplex.core.portal.GenericServer; @@ -104,46 +71,40 @@ import mineplex.core.portal.Intent; import mineplex.core.portal.Portal; import mineplex.core.preferences.Preference; import mineplex.core.preferences.PreferencesManager; -import mineplex.core.projectile.ProjectileManager; +import mineplex.core.profile.ProfileManager; import mineplex.core.punish.Punish; import mineplex.core.quests.QuestManager; -import mineplex.core.scoreboard.MineplexScoreboard; import mineplex.core.scoreboard.ScoreboardManager; import mineplex.core.scoreboard.TabListSorter; import mineplex.core.stats.StatsManager; -import mineplex.core.status.ServerStatusManager; -import mineplex.core.task.TaskManager; import mineplex.core.thank.ThankManager; -import mineplex.core.titles.Titles; import mineplex.core.treasure.TreasureManager; import mineplex.core.twofactor.TwoFactorAuth; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.core.valentines.ValentinesGiftManager; import mineplex.core.youtube.YoutubeManager; -import mineplex.hub.commands.ForcefieldRadius; import mineplex.hub.commands.GadgetToggle; -import mineplex.hub.commands.GameModeCommand; -import mineplex.hub.commands.NewsCommand; -import mineplex.hub.modules.EasterEggHunt; +import mineplex.hub.doublejump.JumpManager; +import mineplex.hub.gimmicks.AdminPunch; +import mineplex.hub.gimmicks.StaffBuild; +import mineplex.hub.hubgame.HubGameManager; import mineplex.hub.modules.ForcefieldManager; import mineplex.hub.modules.HubVisibilityManager; -import mineplex.hub.modules.JumpManager; -import mineplex.hub.modules.KothManager; -import mineplex.hub.modules.MavericksManager; -import mineplex.hub.modules.NewsManager; -import mineplex.hub.modules.ParkourManager; import mineplex.hub.modules.SoccerManager; import mineplex.hub.modules.TemporaryGemHuntersServerSender; -import mineplex.hub.modules.ValentinesManager; -import mineplex.hub.modules.WorldManager; import mineplex.hub.modules.salesannouncements.SalesAnnouncementManager; -import mineplex.hub.profile.gui.GUIProfile; -import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; -import mineplex.minecraft.game.classcombat.item.event.ItemTriggerEvent; +import mineplex.hub.news.NewsManager; +import mineplex.hub.parkour.ParkourManager; +import mineplex.hub.player.CreativeManager; +import mineplex.hub.player.HubPlayerManager; +import mineplex.hub.plugin.HalloweenHubPlugin; +import mineplex.hub.plugin.HubPlugin; +import mineplex.hub.scoreboard.HubScoreboard; +import mineplex.hub.world.HubPortalManager; +import mineplex.hub.world.HubWorldManager; +import mineplex.hub.world.WorldDataModule; import mineplex.minecraft.game.core.combat.DeathMessageType; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; -import mineplex.minecraft.game.core.condition.ConditionManager; public class HubManager extends MiniClientPlugin implements IChatMessageFormatter { @@ -154,301 +115,129 @@ public class HubManager extends MiniClientPlugin implements IChatMess AUTO_OP, VANISH, SPAWN_PM, - NEWS_COMMAND, JOIN_FULL, } // ☃❅ Snowman! - public HubType Type = HubType.Normal; - private BlockRestore _blockRestore; - private CoreClientManager _clientManager; - private ConditionManager _conditionManager; - private DonationManager _donationManager; - private DisguiseManager _disguiseManager; - private PartyManager _partyManager; - private ForcefieldManager _forcefieldManager; - private PollManager _pollManager; - private Portal _portal; - private StatsManager _statsManager; - private GadgetManager _gadgetManager; - private HubVisibilityManager _visibilityManager; - private ParkourManager _parkour; - private PreferencesManager _preferences; - private InventoryManager _inventoryManager; - private NewsManager _news; - private AchievementManager _achievementManager; - private TreasureManager _treasureManager; - private PetManager _petManager; - private PacketHandler _packetHandler; - private PersonalServerManager _personalServerManager; - private PlayerCountManager _playerCountManager; - private CustomDataManager _customDataManager; - private Punish _punishManager; - private IncognitoManager _incognito; - private ValentinesManager _valentinesManager; - private BonusManager _bonusManager; - private JumpManager _jumpManager; -// private HalloweenSpookinessManager _halloweenManager; -// private TrickOrTreatManager _trickOrTreatManager; - private MavericksManager _mavericksManager; - private QuestManager _questManager; - private final TwoFactorAuth _twofactor = Managers.require(TwoFactorAuth.class); - - private HologramManager _hologramManager; + private final CoreClientManager _clientManager; + private final DonationManager _donationManager; + private final DisguiseManager _disguiseManager; + private final PartyManager _partyManager; + private final Portal _portal; + private final GadgetManager _gadgetManager; + private final HubVisibilityManager _visibilityManager; + private final PreferencesManager _preferences; + private final AchievementManager _achievementManager; + private final PetManager _petManager; + private final JumpManager _jumpManager; + private final HologramManager _hologramManager; - private Location _spawn; + private final HubPlugin _hubPlugin; + + private final WorldDataModule _worldData; + private final Location _spawn; - private final String _serverName; private boolean _shuttingDown; - private Map _portalTime = new HashMap<>(); - - private Map> _creativeAdmin = new HashMap<>(); - - public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, IncognitoManager incognito, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, CustomDataManager customDataManager, ThankManager thankManager, BoosterManager boosterManager, CastleManager castleManager) + public HubManager(CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, DisguiseManager disguiseManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, Punish punish, ThankManager thankManager, BoosterManager boosterManager) { super("Hub Manager"); - String serverName = getPlugin().getConfig().getString("serverstatus.name"); - _serverName = serverName.substring(0, Math.min(16, serverName.length())); - - _incognito = incognito; - - _blockRestore = blockRestore; _clientManager = clientManager; - _conditionManager = conditionManager; _donationManager = donationManager; _disguiseManager = disguiseManager; - _pollManager = pollManager; - _personalServerManager = personalServerManager; _portal = portal; - _spawn = LocationConstants.HUB_SPAWN.clone().add(0, 5, 0); + _worldData = require(WorldDataModule.class); + _spawn = _worldData.getCustomLocation("SPAWN").get(0); // Disable item merging ((CraftWorld) _spawn.getWorld()).getHandle().spigotConfig.itemMerge = 0; - _parkour = new ParkourManager(this, donationManager, taskManager); - - new WorldManager(this); + require(ParkourManager.class); _jumpManager = new JumpManager(this); - //new TournamentInviter(this); - _news = new NewsManager(this); + require(NewsManager.class); + require(CreativeManager.class); + require(HubWorldManager.class); - _inventoryManager = inventoryManager; - new BenefitManager(plugin, clientManager, _inventoryManager); - _gadgetManager = new GadgetManager(clientManager, donationManager, _inventoryManager, petManager, preferences, disguiseManager, blockRestore, Managers.get(ProjectileManager.class), achievementManager, packetHandler, hologramManager, incognito, castleManager); + new BenefitManager(_plugin, clientManager, inventoryManager); + _gadgetManager = require(GadgetManager.class); - FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager, inventoryManager); - YoutubeManager youtubeManager = new YoutubeManager(plugin, clientManager, donationManager); - PlayWireManager playWireManager = new PlayWireManager(plugin, clientManager); + FacebookManager facebookManager = new FacebookManager(_plugin, clientManager, donationManager, inventoryManager); + YoutubeManager youtubeManager = new YoutubeManager(_plugin, clientManager, donationManager); + PlayWireManager playWireManager = new PlayWireManager(_plugin, clientManager); - _bonusManager = new BonusManager(plugin, null, playWireManager, clientManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, facebookManager, youtubeManager, _gadgetManager, thankManager, "Carl"); + new BonusManager(_plugin, null, playWireManager, clientManager, donationManager, pollManager, npcManager, hologramManager, statsManager, inventoryManager, petManager, facebookManager, youtubeManager, _gadgetManager, thankManager, "Carl"); + + TreasureManager treasureManager = require(TreasureManager.class); + new CosmeticManager(_plugin, clientManager, donationManager, inventoryManager, _gadgetManager, petManager, treasureManager, boosterManager, punish); + + for (Location location : _worldData.getCustomLocation("TREASURE CHEST")) + { + treasureManager.addTreasureLocation(location); + } + + //new MavericksManager(_plugin, cosmeticManager, hologramManager, this); - _treasureManager = new TreasureManager(_plugin, clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, _gadgetManager, _blockRestore, hologramManager, statsManager, _bonusManager.getRewardManager()); - CosmeticManager cosmeticManager = new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, petManager, _treasureManager, boosterManager, punish); - - _mavericksManager = new MavericksManager(plugin, cosmeticManager, hologramManager, this); - new SoccerManager(this, _gadgetManager); - new KothManager(this, _gadgetManager); new MenuManager(_plugin); new NewInteractionsManager(); AntiSpamManager antiSpam = new AntiSpamManager(); antiSpam.setMessageFormatter(this); - //new TrickOrTreatManager(_plugin, this, taskManager, donationManager, clientManager); - _petManager = petManager; _partyManager = partyManager; _preferences = preferences; _visibilityManager = new HubVisibilityManager(this); - _forcefieldManager = new ForcefieldManager(this); - addCommand(new ForcefieldRadius(_forcefieldManager)); + new ForcefieldManager(this); - _statsManager = statsManager; _achievementManager = achievementManager; - _achievementManager.setGiveInterfaceItem(true); - _packetHandler = packetHandler; new NotificationManager(getPlugin(), clientManager); - new BotSpamManager(plugin, clientManager, punish); + new BotSpamManager(_plugin, clientManager, punish); - ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle().pvpMode = true; + new MusicManager((player) -> _preferences.get(player).isActive(Preference.HUB_MUSIC), "../../update/songs/lobbyMusicHalloween"); - new MusicManager((player) -> _preferences.get(player).isActive(Preference.HUB_MUSIC), "../../update/songs/lobbyMusic"); -// _halloweenManager = new HalloweenSpookinessManager(this); - -// new HolidayGiftManager(plugin, clientManager, donationManager, inventoryManager, taskManager); require(PlayerDisguiseManager.class); -// NotificationManager notificationManager = new NotificationManager(plugin, clientManager, donationManager); -// new MailManager(_plugin, notificationManager); - new ValentinesGiftManager(plugin, clientManager, _bonusManager.getRewardManager(), inventoryManager, _gadgetManager, statsManager); - _playerCountManager = new PlayerCountManager(plugin); + new SalesAnnouncementManager(_plugin); - _customDataManager = Managers.get(CustomDataManager.class); + new CommunityManager(_plugin, _clientManager); - _punishManager = punish; - - _valentinesManager = new ValentinesManager(plugin, clientManager, donationManager); - - new SalesAnnouncementManager(plugin); - - new CommunityManager(plugin, _clientManager); - _hologramManager = hologramManager; - - new EasterEggHunt(plugin, _clientManager); - - _questManager = new QuestManager(hologramManager, null, _inventoryManager, _donationManager); + + //new EasterEggHunt(_plugin, _clientManager); + + new QuestManager(hologramManager, null, inventoryManager, _donationManager); new TemporaryGemHuntersServerSender(_portal); require(TabListSorter.class); - ScoreboardManager scoreboardManager = new ScoreboardManager(plugin) - { - @Override - public void setup(MineplexScoreboard scoreboard) - { - for (PermissionGroup group : PermissionGroup.values()) - { - if (!group.canBePrimary()) - { - continue; - } - if (!group.getDisplay(false, false, false, false).isEmpty()) - { - scoreboard.getHandle().registerNewTeam(group.name()).setPrefix(group.getDisplay(true, true, true, false) + ChatColor.RESET + " "); - } - else - { - scoreboard.getHandle().registerNewTeam(group.name()).setPrefix(""); - } - } + Managers.put(new HubScoreboard(_plugin, this), ScoreboardManager.class); - scoreboard.register(HubScoreboardLine.SERVER_TITLE) - .register(HubScoreboardLine.SERVER_NAME) - .register(HubScoreboardLine.SERVER_EMPTY_SPACER) - .register(HubScoreboardLine.GEM_TITLE) - .register(HubScoreboardLine.GEM_COUNT) - .register(HubScoreboardLine.GEM_EMPTY_SPACER) - .register(HubScoreboardLine.SHARDS_TITLE) - .register(HubScoreboardLine.SHARDS_COUNT) - .register(HubScoreboardLine.PLAYER_EMPTY_SPACER) - .register(HubScoreboardLine.RANK_TITLE) - .register(HubScoreboardLine.RANK_NAME) - .register(HubScoreboardLine.RANK_EMPTY_SPACER) - .register(HubScoreboardLine.WEBSITE_TITLE) - .register(HubScoreboardLine.WEBSITE_VALUE) - .register(HubScoreboardLine.END_BREAKER) - .recalculate(); + require(TwoFactorAuth.class); + require(HubGameManager.class); + //require(ProfileManager.class); + require(HubPlayerManager.class); + require(AdminPunch.class); + //require(StaffBuild.class); + //require(HubPortalManager.class); - scoreboard.get(HubScoreboardLine.SERVER_TITLE).write(C.cAqua + C.Bold + "Server"); - scoreboard.get(HubScoreboardLine.SERVER_NAME).write(_serverName); - scoreboard.get(HubScoreboardLine.GEM_TITLE).write(C.cGreen + C.Bold + "Gems"); - scoreboard.get(HubScoreboardLine.SHARDS_TITLE).write(C.cYellow + C.Bold + "Shards"); - scoreboard.get(HubScoreboardLine.RANK_TITLE).write(C.cGold + C.Bold + "Rank"); - scoreboard.get(HubScoreboardLine.WEBSITE_TITLE).write(C.cRed + C.Bold + "Website"); - scoreboard.get(HubScoreboardLine.WEBSITE_VALUE).write("www.mineplex.com"); - scoreboard.get(HubScoreboardLine.END_BREAKER).write("----------------"); - } + _hubPlugin = new HalloweenHubPlugin(); + //_hubPlugin = new HubPlugin(); - @Override - public void draw(MineplexScoreboard scoreboard) - { - scoreboard.setSidebarName(C.cWhite + C.Bold + Get(scoreboard.getOwner()).GetScoreboardText()); - scoreboard.get(HubScoreboardLine.GEM_COUNT).write(GetDonation().Get(scoreboard.getOwner()).getBalance(GlobalCurrency.GEM)); - scoreboard.get(HubScoreboardLine.SHARDS_COUNT).write(GetDonation().Get(scoreboard.getOwner()).getBalance(GlobalCurrency.TREASURE_SHARD)); - - String rankName = getRankName(GetClients().Get(scoreboard.getOwner()).getPrimaryGroup(), GetDonation().Get(scoreboard.getOwner())); - - PermissionGroup disguisedRank = GetClients().Get(scoreboard.getOwner()).getDisguisedPrimaryGroup(); - String disguisedAs = GetClients().Get(scoreboard.getOwner()).getDisguisedAs(); - if (disguisedRank != null && disguisedAs != null) - { - rankName = getRankName(disguisedRank, GetDonation().Get(GetClients().Get(scoreboard.getOwner()).getDisguisedAsUUID())) + " (" + rankName + ")"; - } - - scoreboard.get(HubScoreboardLine.RANK_NAME).write(rankName); - } - - @Override - public void handlePlayerJoin(String playerName) - { - Player player = Bukkit.getPlayerExact(playerName); - - HubClient hubclient = HubManager.this.Get(player); - hubclient.setName(playerName); - - PermissionGroup group = _clientManager.Get(player).getRealOrDisguisedPrimaryGroup(); - - for (MineplexScoreboard scoreboard : getScoreboards().values()) - { - scoreboard.getHandle().getTeam(group.name()).addEntry(playerName); - } - - if (get(player) != null) - { - for (Player player1 : Bukkit.getOnlinePlayers()) - { - group = _clientManager.Get(player1).getRealOrDisguisedPrimaryGroup(); - get(player).getHandle().getTeam(group.name()).addEntry(player1.getName()); - } - } - } - - @Override - public void handlePlayerQuit(String playerName) - { - Player player = Bukkit.getPlayerExact(playerName); - - PermissionGroup group = _clientManager.Get(player).getRealOrDisguisedPrimaryGroup(); - - for (MineplexScoreboard scoreboard : getScoreboards().values()) - { - scoreboard.getHandle().getTeam(group.name()).removeEntry(playerName); - } - } - - private String getRankName(PermissionGroup group, Donor donor) - { - String display = group.getDisplay(false, false, false, false); - if (display.isEmpty()) - { - if (donor.ownsUnknownSalesPackage("SuperSmashMobs ULTRA") || - donor.ownsUnknownSalesPackage("Survival Games ULTRA") || - donor.ownsUnknownSalesPackage("Minigames ULTRA") || - donor.ownsUnknownSalesPackage("CastleSiege ULTRA") || - donor.ownsUnknownSalesPackage("Champions ULTRA")) - { - display = "Single Ultra"; - } - else - { - display = "No Rank"; - } - } - - return display; - } - }; - - Managers.put(scoreboardManager, ScoreboardManager.class); - generatePermissions(); } - + private void generatePermissions() { PermissionGroup.ADMIN.setPermission(Perm.GADGET_TOGGLE_COMMAND, true, true); PermissionGroup.ADMIN.setPermission(Perm.GAMEMODE_COMMAND, true, true); - PermissionGroup.ADMIN.setPermission(Perm.NEWS_COMMAND, true, true); if (UtilServer.isDevServer() || UtilServer.isTestServer()) { PermissionGroup.ADMIN.setPermission(Perm.AUTO_OP, true, true); @@ -467,8 +256,6 @@ public class HubManager extends MiniClientPlugin implements IChatMess public void addCommands() { addCommand(new GadgetToggle(this)); - addCommand(new NewsCommand(this)); - addCommand(new GameModeCommand(this)); } @EventHandler(priority = EventPriority.HIGHEST) @@ -478,6 +265,10 @@ public class HubManager extends MiniClientPlugin implements IChatMess { event.setMotd("Restarting soon"); } + else if (UtilServer.isTestServer()) + { + event.setMotd(C.cGreen + "Private Mineplex Test Server"); + } } @EventHandler @@ -486,55 +277,14 @@ public class HubManager extends MiniClientPlugin implements IChatMess if (event.getPlayer().isOp() && event.getMessage().equalsIgnoreCase("/stop")) { _shuttingDown = true; - - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable() - { - public void run() - { - _portal.sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK); - - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable() - { - public void run() - { - Bukkit.shutdown(); - } - }, 40L); - } - }, 60L); - event.setCancelled(true); - } - } - @EventHandler - public void preventEggSpawn(ItemSpawnEvent event) - { - if (event.getEntity() instanceof Egg) - { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void OnChunkLoad(ChunkLoadEvent event) - { - for (Entity entity : event.getChunk().getEntities()) - { - if (entity instanceof LivingEntity) + runSyncLater(() -> { - if (((LivingEntity) entity).isCustomNameVisible() && ((LivingEntity) entity).getCustomName() != null) - { - if (ChatColor.stripColor(((LivingEntity) entity).getCustomName()).equalsIgnoreCase("Block Hunt")) - { - DisguiseSlime disguise = new DisguiseSlime(entity); - disguise.setCustomNameVisible(true); - disguise.setName(((LivingEntity) entity).getCustomName(), null); - disguise.SetSize(2); - _disguiseManager.disguise(disguise); - } - } - } + _portal.sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK); + + runSyncLater(Bukkit::shutdown, 40); + }, 60); } } @@ -548,10 +298,7 @@ public class HubManager extends MiniClientPlugin implements IChatMess { if (!client.hasPermission(Perm.JOIN_FULL)) { - Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> - { - _portal.sendPlayerToGenericServer(event.getPlayer(), GenericServer.HUB, Intent.KICK); - }); + runSyncLater(() -> _portal.sendPlayerToGenericServer(event.getPlayer(), GenericServer.HUB, Intent.KICK), 0); event.allow(); } @@ -562,77 +309,31 @@ public class HubManager extends MiniClientPlugin implements IChatMess } } - @EventHandler(priority = EventPriority.LOW) - public void AdminOP(PlayerJoinEvent event) - { - if (_clientManager.Get(event.getPlayer()).hasPermission(Perm.AUTO_OP)) - event.getPlayer().setOp(true); - else - event.getPlayer().setOp(false); - } - @EventHandler - public void PlayerRespawn(PlayerRespawnEvent event) - { - event.setRespawnLocation(GetSpawn()); - } - - @EventHandler(priority = EventPriority.LOW) - public void PlayerJoin(PlayerJoinEvent event) + public void autoOP(PlayerJoinEvent event) { Player player = event.getPlayer(); - String playerName = player.getName(); - // April Fools -// if (AprilFoolsManager.Instance.isActive()) -// playerName = AprilFoolsManager.Instance.getName(player); - - //Public Message - event.setJoinMessage(null); - -// if (_clientManager.Get(player).GetRank() != Rank.LEGEND) -// event.setJoinMessage(null); -// else -// { -// event.setJoinMessage(C.cGreen + C.Bold + "Legend " + playerName + " has joined!"); -// } - - //Teleport - player.teleport(GetSpawn()); - - //Survival - player.setGameMode(GameMode.SURVIVAL); - - //Clear Inv - UtilInv.Clear(player); - - //Allow Double Jump - player.setAllowFlight(true); - - //Health - player.setHealth(20); - - //only give it in the hub - player.getInventory().setItem(PartyManager.INTERFACE_SLOT, PartyManager.INTERFACE_ITEM); - require(Titles.class).giveBook(player, false); + player.setOp(_clientManager.Get(event.getPlayer()).hasPermission(Perm.AUTO_OP)); } @EventHandler - public void PlayerQuit(PlayerQuitEvent event) + public void playerQuit(PlayerQuitEvent event) { event.setQuitMessage(null); + } - event.getPlayer().leaveVehicle(); - event.getPlayer().eject(); - - _portalTime.remove(event.getPlayer().getName()); + @EventHandler + public void combatDeath(CombatDeathEvent event) + { + event.SetBroadcastType(DeathMessageType.None); } @EventHandler public void playerPrivateMessage(PrivateMessageEvent event) { //Dont Let PM Near Spawn! - if (UtilMath.offset2d(GetSpawn(), event.getSender().getLocation()) == 0 && !!_clientManager.Get(event.getSender()).hasPermission(Perm.SPAWN_PM)) + if (UtilMath.offset2d(GetSpawn(), event.getSender().getLocation()) == 0 && _clientManager.Get(event.getSender()).hasPermission(Perm.SPAWN_PM)) { UtilPlayer.message(event.getSender(), F.main("Chat", "You must leave spawn before you can Private Message!")); event.setCancelled(true); @@ -686,7 +387,7 @@ public class HubManager extends MiniClientPlugin implements IChatMess event.setMessage(event.getMessage().substring(1, event.getMessage().length()).trim()); event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + playerName + " " + C.cPurple + "%2$s"); - event.getRecipients().removeIf(other -> !party.getMembers().contains(other)); + event.getRecipients().removeIf(other -> !party.getMembers().contains(other)); } else { @@ -718,7 +419,7 @@ public class HubManager extends MiniClientPlugin implements IChatMess { for (Player other : event.getRecipients()) { - other.spigot().sendMessage(component); + other.spigot().sendMessage(component); } } event.setCancelled(true); @@ -754,82 +455,17 @@ public class HubManager extends MiniClientPlugin implements IChatMess return new ChatFormat(component.toLegacyText(), false); } - @EventHandler - public void Damage(EntityDamageEvent event) - { - if (event.getCause() == DamageCause.VOID) - if (event.getEntity() instanceof Player) - { - event.getEntity().eject(); - event.getEntity().leaveVehicle(); - event.getEntity().teleport(GetSpawn()); - } - else - { - if (!UtilEnt.hasFlag(event.getEntity(), UtilEnt.FLAG_NO_REMOVE)) - event.getEntity().remove(); - } - - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void handleDeath(PlayerDeathEvent event) - { - event.setKeepInventory(true); - event.getDrops().clear(); - event.getEntity().setHealth(20); - event.getEntity().teleport(GetSpawn()); - } - - @EventHandler - public void combatDeath(CombatDeathEvent event) - { - event.SetBroadcastType(DeathMessageType.None); - } - - @EventHandler - public void FoodHealthUpdate(UpdateEvent event) - { - if (event.getType() != UpdateType.SEC) - return; - - for (Player player : UtilServer.getPlayers()) - { - player.setFoodLevel(20); - player.setExhaustion(0f); - player.setSaturation(3f); - } - } - - @EventHandler - public void InventoryCancel(InventoryClickEvent event) - { - if (event.getWhoClicked() instanceof Player && ((Player) event.getWhoClicked()).getGameMode() != GameMode.CREATIVE) - event.setCancelled(true); - } - @Override protected HubClient addPlayer(UUID uuid) { return new HubClient(Bukkit.getPlayer(uuid).getName()); } - public BlockRestore GetBlockRestore() - { - return _blockRestore; - } - public CoreClientManager GetClients() { return _clientManager; } - public ConditionManager GetCondition() - { - return _conditionManager; - } - public DonationManager GetDonation() { return _donationManager; @@ -839,7 +475,7 @@ public class HubManager extends MiniClientPlugin implements IChatMess { return _disguiseManager; } - + public HologramManager getHologram() { return _hologramManager; @@ -850,16 +486,6 @@ public class HubManager extends MiniClientPlugin implements IChatMess return _gadgetManager; } - public TreasureManager GetTreasure() - { - return _treasureManager; - } - - public ParkourManager GetParkour() - { - return _parkour; - } - public PreferencesManager getPreferences() { return _preferences; @@ -875,82 +501,14 @@ public class HubManager extends MiniClientPlugin implements IChatMess return _petManager; } - public BonusManager getBonusManager() - { - return _bonusManager; - } - - public StatsManager GetStats() - { - return _statsManager; - } - public HubVisibilityManager GetVisibility() { return _visibilityManager; } - public CustomDataManager getCustomDataManager() + public JumpManager getJumpManager() { - return _customDataManager; - } - - public Punish getPunishments() - { - return _punishManager; - } - - public MavericksManager getMavericksManager() - { - return _mavericksManager; - } - - // public HalloweenSpookinessManager getHalloweenManager() -// { -// return _halloweenManager; -// } - - @EventHandler(priority = EventPriority.MONITOR) - public void gadgetCollide(GadgetCollideEntityEvent event) - { - if (!event.isCancelled()) - SetPortalDelay(event.getOther()); - } - - public void SetPortalDelay(Entity ent) - { - if (ent instanceof Player) - _portalTime.put(((Player) ent).getName(), System.currentTimeMillis()); - } - - public boolean CanPortal(Player player) - { - //Riding - if (player.getVehicle() != null || player.getPassenger() != null) - return false; - - //Portal Delay - if (!_portalTime.containsKey(player.getName())) - return true; - - return UtilTime.elapsed(_portalTime.get(player.getName()), 5000); - } - - @EventHandler - public void SkillTrigger(SkillTriggerEvent event) - { - event.SetCancelled(true); - } - - @EventHandler - public void ItemTrigger(ItemTriggerEvent event) - { - event.SetCancelled(true); - } - - public NewsManager GetNewsManager() - { - return _news; + return _jumpManager; } @EventHandler @@ -962,31 +520,13 @@ public class HubManager extends MiniClientPlugin implements IChatMess } } - public void ToggleGadget(Player caller) - { - toggleGadget(); - } - public void toggleGadget() { GetGadget().toggleGadgetEnabled(); - for (Player player : UtilServer.getPlayers()) - player.sendMessage(C.cWhite + C.Bold + "Gadgets/Mounts are now " + F.elem(GetGadget().isGadgetEnabled() ? C.cGreen + C.Bold + "Enabled" : C.cRed + C.Bold + "Disabled")); - } - - public void addGameMode(Player caller, Player target) - { - if (!_creativeAdmin.containsKey(caller.getName())) - _creativeAdmin.put(caller.getName(), new ArrayList()); - - if (target.getGameMode() == GameMode.CREATIVE) + for (Player player : UtilServer.getPlayersCollection()) { - _creativeAdmin.get(caller.getName()).add(target.getName()); - } - else - { - _creativeAdmin.get(caller.getName()).remove(target.getName()); + player.sendMessage(C.cWhiteB + "Gadgets/Mounts are now " + F.elem(GetGadget().isGadgetEnabled() ? C.cGreenB + "Enabled" : C.cRedB + "Disabled")); } } @@ -994,9 +534,11 @@ public class HubManager extends MiniClientPlugin implements IChatMess public void clearEntityTargets(UpdateEvent event) { if (event.getType() != UpdateType.SEC) + { return; + } - for (Entity entity : Bukkit.getWorlds().get(0).getEntities()) + for (Entity entity : _worldData.World.getEntities()) { if (entity instanceof EntityInsentient) { @@ -1005,76 +547,11 @@ public class HubManager extends MiniClientPlugin implements IChatMess if (entityMonster.getGoalTarget() != null && entityMonster.getGoalTarget() instanceof EntityPlayer) { if (((EntityPlayer) entityMonster.getGoalTarget()).playerConnection.isDisconnected()) + { entityMonster.setGoalTarget(null, TargetReason.FORGOT_TARGET, false); + } } } } } - - @EventHandler - public void clearGameMode(PlayerQuitEvent event) - { - List creative = _creativeAdmin.remove(event.getPlayer().getName()); - - if (creative == null) - return; - - for (String name : creative) - { - Player player = UtilPlayer.searchExact(name); - if (player == null) - continue; - - player.setGameMode(GameMode.SURVIVAL); - - UtilPlayer.message(player, F.main("Game Mode", event.getPlayer().getName() + " left the game. Creative Mode: " + F.tf(false))); - } - } - - public PacketHandler getPacketHandler() - { - return _packetHandler; - } - - @EventHandler - public void openProfile(PlayerInteractEvent event) - { - if (_twofactor.isAuthenticating(event.getPlayer()) || event.getItem() == null || event.getItem().getType() != Material.SKULL_ITEM) - return; - - new GUIProfile(getPlugin(), event.getPlayer(), _preferences, _achievementManager, _personalServerManager).openInventory(); - ; - } - - @EventHandler - public void trackPortalDelayPlayers(UpdateEvent event) - { - if (event.getType() != UpdateType.TICK) - return; - - for (Iterator playerNameIterator = _portalTime.keySet().iterator(); playerNameIterator.hasNext(); ) - { - String playerName = playerNameIterator.next(); - - if (UtilTime.elapsed(_portalTime.get(playerName), 5000)) - { - playerNameIterator.remove(); - } - } - } - - public IncognitoManager getIncognitoManager() - { - return _incognito; - } - - public JumpManager getJumpManager() - { - return _jumpManager; - } - - public QuestManager getQuestManager() - { - return _questManager; - } -} \ No newline at end of file +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java deleted file mode 100644 index 065728f36..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java +++ /dev/null @@ -1,234 +0,0 @@ -package mineplex.hub; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; - -import mineplex.serverdata.database.DBPool; - -public class HubRepository -{ - private boolean _us = true; - - private static String CREATE_NEWS_TABLE = "CREATE TABLE IF NOT EXISTS newsList (id INT NOT NULL AUTO_INCREMENT, newsString VARCHAR(256), newsPosition INT, PRIMARY KEY (id));"; - private static String RETRIEVE_NEWS_ENTRIES = "SELECT newsString, newsPosition FROM newsList;"; - private static String RETRIEVE_MAX_NEWS_POSITION = "SELECT MAX(newsPosition) AS newsPosition FROM newsList;"; - private static String ADD_NEWS_ENTRY = "INSERT INTO newsList (newsString, newsPosition) VALUES(?,?);"; - //private static String ADD_NEWS_ENTRY = "SET @max = (SELECT MAX(newsPosition) AS newsPosition FROM newsList);INSERT INTO newsList (newsString, newsPosition) VALUES(?,@max + 1);"; - private static String SET_NEWS_ENTRY = "UPDATE newsList SET newsString = ? WHERE newsPosition = ?;"; - private static String DELETE_NEWS_ENTRY = "DELETE FROM newsList WHERE newsPosition = ?;"; - private static String RECALC_NEWS_POSITIONS = "UPDATE newsList SET newsPosition = newsPosition - 1 WHERE newsPosition > ?;"; - //private static String DELETE_RECALC_NEWS_ENTRY = "SET @pos = ?;SET @max = (SELECT MAX(newsPosition) AS newsPosition FROM newsList);DELETE FROM newsList WHERE newsPosition = @pos;UPDATE newsList SET newsPosition = IF(@max <> @pos, newsPosition - 1, newsPosition) WHERE newsPosition > @pos;"; - - public void initialize(boolean us) - { - _us = us; - } - - public HashMap retrieveNewsEntries() - { - ResultSet resultSet = null; - PreparedStatement preparedStatement = null; - HashMap newsEntries = new HashMap(); - - try (Connection connection = DBPool.getMineplex().getConnection()) - { - preparedStatement = connection.prepareStatement(RETRIEVE_NEWS_ENTRIES); - - resultSet = preparedStatement.executeQuery(); - - while (resultSet.next()) - { - newsEntries.put(resultSet.getString(2), resultSet.getString(1)); - } - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - - if (resultSet != null) - { - try - { - resultSet.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } - - return newsEntries; - } - - public boolean setNewsEntry(String newsEntry, int newsPosition) - { - int result = 0; - PreparedStatement preparedStatement = null; - - try (Connection connection = DBPool.getMineplex().getConnection()) - { - preparedStatement = connection.prepareStatement(SET_NEWS_ENTRY); - preparedStatement.setString(1, newsEntry); - preparedStatement.setInt(2, newsPosition); - - result = preparedStatement.executeUpdate(); - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } - - return result != 0; - } - - public int retrieveMaxNewsPosition() - { - int result = 0; - ResultSet resultSet = null; - PreparedStatement preparedStatement = null; - - try (Connection connection = DBPool.getMineplex().getConnection()) - { - preparedStatement = connection.prepareStatement(RETRIEVE_MAX_NEWS_POSITION); - resultSet = preparedStatement.executeQuery(); - - while (resultSet.next()) - { - result = Integer.parseInt(resultSet.getString(1)); - } - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } - - return result; - } - - public boolean addNewsEntry(String newsEntry) - { - int result = 0; - int maxPos = retrieveMaxNewsPosition(); - PreparedStatement preparedStatement = null; - - try (Connection connection = DBPool.getMineplex().getConnection()) - { - preparedStatement = connection.prepareStatement(ADD_NEWS_ENTRY); - preparedStatement.setString(1, newsEntry); - preparedStatement.setInt(2, maxPos + 1); - - result = preparedStatement.executeUpdate(); - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } - - return result != 0; - } - - public boolean deleteNewsEntry(int newsPosition) - { - int result = 0; - int maxPos = retrieveMaxNewsPosition(); - PreparedStatement preparedStatement = null; - - try (Connection connection = DBPool.getMineplex().getConnection()) - { - //preparedStatement = connection.prepareStatement(DELETE_RECALC_NEWS_ENTRY); - preparedStatement = connection.prepareStatement(DELETE_NEWS_ENTRY); - preparedStatement.setInt(1, newsPosition); - result = preparedStatement.executeUpdate(); - - if (result != 0 && maxPos != newsPosition) - { - preparedStatement.close(); - - preparedStatement = connection.prepareStatement(RECALC_NEWS_POSITIONS); - preparedStatement.setInt(1, newsPosition); - - result = preparedStatement.executeUpdate(); - } - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } - - return result != 0; - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubType.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubType.java deleted file mode 100644 index 4b058b45f..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubType.java +++ /dev/null @@ -1,8 +0,0 @@ -package mineplex.hub; - -public enum HubType -{ - Normal, - Halloween, - Christmas -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/brawl/fountain/FountainManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/brawl/fountain/FountainManager.java deleted file mode 100644 index 5bbeb6618..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/brawl/fountain/FountainManager.java +++ /dev/null @@ -1,78 +0,0 @@ -package mineplex.hub.brawl.fountain; - -import java.util.Calendar; -import java.util.TimeZone; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.MiniPlugin; -import mineplex.core.common.util.F; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.hub.server.ServerManager; - -public class FountainManager extends MiniPlugin -{ - private final ServerManager _serverManager; - private boolean _brawlActive = false; - - public FountainManager(JavaPlugin plugin, ServerManager serverManager) - { - super("Counter", plugin); - _serverManager = serverManager; - } - - @EventHandler - public void updateFountainCount(UpdateEvent event) - { - if (event.getType() != UpdateType.SEC) - return; - - updateBrawlActive(); - } - - public void updateBrawlActive() - { - Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("PST")); - int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); - _brawlActive = dayOfWeek == Calendar.FRIDAY || dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY; - } - - @EventHandler - public void onInteractAtEntity(PlayerInteractAtEntityEvent event) - { - tryBrawl(event.getPlayer(), event.getRightClicked()); - } - - @EventHandler - public void onDamage(EntityDamageByEntityEvent event) - { - if (event.getDamager() instanceof Player) - { - tryBrawl((Player) event.getDamager(), event.getEntity()); - } - } - - private void tryBrawl(Player player, Entity entity) - { - if (entity.getCustomName() != null && entity.isCustomNameVisible()) - { - if (entity.getCustomName().contains("Weekend Brawl")) - { - if (_brawlActive) - { - _serverManager.getBrawlShop().attemptShopOpen(player); - } - else - { - player.sendMessage(F.main("BRAWL", "Come back this weekend to play Weekend Brawl!")); - } - } - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/brawlfountain/FountainManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/brawlfountain/FountainManager.java new file mode 100644 index 000000000..967272524 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/brawlfountain/FountainManager.java @@ -0,0 +1,73 @@ +package mineplex.hub.brawlfountain; + +import java.util.Calendar; +import java.util.TimeZone; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.F; +import mineplex.core.newnpc.NPC; +import mineplex.core.newnpc.NewNPCManager; +import mineplex.core.newnpc.event.NPCInteractEvent; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.server.ServerManager; + +@ReflectivelyCreateMiniPlugin +public class FountainManager extends MiniPlugin +{ + + private final ServerManager _serverManager; + private NPC _npc; + private boolean _brawlActive = false; + + public FountainManager() + { + super("Brawl"); + + _serverManager = require(ServerManager.class); + require(NewNPCManager.class).spawnNPCs("BRAWL", npc -> _npc = npc); + } + + @EventHandler + public void updateFountainCount(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW) + { + return; + } + + updateBrawlActive(); + } + + private void updateBrawlActive() + { + Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("PST")); + int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); + _brawlActive = dayOfWeek == Calendar.FRIDAY || dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY; + } + + @EventHandler + public void npcInteract(NPCInteractEvent event) + { + if (!event.getNpc().equals(_npc)) + { + return; + } + + Player player = event.getPlayer(); + + if (_brawlActive) + { + _serverManager.getBrawlShop().attemptShopOpen(player); + } + else + { + player.sendMessage(F.main(_moduleName, "Come back this weekend to play Weekend Brawl!")); + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/GadgetToggle.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/GadgetToggle.java index ab51becd5..f2553cc4c 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/GadgetToggle.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/GadgetToggle.java @@ -15,6 +15,6 @@ public class GadgetToggle extends CommandBase @Override public void Execute(Player caller, String[] args) { - Plugin.ToggleGadget(caller); + Plugin.toggleGadget(); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/GameModeCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/GameModeCommand.java deleted file mode 100644 index 91122febb..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/GameModeCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package mineplex.hub.commands; - -import org.bukkit.GameMode; -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.hub.HubManager; - -public class GameModeCommand extends CommandBase -{ - public GameModeCommand(HubManager plugin) - { - super(plugin, HubManager.Perm.GAMEMODE_COMMAND, "gm"); - } - - @Override - public void Execute(Player caller, String[] args) - { - Player target = caller; - - if (args != null && args.length >= 1) - { - target = UtilPlayer.searchOnline(caller, args[0], true); - - if (target == null) - return; - } - - if (target.getGameMode() == GameMode.SURVIVAL) - target.setGameMode(GameMode.CREATIVE); - else - target.setGameMode(GameMode.SURVIVAL); - - if (!target.equals(caller)) - { - Plugin.addGameMode(caller, target); - UtilPlayer.message(target, F.main("Game Mode", caller.getName() + " toggled your Creative Mode: " + F.tf(target.getGameMode() == GameMode.CREATIVE))); - } - - UtilPlayer.message(caller, F.main("Game Mode", target.getName() + " Creative Mode: " + F.tf(target.getGameMode() == GameMode.CREATIVE))); - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/HorseSpawn.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/HorseSpawn.java deleted file mode 100644 index 223699324..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/HorseSpawn.java +++ /dev/null @@ -1,20 +0,0 @@ -package mineplex.hub.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.hub.modules.AdminMountManager; - -public class HorseSpawn extends CommandBase -{ - public HorseSpawn(AdminMountManager plugin) - { - super(plugin, AdminMountManager.Perm.HORSE_COMMAND, "horse"); - } - - @Override - public void Execute(Player caller, String[] args) - { - Plugin.HorseCommand(caller, args); - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewYearCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewYearCommand.java deleted file mode 100644 index 18c44b660..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewYearCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -package mineplex.hub.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.hub.modules.NewYearCountdown; -import mineplex.hub.modules.newyear.NewYearMessage; - -/** - * Created by William (WilliamTiger). - * 29/12/15 - */ -public class NewYearCommand extends CommandBase -{ - public NewYearCommand(NewYearCountdown plugin) - { - super(plugin, NewYearCountdown.Perm.NEW_YEARS_COMMAND, "newyear", "nycountdown", "nyc"); - } - - @Override - public void Execute(Player caller, String[] args) - { - if (Plugin.isInProgress()) - { - caller.sendMessage(F.main("NYC", C.cRed + "A new year countdown event is already in progress!")); - return; - } - - if (args.length != 3) - { - caller.sendMessage(F.main("NYC", C.cRed + "/newyear ")); - return; - } - - if (!(validateInteger(args[0]) && validateInteger(args[1]) && validateInteger(args[2]))) - { - caller.sendMessage(F.main("NYC", C.cRed + "You have entered invalid hours/minutes/seconds.")); - return; - } - - int hours = Integer.valueOf(args[0]); - int mins = Integer.valueOf(args[1]); - int secs = Integer.valueOf(args[2]); - int total = secs + (mins * 60) + (hours * 60 * 60); - - caller.sendMessage(F.main("NYC", "Sent command to all lobbies to start with " + F.elem(total + "") + " seconds.")); - new NewYearMessage(total).publish(); - } - - private boolean validateInteger(String str) - { - try - { - Integer.valueOf(str); - - return true; - } - catch (Exception e) - { - return false; - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsAddCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsAddCommand.java deleted file mode 100644 index f43da9005..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsAddCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package mineplex.hub.commands; - -import net.md_5.bungee.api.ChatColor; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.hub.HubManager; -import mineplex.hub.modules.NewsManager; - -public class NewsAddCommand extends CommandBase -{ - public NewsAddCommand(HubManager plugin) - { - super(plugin, HubManager.Perm.NEWS_COMMAND, "add"); - } - - @Override - public void Execute(final Player caller, final String[] args) - { - if (args == null || args.length == 0 || args.length > 128) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!")); - return; - } - else - { - NewsManager newsMang = Plugin.GetNewsManager(); - - String newsEntry = ""; - for (int i = 0; i < args.length; i++) - { - newsEntry += args[i] + " "; - } - newsEntry = ChatColor.translateAlternateColorCodes('&', newsEntry.substring(0, newsEntry.length() - 1)); - - // Check for 256 character length for MySQL! - if (newsEntry.length() > 256) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "The specified news entry is too long [> 256 characters]!")); - return; - } - - final String entry = newsEntry; - - newsMang.AddNewsEntry(entry, success -> - { - if (success) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cGray + "The news entry: " + C.cGold + entry + C.cGray + " has been added to the database!")); - } - else - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "There was an error adding the news entry to the database!")); - } - }); - return; - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java deleted file mode 100644 index 3109b2fb0..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsCommand.java +++ /dev/null @@ -1,26 +0,0 @@ -package mineplex.hub.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.MultiCommandBase; -import mineplex.hub.HubManager; - -public class NewsCommand extends MultiCommandBase -{ - public NewsCommand(HubManager plugin) - { - super(plugin, HubManager.Perm.NEWS_COMMAND, "news"); - - AddCommand(new NewsAddCommand(plugin)); - AddCommand(new NewsDeleteCommand(plugin)); - AddCommand(new NewsConfirmCommand(plugin)); - AddCommand(new NewsListCommand(plugin)); - AddCommand(new NewsSetCommand(plugin)); - } - - @Override - protected void Help(Player caller, String args[]) - { - Plugin.GetNewsManager().Help(caller); - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsConfirmCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsConfirmCommand.java deleted file mode 100644 index 43eb186ac..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsConfirmCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package mineplex.hub.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.hub.HubManager; - -public class NewsConfirmCommand extends CommandBase -{ - public NewsConfirmCommand(HubManager plugin) - { - super(plugin, HubManager.Perm.NEWS_COMMAND, "¢¤₦₣¡₨₥"); - } - - @Override - public void Execute(Player caller, String[] args) - { - if (args == null || args.length == 0 || args.length > 1) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!")); - return; - } - else - { - int newsPosition; - try - { - newsPosition = Integer.parseInt(args[0]); - } - catch (Exception exception) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "The specified news position is invalid!")); - return; - } - - UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.getName() + "> \", color:blue, \"extra\":[{\"text\":\"[CONFIRM] \", color:green, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news delete " + newsPosition + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Are you absolutely sure???\"}}, {\"text\":\"News Entry " + newsPosition + "\", color:gold}, {\"text\":\" deletion?\", color:gray}]}"); - return; - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsDeleteCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsDeleteCommand.java deleted file mode 100644 index 7b27eae45..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsDeleteCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -package mineplex.hub.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.hub.HubManager; -import mineplex.hub.modules.NewsManager; - -public class NewsDeleteCommand extends CommandBase -{ - public NewsDeleteCommand(HubManager plugin) - { - super(plugin, HubManager.Perm.NEWS_COMMAND, "delete"); - } - - @Override - public void Execute(final Player caller, String[] args) - { - if (args == null || args.length == 0 || args.length > 1) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!")); - return; - } - else - { - NewsManager newsMang = Plugin.GetNewsManager(); - final int newsPosition; - try - { - newsPosition = Integer.parseInt(args[0]); - } - catch (Exception exception) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "The specified news position is invalid!")); - return; - } - newsMang.DeleteNewsEntry(newsPosition, success -> - { - if (success) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been deleted!")); - } - else - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "There was an error deleting the news entry; likely the specified news position was invalid!")); - } - }); - return; - } - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsListCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsListCommand.java deleted file mode 100644 index d281de462..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsListCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -package mineplex.hub.commands; - -import java.util.Iterator; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.hub.HubManager; -import mineplex.hub.modules.NewsManager; - -public class NewsListCommand extends CommandBase -{ - public NewsListCommand(HubManager plugin) - { - super(plugin, HubManager.Perm.NEWS_COMMAND, "list"); - } - - @Override - public void Execute(final Player caller, String[] args) - { - if (args == null || args.length == 0) - { - final NewsManager newsMang = Plugin.GetNewsManager(); - - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cGray + "Current server news messages:")); - - newsMang.RetriveNewsEntries(entries -> - { - // Order newsEntries set or its output by newsPosition, not hash order... - newsMang.RetrieveMaxNewsPosition(maxPosition -> - { - String[] newsStrings = new String[maxPosition]; - for (Iterator iterator = entries.keySet().iterator(); iterator.hasNext();) - { - String newsPosition = iterator.next(); - newsStrings[Integer.parseInt(newsPosition) - 1] = entries.get(newsPosition); - } - - for (int i = 0; i < newsStrings.length; i++) - { - UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.getName() + "> \", color:blue, \"extra\":[{\"text\":\"[DELETE] \", color:red, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news ¢¤₦₣¡₨₥ " + (i + 1) + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Deletes News Entry " + (i + 1) + " : " + newsStrings[i] + "\"}}, {\"text\":\"News " + (i + 1) + "\", color:gold}, {\"text\":\" : \", color:gray}, {\"text\":\"" + newsStrings[i] + "\", color:white}]}"); - } - }); - }); - return; - } - else - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!")); - return; - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsSetCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsSetCommand.java deleted file mode 100644 index 5d001709c..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewsSetCommand.java +++ /dev/null @@ -1,73 +0,0 @@ -package mineplex.hub.commands; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.hub.HubManager; -import mineplex.hub.modules.NewsManager; - -public class NewsSetCommand extends CommandBase -{ - public NewsSetCommand(HubManager plugin) - { - super(plugin, HubManager.Perm.NEWS_COMMAND, "set"); - } - - @Override - public void Execute(final Player caller, final String[] args) - { - if (args == null || args.length < 2 || args.length > 128) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!")); - return; - } - else - { - NewsManager newsMang = Plugin.GetNewsManager(); - - final int newsPosition; - String newsEntry = ""; - for (int i = 1; i < args.length; i++) - { - newsEntry += args[i] + " "; - } - newsEntry = ChatColor.translateAlternateColorCodes('&', newsEntry.substring(0, newsEntry.length() - 1)); - - // Check for 256 character length for MySQL! - if (newsEntry.length() > 256) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "The specified news entry is too long [> 256 characters]!")); - return; - } - - try - { - newsPosition = Integer.parseInt(args[0]); - } - catch (Exception exception) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "The specified news position is invalid!")); - return; - } - - final String entry = newsEntry; - - newsMang.SetNewsEntry(entry, newsPosition, success -> - { - if (success) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been updated to: " + C.cGold + entry + C.cGray + "!")); - } - else - { - UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "There was an error updating the news entry; likely the specified news position was invalid!")); - } - }); - return; - } - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/doublejump/DoubleJumpPrepareEvent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/doublejump/DoubleJumpPrepareEvent.java new file mode 100644 index 000000000..fc238ec62 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/doublejump/DoubleJumpPrepareEvent.java @@ -0,0 +1,43 @@ +package mineplex.hub.doublejump; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class DoubleJumpPrepareEvent extends PlayerEvent implements Cancellable +{ + + private static final HandlerList _handlers = new HandlerList(); + + private boolean _cancelled; + + public DoubleJumpPrepareEvent(Player who) + { + super(who); + } + + @Override + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } + + @Override + public boolean isCancelled() + { + return _cancelled; + } + + public static HandlerList getHandlerList() + { + return _handlers; + } + + @Override + public HandlerList getHandlers() + { + return getHandlerList(); + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/JumpManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/doublejump/JumpManager.java similarity index 74% rename from Plugins/Mineplex.Hub/src/mineplex/hub/modules/JumpManager.java rename to Plugins/Mineplex.Hub/src/mineplex/hub/doublejump/JumpManager.java index 9486e9014..24e867d2d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/JumpManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/doublejump/JumpManager.java @@ -1,11 +1,10 @@ -package mineplex.hub.modules; +package mineplex.hub.doublejump; import java.util.HashSet; import java.util.Set; import org.bukkit.Effect; import org.bukkit.GameMode; -import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerQuitEvent; @@ -14,7 +13,6 @@ import org.bukkit.util.Vector; import mineplex.core.MiniPlugin; import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilServer; import mineplex.core.disguise.disguises.DisguiseBase; @@ -33,16 +31,16 @@ public class JumpManager extends MiniPlugin public HubManager Manager; private Set _preparedDoubleJump = new HashSet<>(); - + public JumpManager(HubManager manager) { super("Double Jump", manager.getPlugin()); - + Manager = manager; } @EventHandler - public void FlightHop(PlayerToggleFlightEvent event) + public void toggleFlight(PlayerToggleFlightEvent event) { Player player = event.getPlayer(); @@ -55,17 +53,17 @@ public class JumpManager extends MiniPlugin { return; } - + //Chicken Cancel DisguiseBase disguise = Manager.GetDisguise().getActiveDisguise(player); - if (disguise != null && - ((disguise instanceof DisguiseChicken && !((DisguiseChicken)disguise).isBaby()) || disguise instanceof DisguiseBat || disguise instanceof DisguiseEnderman || disguise instanceof DisguiseWither)) + if (disguise != null && + ((disguise instanceof DisguiseChicken && !((DisguiseChicken) disguise).isBaby()) || disguise instanceof DisguiseBat || disguise instanceof DisguiseEnderman || disguise instanceof DisguiseWither)) return; - + event.setCancelled(true); - player.setFlying(false); //Disable Flight + player.setFlying(false); player.setAllowFlight(false); Vector vec = player.getLocation().getDirection(); @@ -77,42 +75,48 @@ public class JumpManager extends MiniPlugin //Sound player.playEffect(player.getLocation(), Effect.BLAZE_SHOOT, 0); - + Recharge.Instance.useForce(player, "Double Jump", 250); } @EventHandler - public void FlightUpdate(UpdateEvent event) + public void updateFlight(UpdateEvent event) { if (event.getType() != UpdateType.TICK) + { return; + } - for (Player player : UtilServer.getPlayers()) + for (Player player : UtilServer.getPlayersCollection()) { if (player.getGameMode() == GameMode.CREATIVE) + { continue; + } - if (Manager.getPreferences().get(player).isActive(Preference.INVISIBILITY) && Manager.GetClients().Get(player).hasPermission(Preference.INVISIBILITY)) + // TODO put this somewhere better + if (Manager.getPreferences().get(player).isActive(Preference.INVISIBILITY) && Manager.GetClients().Get(player).hasPermission(Preference.INVISIBILITY)) { player.setAllowFlight(true); continue; } - - if (Manager.GetParkour().isParkourMode(player)) + + DoubleJumpPrepareEvent jumpEvent = new DoubleJumpPrepareEvent(player); + UtilServer.CallEvent(jumpEvent); + + if (jumpEvent.isCancelled()) { - player.setAllowFlight(false); player.setFlying(false); + player.setAllowFlight(false); continue; } - - if (UtilEnt.isGrounded(player) || UtilBlock.solid(player.getLocation().getBlock().getRelative(BlockFace.DOWN))) + + //if (UtilEnt.isGrounded(player) || UtilBlock.solid(player.getLocation().getBlock().getRelative(BlockFace.DOWN))) + if (UtilEnt.onBlock(player) && !player.getAllowFlight() && Recharge.Instance.usable(player, "Double Jump")) { - if(!player.getAllowFlight() && Recharge.Instance.usable(player, "Double Jump")) - { - player.setAllowFlight(true); - player.setFlying(false); - _preparedDoubleJump.remove(player.getName()); - } + player.setAllowFlight(true); + player.setFlying(false); + _preparedDoubleJump.remove(player.getName()); } } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/AdminPunch.java b/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/AdminPunch.java new file mode 100644 index 000000000..32e860db3 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/AdminPunch.java @@ -0,0 +1,125 @@ +package mineplex.hub.gimmicks; + +import java.util.HashSet; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.util.Vector; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.permissions.Permission; +import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.command.CommandBase; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.recharge.Recharge; + +@ReflectivelyCreateMiniPlugin +public class AdminPunch extends MiniPlugin +{ + + public enum Perm implements Permission + { + PUNCH_COMMAND + } + + private static final Vector UP = new Vector(0, 8, 0); + + private final Set _active; + + private AdminPunch() + { + super("Rocket Punch"); + + _active = new HashSet<>(); + + generatePermissions(); + + addCommand(new CommandBase(this, Perm.PUNCH_COMMAND, "mystery") + { + @Override + public void Execute(Player caller, String[] args) + { + toggleState(caller); + } + }); + } + + private void generatePermissions() + { + PermissionGroup.ADMIN.setPermission(Perm.PUNCH_COMMAND, true, true); + } + + private void toggleState(Player player) + { + if (_active.remove(player)) + { + player.sendMessage(F.main(_moduleName, "Disabled " + F.name(_moduleName) + "!")); + } + else + { + _active.add(player); + player.sendMessage(F.main(_moduleName, "Enabled " + F.name(_moduleName) + "!")); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void entityDamage(PlayerInteractEvent event) + { + if (!UtilEvent.isAction(event, ActionType.L)) + { + return; + } + + Player player = event.getPlayer(); + + for (Player other : UtilPlayer.getNearby(player.getLocation(), 4)) + { + if (player.equals(other)) + { + continue; + } + + punch(player, other); + } + } + + private void punch(Player damager, Player damagee) + { + if (!_active.contains(damager) || + !Recharge.Instance.use(damager, _moduleName, 100, false, false) || + !Recharge.Instance.use(damager, _moduleName + damagee.getName(), 1000, false, false)) + { + return; + } + + Location location = damagee.getLocation().add(0, 1, 0); + + UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, location, 0, 0, 0, 0.1F, 1, ViewDist.LONG); + UtilParticle.PlayParticleToAll(ParticleType.LAVA, location, 5, 0.5F, 5, 0.1F, 20, ViewDist.LONG); + location.getWorld().playSound(location, Sound.EXPLODE, 3, 0.5F); + + UtilAction.velocity(damagee, UP); + Bukkit.broadcastMessage(F.main(_moduleName, F.name(damager.getName()) + " punched " + F.name(damagee.getName()) + " into the air!")); + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + _active.remove(event.getPlayer()); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/StaffBuild.java b/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/StaffBuild.java new file mode 100644 index 000000000..b256595bd --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/StaffBuild.java @@ -0,0 +1,128 @@ +package mineplex.hub.gimmicks; + +import java.util.List; + +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.account.permissions.Permission; +import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.player.CreativeManager; +import mineplex.hub.player.HubPlayerManager; +import mineplex.hub.world.WorldDataModule; + +@ReflectivelyCreateMiniPlugin +public class StaffBuild extends MiniPlugin +{ + + public enum Perm implements Permission + { + BUILD + } + + private static final int MAX_Y_DIFFERENCE = 50; + + private final CoreClientManager _clientManager; + private final CreativeManager _creativeManager; + private final HubPlayerManager _playerManager; + private final List _buildLocations; + + private StaffBuild() + { + super("Staff Build"); + + _clientManager = require(CoreClientManager.class); + _creativeManager = require(CreativeManager.class); + _playerManager = require(HubPlayerManager.class); + _buildLocations = require(WorldDataModule.class).getCustomLocation(String.valueOf(Material.RED_SANDSTONE.getId())); + _buildLocations.forEach(location -> location.getBlock().setType(Material.AIR)); + + generatePermissions(); + } + + private void generatePermissions() + { + PermissionGroup.BUILDER.setPermission(Perm.BUILD, true, true); + } + + @EventHandler + public void updateCreative(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + for (Player player : UtilServer.getPlayersCollection()) + { + boolean allowed = isAllowed(player, player.getLocation()); + boolean creative = player.getGameMode() == GameMode.CREATIVE; + + if (allowed && !creative) + { + player.setGameMode(GameMode.CREATIVE); + sendMessage(player, true); + player.getInventory().clear(); + } + else if (!allowed && creative) + { + player.setGameMode(GameMode.ADVENTURE); + sendMessage(player, false); + _playerManager.giveHotbar(player); + } + } + } + + private void sendMessage(Player player, boolean enabled) + { + player.sendMessage(F.main(_moduleName, "Build mode " + F.ed(enabled) + ".")); + } + + @EventHandler + public void blockBreak(BlockBreakEvent event) + { + event.setCancelled(!isAllowed(event.getPlayer(), event.getBlock().getLocation())); + } + + @EventHandler + public void blockPlace(BlockPlaceEvent event) + { + event.setCancelled(!isAllowed(event.getPlayer(), event.getBlock().getLocation())); + } + + private boolean isAllowed(Player player, Location location) + { + if (_creativeManager.isInCreative(player)) + { + return true; + } + else if (!_clientManager.Get(player).hasPermission(Perm.BUILD)) + { + return false; + } + + for (Location buildLocation : _buildLocations) + { + int delta = location.getBlockY() - buildLocation.getBlockY(); + + if (location.getBlockX() == buildLocation.getBlockX() && location.getBlockZ() == buildLocation.getBlockZ() && delta >= 0 && delta < MAX_Y_DIFFERENCE) + { + return true; + } + } + + return false; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/CycledGame.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/CycledGame.java new file mode 100644 index 000000000..1dda5ca21 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/CycledGame.java @@ -0,0 +1,179 @@ +package mineplex.hub.hubgame; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.Player; + +import mineplex.core.common.util.UtilServer; +import mineplex.hub.hubgame.event.HubGamePlayerDeathEvent; +import mineplex.hub.hubgame.event.HubGameStateChangeEvent; + +public abstract class CycledGame extends HubGame +{ + + // Game Properties + private GameState _state; + + // Game Timer + private long _lastStart; + + // Players + private final List _queuedPlayers; + private final List _alivePlayers; + private final List _allPlayers; + private final List _places; + + // Lobby + private int _countdown; + + public CycledGame(HubGameManager manager, HubGameType type) + { + super(manager, type); + + _state = GameState.Waiting; + + _queuedPlayers = new ArrayList<>(); + _alivePlayers = new ArrayList<>(type.getMaxPlayers()); + _allPlayers = new ArrayList<>(type.getMaxPlayers()); + _places = new ArrayList<>(type.getMaxPlayers()); + + _countdown = -1; + } + + @Override + public List getAlivePlayers() + { + return _alivePlayers; + } + + public List getAllPlayers() + { + return _allPlayers; + } + + /* + Game Events + */ + + public void onPrepare() + { + } + + public void onLive() + { + } + + public abstract boolean endCheck(); + + public void onEnd() + { + } + + public void onCleanup() + { + _alivePlayers.clear(); + _allPlayers.clear(); + _places.clear(); + } + + /* + Player Events + */ + + public void onPlayerQueue(Player player) + { + } + + public void onPlayerLeaveQueue(Player player) + { + } + + @Override + public void onPlayerDeath(Player player) + { + onPlayerDeath(player, false); + } + + public void onPlayerDeath(Player player, boolean end) + { + HubGamePlayerDeathEvent event = new HubGamePlayerDeathEvent(player, this, end); + UtilServer.CallEvent(event); + } + + @Override + public void onCleanupPlayer(Player player) + { + _queuedPlayers.remove(player); + _alivePlayers.remove(player); + _allPlayers.remove(player); + _places.remove(player); + } + + public boolean isLive() + { + return _state == GameState.Live; + } + + public void setState(GameState state) + { + _state = state; + + switch (state) + { + case Prepare: + onPrepare(); + break; + case Live: + _lastStart = System.currentTimeMillis(); + onLive(); + break; + } + + UtilServer.CallEvent(new HubGameStateChangeEvent(this, state)); + setPhase(state); + } + + public GameState getGameState() + { + return _state; + } + + public long getLastStart() + { + return _lastStart; + } + + public List getQueuedPlayers() + { + return _queuedPlayers; + } + + public List getNextPlayers() + { + return _queuedPlayers.subList(0, Math.min(_queuedPlayers.size(), getGameType().getMaxPlayers())); + } + + public List getPlaces() + { + return _places; + } + + public void setCountdown(int countdown) + { + _countdown = countdown; + } + + public int getCountdown() + { + return _countdown; + } + + public enum GameState + { + + Waiting, Prepare, Live, End + + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGame.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGame.java new file mode 100644 index 000000000..150853d8a --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGame.java @@ -0,0 +1,103 @@ +package mineplex.hub.hubgame; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +import mineplex.core.Managers; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilServer; +import mineplex.core.lifetimes.PhasedLifetime; +import mineplex.core.newnpc.NPC; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.common.HubGameComponent; +import mineplex.hub.hubgame.ui.HubGamePage; +import mineplex.hub.world.WorldDataModule; + +public abstract class HubGame extends PhasedLifetime implements Listener +{ + + private final HubGameManager _manager; + private final HubGameType _type; + private final Map>, HubGameComponent> _components; + + protected final WorldDataModule _worldData; + + private final Location _spawn; + + public HubGame(HubGameManager manager, HubGameType type) + { + _manager = manager; + _type = type; + _components = new HashMap<>(); + + _worldData = Managers.require(WorldDataModule.class); + _spawn = _worldData.getCustomLocation(type.name() + " SPAWN").get(0); + + start(GameState.Waiting); + UtilServer.RegisterEvents(this); + } + + public abstract void onPlayerDeath(Player player); + + public abstract List getAlivePlayers(); + + public abstract void onCleanupPlayer(Player player); + + public HubGameManager getManager() + { + return _manager; + } + + public HubGameType getGameType() + { + return _type; + } + + @SuppressWarnings("unchecked") + protected > T registerComponent(T instance) + { + _components.put((Class>) instance.getClass(), instance); + register(instance); + return instance; + } + + @SuppressWarnings("unchecked") + public > T getComponent(Class clazz) + { + return (T) _components.get(clazz); + } + + public void setNpc(NPC npc) + { + if (npc.getEntity() != null) + { + _spawn.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(_spawn, npc.getEntity().getLocation()))); + } + } + + public Location getSpawn() + { + return _spawn; + } + + public boolean isAlive(Player player) + { + return getAlivePlayers().contains(player); + } + + public void announce(String message) + { + getAlivePlayers().forEach(player -> player.sendMessage(F.main(getManager().getName(), message))); + } + + public HubGamePage getInformationPage(Player player) + { + return new HubGamePage<>(getManager(), getManager().getShop(), getManager().getClientManager(), getManager().getDonationManager(), player, this); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java new file mode 100644 index 000000000..3f482055f --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java @@ -0,0 +1,453 @@ +package mineplex.hub.hubgame; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerQuitEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.donation.DonationManager; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.types.GadgetType; +import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.HologramManager; +import mineplex.core.newnpc.NPC; +import mineplex.core.newnpc.NewNPCManager; +import mineplex.core.newnpc.event.NPCInteractEvent; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.event.HubGamePlayerDeathEvent; +import mineplex.hub.hubgame.ui.HubGameShop; +import mineplex.hub.player.HubPlayerManager; +import mineplex.hub.world.WorldDataModule; + +@ReflectivelyCreateMiniPlugin +public class HubGameManager extends MiniPlugin +{ + + private static final int MIN_PLAYERS_COUNTDOWN = 20; + private static final int MAX_PLAYERS_COUNTDOWN = 5; + private static final int PREPARE_COUNTDOWN = 5; + private static final String HEADER_FOOTER = C.cDGreen + C.Strike + "================================================"; + + public static String getHeaderFooter() + { + return HEADER_FOOTER; + } + + private final CoreClientManager _clientManager; + private final DonationManager _donationManager; + private final GadgetManager _gadgetManager; + private final HologramManager _hologramManager; + private final HubPlayerManager _hotbarManager; + private final NewNPCManager _npcManager; + private final WorldDataModule _worldData; + + private final HubGameShop _shop; + private final List _games; + + private HubGameManager() + { + super("Hub Games"); + + _clientManager = require(CoreClientManager.class); + _donationManager = require(DonationManager.class); + _gadgetManager = require(GadgetManager.class); + _hologramManager = require(HologramManager.class); + _hotbarManager = require(HubPlayerManager.class); + _npcManager = require(NewNPCManager.class); + _worldData = require(WorldDataModule.class); + + _shop = new HubGameShop(this, _clientManager, _donationManager); + _games = new ArrayList<>(); + + runSyncLater(this::spawnNPCs, 50); + } + + public void addGame(HubGame game) + { + _games.add(game); + } + + private void spawnNPCs() + { + _games.forEach(game -> + { + _npcManager.spawnNPCs(game.getGameType().name(), npc -> + { + game.setNpc(npc); + Hologram nameTag = npc.getNameTag(); + + nameTag.setText(C.cYellowB + "Click To Play", nameTag.getText()[0]); + }); + + new Hologram(_hologramManager, _worldData.getCustomLocation(game.getGameType().name() + " INFO").get(0), true, game.getGameType().getDescription()) + .start(); + }); + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + _games.forEach(game -> game.onCleanupPlayer(event.getPlayer())); + } + + @EventHandler + public void npcInteract(NPCInteractEvent event) + { + if (event.isCancelled()) + { + return; + } + + NPC npc = event.getNpc(); + + for (HubGame game : _games) + { + if (!npc.getMetadata().equals(game.getGameType().name())) + { + continue; + } + + Player player = event.getPlayer(); + + if (game instanceof CycledGame) + { + CycledGame cycledGame = (CycledGame) game; + List queuedPlayers = cycledGame.getQueuedPlayers(); + + if (event.isLeftClick()) + { + if (queuedPlayers.contains(player)) + { + leaveQueue(cycledGame, player, false); + } + else + { + joinQueue(cycledGame, player); + } + } + else + { + showInformationPage(game, player); + } + } + else + { + showInformationPage(game, player); + } + + return; + } + } + + @SuppressWarnings("unchecked") + private void showInformationPage(HubGame game, Player player) + { + _shop.openPageForPlayer(player, game.getInformationPage(player)); + } + + private void disableGadgets(Player player, GadgetType type) + { + _gadgetManager.getGadgets(type).forEach(gadget -> gadget.disable(player)); + } + + public void joinQueue(CycledGame game, Player player) + { + for (HubGame other : _games) + { + if (other instanceof CycledGame && ((CycledGame) other).getQueuedPlayers().remove(player)) + { + leaveQueue((CycledGame) other, player, true); + } + } + + clearPlayer(player); + + disableGadgets(player, GadgetType.MORPH); + disableGadgets(player, GadgetType.MOUNT); + disableGadgets(player, GadgetType.COSTUME); + disableGadgets(player, GadgetType.ITEM); + disableGadgets(player, GadgetType.BALLOON); + disableGadgets(player, GadgetType.FLAG); + disableGadgets(player, GadgetType.HAT); + + player.sendMessage(F.main(_moduleName, "You have joined the queue for " + F.name(getGameName(game)) + ".")); + game.getQueuedPlayers().add(player); + game.onPlayerQueue(player); + informQueuePosition(game, player); + } + + public void leaveQueue(CycledGame game, Player player, boolean forAnother) + { + if (!forAnother) + { + _hotbarManager.giveHotbar(player); + } + + player.sendMessage(F.main(_moduleName, "You have left the queue for " + F.name(getGameName(game)) + ".")); + game.getQueuedPlayers().remove(player); + game.onPlayerLeaveQueue(player); + } + + private void informQueuePosition(CycledGame game, Player player) + { + int position = game.getQueuedPlayers().indexOf(player); + + if (position == -1) + { + return; + } + + player.sendMessage(F.main(_moduleName, "Your position in the queue for " + + F.name(getGameName(game)) + " is " + + F.elem((position + 1)) + "/" + + F.elem(game.getQueuedPlayers().size()) + + "!")); + } + + @EventHandler + public void updateLobby(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + for (HubGame game : _games) + { + if (!(game instanceof CycledGame)) + { + continue; + } + + CycledGame cycledGame = (CycledGame) game; + HubGameType gameType = game.getGameType(); + + if (cycledGame.getGameState() != GameState.Waiting) + { + continue; + } + + int countdown = cycledGame.getCountdown(); + int queuedSize = cycledGame.getQueuedPlayers().size(); + + // Initial start check + if (countdown == -1 && queuedSize >= gameType.getMinPlayers()) + { + int waitTime = MIN_PLAYERS_COUNTDOWN; + + if (queuedSize >= gameType.getMaxPlayers()) + { + waitTime = MAX_PLAYERS_COUNTDOWN; + } + + cycledGame.setCountdown(waitTime); + + for (Player player : cycledGame.getQueuedPlayers()) + { + player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 0.7F); + } + } + else if (countdown != -1 && isEnoughPlayers(cycledGame)) + { + // Start Game + if (countdown == 0 && isEnoughPlayers(cycledGame)) + { + List players = cycledGame.getNextPlayers(); + + cycledGame.getAlivePlayers().addAll(players); + cycledGame.getAllPlayers().addAll(players); + cycledGame.getQueuedPlayers().removeAll(players); + + cycledGame.setCountdown(PREPARE_COUNTDOWN); + cycledGame.setState(GameState.Prepare); + + for (Player player : cycledGame.getQueuedPlayers()) + { + informQueuePosition(cycledGame, player); + } + } + // Countdown + else if (countdown > 0) + { + cycledGame.setCountdown(countdown - 1); + + if (countdown < 10 || countdown % 10 == 0) + { + for (Player player : cycledGame.getNextPlayers()) + { + player.playSound(player.getLocation(), Sound.CLICK, 1, 0.6F); + player.sendMessage(F.main(_moduleName, F.elem(countdown) + " second" + (countdown == 1 ? "" : "s") + " until the game starts.")); + UtilTextMiddle.display("", C.cGreen + countdown, 0, 30, 0, player); + } + } + } + } + } + } + + // Ensure that prepare is run before the lobby update + @EventHandler(priority = EventPriority.LOW) + public void updatePrepare(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + for (HubGame game : _games) + { + if (!(game instanceof CycledGame)) + { + continue; + } + + CycledGame cycledGame = (CycledGame) game; + + if (cycledGame.getGameState() != GameState.Prepare) + { + continue; + } + + int countdown = cycledGame.getCountdown(); + + if (countdown == 0) + { + for (Player player : cycledGame.getAllPlayers()) + { + player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.2F); + } + + cycledGame.setState(GameState.Live); + } + else if (countdown <= 3) + { + for (Player player : cycledGame.getAllPlayers()) + { + player.playSound(player.getLocation(), Sound.CLICK, 1, 0.4F); + UtilTextMiddle.display("", C.cRed + countdown, 0, 30, 0, player); + } + } + + cycledGame.setCountdown(countdown - 1); + } + } + + @EventHandler + public void updateEnd(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + { + return; + } + + for (HubGame game : _games) + { + if (!(game instanceof CycledGame)) + { + continue; + } + + CycledGame cycledGame = (CycledGame) game; + + if (cycledGame.isLive() && cycledGame.endCheck()) + { + for (Player player : cycledGame.getAlivePlayers()) + { + cycledGame.onPlayerDeath(player, true); + } + + Collections.reverse(cycledGame.getPlaces()); + + cycledGame.onEnd(); + cycledGame.setState(GameState.End); + + cycledGame.onCleanup(); + cycledGame.setState(GameState.Waiting); + } + } + } + + private boolean isEnoughPlayers(CycledGame game) + { + boolean enough = game.getQueuedPlayers().size() >= game.getGameType().getMinPlayers(); + + if (!enough) + { + game.setCountdown(-1); + + for (Player player : game.getQueuedPlayers()) + { + player.sendMessage(F.main(_moduleName, "Not enough players.")); + UtilTextMiddle.display("", C.cRed + "Not enough players", 0, 30, 0, player); + } + } + + return enough; + } + + @EventHandler + public void playerDeath(HubGamePlayerDeathEvent event) + { + Player player = event.getPlayer(); + CycledGame game = event.getGame(); + + if (!event.isEnding()) + { + game.getAlivePlayers().remove(player); + } + + game.getPlaces().add(player); + clearPlayer(player); + player.teleport(game.getSpawn()); + _hotbarManager.giveHotbar(player); + } + + private void clearPlayer(Player player) + { + UtilPlayer.clearPotionEffects(player); + UtilPlayer.clearInventory(player); + player.leaveVehicle(); + player.eject(); + player.setFireTicks(0); + player.setHealth(player.getMaxHealth()); + } + + public String getGameHeader(CycledGame game) + { + return C.cWhiteB + "Game" + C.cYellow + " - " + C.cWhiteB + getGameName(game); + } + + private String getGameName(CycledGame game) + { + return game.getGameType().getName(); + } + + public CoreClientManager getClientManager() + { + return _clientManager; + } + + public DonationManager getDonationManager() + { + return _donationManager; + } + + public HubGameShop getShop() + { + return _shop; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameType.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameType.java new file mode 100644 index 000000000..5b7990525 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameType.java @@ -0,0 +1,68 @@ +package mineplex.hub.hubgame; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public enum HubGameType +{ + + TRON("Tron", new String[] + { + "Control your Slime by looking in", + "the direction you want to go!", + "Avoid other trails and walls.", + "Last player standing wins!", + }, new ItemStack(Material.SLIME_BALL), 2, 4), + DUELS("Duels", new String[] + { + "A 1v1 duel against another player.", + "You do not regenerate health.", + "You can place blocks!", + "Kill your opponent to win!" + }, new ItemStack(Material.DIAMOND_SWORD), 2, 2), + FOOTBALL("Soccer", new String[] + { + + }, new ItemStack(Material.SLIME_BALL), 1, 6), + ; + + private final String _name; + private final String[] _description; + private final ItemStack _itemStack; + private final int _minPlayers; + private final int _maxPlayers; + + HubGameType(String name, String[] description, ItemStack itemStack, int minPlayers, int maxPlayers) + { + _name = name; + _description = description; + _itemStack = itemStack; + _minPlayers = minPlayers; + _maxPlayers = maxPlayers; + } + + public String getName() + { + return _name; + } + + public String[] getDescription() + { + return _description; + } + + public ItemStack getItemStack() + { + return _itemStack; + } + + public int getMinPlayers() + { + return _minPlayers; + } + + public int getMaxPlayers() + { + return _maxPlayers; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/SimpleGame.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/SimpleGame.java new file mode 100644 index 000000000..5d1910bbf --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/SimpleGame.java @@ -0,0 +1,37 @@ +package mineplex.hub.hubgame; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.Player; + +public class SimpleGame extends HubGame +{ + + private final List _players; + + public SimpleGame(HubGameManager manager, HubGameType type) + { + super(manager, type); + + _players = new ArrayList<>(); + } + + @Override + public void onPlayerDeath(Player player) + { + player.teleport(getSpawn()); + } + + @Override + public List getAlivePlayers() + { + return _players; + } + + @Override + public void onCleanupPlayer(Player player) + { + _players.remove(player); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/HubGameComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/HubGameComponent.java new file mode 100644 index 000000000..d10943059 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/HubGameComponent.java @@ -0,0 +1,15 @@ +package mineplex.hub.hubgame.common; + +import mineplex.core.lifetimes.ListenerComponent; +import mineplex.hub.hubgame.HubGame; + +public class HubGameComponent extends ListenerComponent +{ + + protected final T _game; + + public HubGameComponent(T game) + { + _game = game; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/damage/DamageComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/damage/DamageComponent.java new file mode 100644 index 000000000..9c4e309de --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/damage/DamageComponent.java @@ -0,0 +1,100 @@ +package mineplex.hub.hubgame.common.damage; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; + +import mineplex.core.Managers; +import mineplex.core.common.util.UtilAction; +import mineplex.core.titles.Titles; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.HubGame; +import mineplex.hub.hubgame.common.HubGameComponent; +import mineplex.hub.hubgame.event.HubGameStateChangeEvent; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; + +public class DamageComponent extends HubGameComponent +{ + + private static final Titles TITLES = Managers.get(Titles.class); + + public DamageComponent(HubGame game) + { + super(game); + } + + @EventHandler + public void disableTitles(HubGameStateChangeEvent event) + { + if (event.getState() != GameState.Prepare && event.getState() != GameState.End) + { + return; + } + + for (Player player : _game.getAlivePlayers()) + { + if (event.getState() == GameState.Prepare) + { + TITLES.forceDisable(player); + } + else + { + TITLES.forceEnable(player); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void entityDamage(EntityDamageEvent event) + { + uncancelDamageEvent(event); + } + + private void uncancelDamageEvent(EntityDamageEvent event) + { + if (!(event.getEntity() instanceof Player)) + { + return; + } + + Player player = (Player) event.getEntity(); + + if (!_game.isAlive(player)) + { + return; + } + + event.setCancelled(false); + } + + @EventHandler + public void increaseKnockback(CustomDamageEvent event) + { + Player damagee = event.GetDamageePlayer(); + + if (damagee == null || !_game.isAlive(damagee)) + { + return; + } + + event.AddKnockback("Damage Component", 1.4); + } + + @EventHandler + public void playerDeath(CombatDeathEvent event) + { + Player player = (Player) event.GetEvent().getEntity(); + + if (!_game.isAlive(player)) + { + return; + } + + event.GetEvent().getDrops().clear(); + player.setHealth(player.getMaxHealth()); + UtilAction.zeroVelocity(player); + _game.onPlayerDeath(player); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/damage/PVPTrackerComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/damage/PVPTrackerComponent.java new file mode 100644 index 000000000..d43a92f21 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/damage/PVPTrackerComponent.java @@ -0,0 +1,418 @@ +package mineplex.hub.hubgame.common.damage; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerItemConsumeEvent; + +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.Color; +import mineplex.core.common.jsonchat.HoverEvent; +import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTextBottom; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.HubGame; +import mineplex.hub.hubgame.HubGameManager; +import mineplex.hub.hubgame.common.HubGameComponent; +import mineplex.hub.hubgame.event.HubGamePlayerDeathEvent; +import mineplex.hub.hubgame.event.HubGameStateChangeEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; + +public class PVPTrackerComponent extends HubGameComponent +{ + + private static final int MATCH_HISTORY_SIZE = 5; + private static final String STATS_COMMAND = "/duelstats"; + private static final String HEART = C.cRed + "❤" + C.Reset; + private static final DecimalFormat FORMAT = new DecimalFormat("0.#"); + + private final List _matches; + + public PVPTrackerComponent(HubGame game) + { + super(game); + + _matches = new ArrayList<>(); + } + + private Match getLatestMatch(Player player) + { + Match latest = null; + + for (Match match : _matches) + { + if (match.PlayerA.Player.equals(player) || match.PlayerB.Player.equals(player)) + { + latest = match; + } + } + + return latest; + } + + + private PVPStats getLatestStats(Player player) + { + PVPStats latest = null; + + for (Match match : _matches) + { + if (match.PlayerA.Player.equals(player)) + { + latest = match.PlayerA; + } + else if (match.PlayerB.Player.equals(player)) + { + latest = match.PlayerB; + } + } + + return latest; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void playerDeath(HubGamePlayerDeathEvent event) + { + Player player = event.getPlayer(); + Player killer = player.getKiller(); + + if (killer == null || !_game.isAlive(killer)) + { + return; + } + + PVPStats playerStats = getLatestStats(player); + PVPStats killerStats = getLatestStats(killer); + + playerStats.EndHealth = 0; + killerStats.EndHealth = killer.getHealth() / 2D; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void damage(CustomDamageEvent event) + { + if (event.isCancelled()) + { + return; + } + + Player damagee = event.GetDamageePlayer(); + Player damager = event.GetDamagerPlayer(true); + + if (damagee == null) + { + return; + } + + PVPStats damageeStats = getLatestStats(damagee); + + if (!_game.isAlive(damagee)) + { + return; + } + + damageeStats.CurrentCombo = 0; + damageeStats.DamageTaken += event.GetDamage(); + + if (damager == null) + { + return; + } + + PVPStats damagerStats = getLatestStats(damager); + + damagerStats.DamageDealt += event.GetDamage(); + + if (event.GetCause() == DamageCause.ENTITY_ATTACK) + { + UtilTextBottom.display(C.cGreen + FORMAT.format(damagee.getHealth() / 2D) + HEART, damager); + damagerStats.CurrentCombo++; + + if (damagerStats.CurrentCombo > damagerStats.MaxCombo) + { + damagerStats.MaxCombo = damagerStats.CurrentCombo; + } + + } + if (event.GetCause() == DamageCause.PROJECTILE) + { + damagerStats.ArrowsHit++; + + damager.sendMessage(F.main(_game.getManager().getName(), F.name(damagee.getName()) + " is at " + C.cRedB + FORMAT.format(damagee.getHealth() / 2D) + HEART + C.mBody + ".")); + } + } + + @EventHandler + public void appleEat(PlayerItemConsumeEvent event) + { + Player player = event.getPlayer(); + + if (event.getItem().getType() != Material.GOLDEN_APPLE || !_game.isAlive(player)) + { + return; + } + + getLatestStats(player).ApplesUsed++; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void blockPlace(BlockPlaceEvent event) + { + if (event.isCancelled()) + { + return; + } + + Player player = event.getPlayer(); + + if (!_game.isAlive(player)) + { + return; + } + + getLatestStats(player).BlocksPlaced++; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void blockBreak(BlockBreakEvent event) + { + if (event.isCancelled()) + { + return; + } + + Player player = event.getPlayer(); + + if (!_game.isAlive(player)) + { + return; + } + + getLatestStats(player).BlocksBroken++; + } + + @EventHandler + public void shootBow(EntityShootBowEvent event) + { + if (!(event.getEntity() instanceof Player)) + { + return; + } + + Player player = (Player) event.getEntity(); + + if (!_game.isAlive(player)) + { + return; + } + + getLatestStats(player).ArrowsShot++; + } + + @EventHandler + public void start(HubGameStateChangeEvent event) + { + if (event.getState() != GameState.Prepare || !event.getGame().equals(_game)) + { + return; + } + + if (_matches.size() >= MATCH_HISTORY_SIZE) + { + _matches.remove(0); + } + + List alive = _game.getAlivePlayers(); + Player a = alive.get(0); + Player b = alive.get(1); + + _matches.add(new Match(new PVPStats(a, b), new PVPStats(b, a))); + } + + @EventHandler + public void end(HubGameStateChangeEvent event) + { + if (event.getState() != GameState.Waiting || !event.getGame().equals(_game)) + { + return; + } + + UtilServer.runSyncLater(() -> + { + Match match = _matches.get(_matches.size() - 1); + match.Complete = true; + + for (Player player : match.getPlayers()) + { + player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 0.5F); + player.sendMessage(""); + new JsonMessage(" Click to view the match summary for this match! ") + .color(Color.GREEN) + .bold() + .click(ClickEvent.RUN_COMMAND, STATS_COMMAND) + .hover(HoverEvent.SHOW_TEXT, C.cYellow + "Click here to view the match summary.") + .sendToPlayer(player); + player.sendMessage(""); + } + }, 10); + } + + @EventHandler + public void command(PlayerCommandPreprocessEvent event) + { + if (!event.getMessage().equals(STATS_COMMAND)) + { + return; + } + + Player player = event.getPlayer(); + Match match = getLatestMatch(player); + + if (match == null) + { + return; + } + + event.setCancelled(true); + + if (!match.Complete) + { + player.sendMessage(F.main(_game.getManager().getName(), "Sorry but it seems that we cannot display the stats for that match anymore.")); + return; + } + + sendMatch(player, match); + } + + public void sendMatch(Player player, Match match) + { + boolean playerA = match.PlayerA.Player.equals(player); + boolean none = !playerA && !match.PlayerB.equals(player); + PVPStats stats = playerA || none ? match.PlayerA : match.PlayerB; + PVPStats other = playerA ? match.PlayerB : match.PlayerA; + + player.sendMessage(HubGameManager.getHeaderFooter()); + player.sendMessage(UtilText.centerChat(C.cGreenB + player.getName() + C.cWhite + " v " + C.cRedB + stats.Opponent.getName(), LineFormat.CHAT)); + player.sendMessage(""); + + sendStat(player, "Health", stats.EndHealth, other.EndHealth, HEART); + sendStat(player, "Damage Dealt", stats.DamageDealt, other.DamageDealt, HEART); + sendStat(player, "Damage Taken", stats.DamageTaken, other.DamageTaken, HEART); + sendStat(player, "Apples Used", stats.ApplesUsed, other.ApplesUsed, ""); + sendStat(player, "Blocks Placed", stats.BlocksPlaced, other.BlocksPlaced, ""); + sendStat(player, "Blocks Broken", stats.BlocksBroken, other.BlocksBroken, ""); + + new JsonMessage(getStatString( + "Bow Accuracy", + ((double) stats.ArrowsHit / Math.max(1, stats.ArrowsShot) * 100D), + ((double) other.ArrowsHit / Math.max(1, other.ArrowsShot) * 100D), + "%", false)) + .hover(HoverEvent.SHOW_TEXT, + getStatString("Arrows Shot", stats.ArrowsShot, other.ArrowsShot, "", true) + "\n" + + getStatString("Arrows Hit", stats.ArrowsHit, other.ArrowsHit, "", true) + ) + .sendToPlayer(player); + + sendStat(player, "Combo", stats.MaxCombo, other.MaxCombo, ""); + + player.sendMessage(""); + player.sendMessage(C.cDGreen + "Hover over values to find out more information!"); + player.sendMessage(HubGameManager.getHeaderFooter()); + } + + private void sendStat(Player player, String statName, double statA, double statB, String suffix) + { + sendStat(player, statName, statA, statB, suffix, false); + } + + private void sendStat(Player player, String statName, double statA, double statB, String suffix, boolean hoverText) + { + new JsonMessage(getStatString(statName, statA, statB, suffix, hoverText)) + .sendToPlayer(player); + } + + private String getStatString(String statName, double statA, double statB, String suffix, boolean hoverText) + { + boolean aHigher = statA > statB; + boolean equal = statA == statB; + String statString = + C.cGreen + (aHigher || equal ? C.Bold : "") + FORMAT.format(statA) + C.cWhite + suffix + + " v " + + C.cRed + (!aHigher || equal ? C.Bold : "") + FORMAT.format(statB) + C.cWhite + suffix; + + String output = C.cWhiteB + statName + " " + statString; + return hoverText ? output : UtilText.centerChat(output, LineFormat.CHAT); + } + + public List getMatches() + { + return _matches; + } + + public class Match + { + + PVPStats PlayerA; + PVPStats PlayerB; + long Start; + boolean Complete; + + Match(PVPStats playerA, PVPStats playerB) + { + PlayerA = playerA; + PlayerB = playerB; + Start = System.currentTimeMillis(); + } + + public Player[] getPlayers() + { + return new Player[]{PlayerA.Player, PlayerB.Player}; + } + + public long getStart() + { + return Start; + } + } + + private class PVPStats + { + + Player Player; + Player Opponent; + double EndHealth; + double DamageDealt; + double DamageTaken; + int ApplesUsed; + int BlocksPlaced; + int BlocksBroken; + int ArrowsShot; + int ArrowsHit; + int CurrentCombo; + int MaxCombo; + + PVPStats(Player player, Player opponent) + { + Player = player; + Opponent = opponent; + } + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/DoubleJumpComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/DoubleJumpComponent.java new file mode 100644 index 000000000..d13b1ea9c --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/DoubleJumpComponent.java @@ -0,0 +1,27 @@ +package mineplex.hub.hubgame.common.general; + +import org.bukkit.event.EventHandler; + +import mineplex.hub.doublejump.DoubleJumpPrepareEvent; +import mineplex.hub.hubgame.HubGame; +import mineplex.hub.hubgame.common.HubGameComponent; + +public class DoubleJumpComponent extends HubGameComponent +{ + + public DoubleJumpComponent(HubGame game) + { + super(game); + } + + @EventHandler + public void doubleJump(DoubleJumpPrepareEvent event) + { + if (!_game.isAlive(event.getPlayer())) + { + return; + } + + event.setCancelled(true); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/GameDescriptionComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/GameDescriptionComponent.java new file mode 100644 index 000000000..83ace22f7 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/GameDescriptionComponent.java @@ -0,0 +1,73 @@ +package mineplex.hub.hubgame.common.general; + +import java.util.function.Function; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.HubGameManager; +import mineplex.hub.hubgame.common.HubGameComponent; +import mineplex.hub.hubgame.event.HubGameStateChangeEvent; + +public class GameDescriptionComponent extends HubGameComponent +{ + + private final Function _customLines; + + public GameDescriptionComponent(CycledGame game) + { + this(game, null); + } + + public GameDescriptionComponent(CycledGame game, Function customLine) + { + super(game); + + _customLines = customLine; + } + + @EventHandler + public void displayDescription(HubGameStateChangeEvent event) + { + if (event.getState() != GameState.Prepare || !event.getGame().equals(_game)) + { + return; + } + + CycledGame game = event.getGame(); + + String gameString = _game.getManager().getGameHeader(game); + + for (Player player : game.getAllPlayers()) + { + player.sendMessage(HubGameManager.getHeaderFooter()); + player.sendMessage(gameString); + player.sendMessage(""); + + for (String description : game.getGameType().getDescription()) + { + player.sendMessage(" " + description); + } + + if (_customLines != null) + { + String line = _customLines.apply(player); + + if (line != null) + { + player.sendMessage(""); + player.sendMessage(" " + line); + } + } + + player.sendMessage(""); + player.sendMessage(HubGameManager.getHeaderFooter()); + + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1.2F); + } + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/GameTimeoutComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/GameTimeoutComponent.java new file mode 100644 index 000000000..f12271d92 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/GameTimeoutComponent.java @@ -0,0 +1,56 @@ +package mineplex.hub.hubgame.common.general; + +import java.util.concurrent.TimeUnit; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.common.HubGameComponent; + +public class GameTimeoutComponent extends HubGameComponent +{ + + private static final long SECONDS_30 = TimeUnit.SECONDS.toMillis(30); + + private final long _timeout; + private boolean _announced30Seconds; + + public GameTimeoutComponent(CycledGame game, long timeout) + { + super(game); + + _timeout = timeout; + } + + @EventHandler + public void updateTimeout(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC || !_game.isLive()) + { + return; + } + + if (!_announced30Seconds && UtilTime.elapsed(_game.getLastStart(), _timeout - SECONDS_30)) + { + _game.announce("The game will end in " + F.time("30 Seconds") + "."); + _announced30Seconds = true; + } + else if (UtilTime.elapsed(_game.getLastStart(), _timeout)) + { + _game.announce("The game took too long and has ended"); + + for (Player player : _game.getAlivePlayers()) + { + _game.onPlayerDeath(player, true); + } + + _game.getAlivePlayers().clear(); + _announced30Seconds = false; + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/InventoryEditComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/InventoryEditComponent.java new file mode 100644 index 000000000..7c504f0fa --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/InventoryEditComponent.java @@ -0,0 +1,29 @@ +package mineplex.hub.hubgame.common.general; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryClickEvent; + +import mineplex.hub.hubgame.HubGame; +import mineplex.hub.hubgame.common.HubGameComponent; + +public class InventoryEditComponent extends HubGameComponent +{ + + public InventoryEditComponent(HubGame game) + { + super(game); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void inventoryClick(InventoryClickEvent event) + { + Player player = (Player) event.getWhoClicked(); + + if (_game.isAlive(player)) + { + event.setCancelled(false); + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/PlacesComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/PlacesComponent.java new file mode 100644 index 000000000..1d6d1818c --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/PlacesComponent.java @@ -0,0 +1,61 @@ +package mineplex.hub.hubgame.common.general; + +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.util.C; +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.HubGameManager; +import mineplex.hub.hubgame.common.HubGameComponent; +import mineplex.hub.hubgame.event.HubGameStateChangeEvent; + +public class PlacesComponent extends HubGameComponent +{ + + public PlacesComponent(CycledGame game) + { + super(game); + } + + @EventHandler + public void displayPlaces(HubGameStateChangeEvent event) + { + if (event.getState() != GameState.End || !event.getGame().equals(_game)) + { + return; + } + + CycledGame game = event.getGame(); + List places = game.getPlaces(); + String gameString = _game.getManager().getGameHeader(game); + + for (Player player : places) + { + if (!player.isOnline()) + { + continue; + } + + player.sendMessage(HubGameManager.getHeaderFooter()); + player.sendMessage(gameString); + player.sendMessage(""); + if (!places.isEmpty()) + { + player.sendMessage(C.cRedB + "1st Place " + C.cWhite + places.get(0).getName()); + } + if (places.size() > 1) + { + player.sendMessage(C.cGoldB + "2nd Place " + C.cWhite + places.get(1).getName()); + } + if (places.size() > 2) + { + player.sendMessage(C.cYellowB + "3rd Place " + C.cWhite + places.get(2).getName()); + } + player.sendMessage(""); + player.sendMessage(HubGameManager.getHeaderFooter()); + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/PlayerGameModeComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/PlayerGameModeComponent.java new file mode 100644 index 000000000..d6987bec9 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/PlayerGameModeComponent.java @@ -0,0 +1,40 @@ +package mineplex.hub.hubgame.common.general; + +import org.bukkit.GameMode; +import org.bukkit.event.EventHandler; + +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.common.HubGameComponent; +import mineplex.hub.hubgame.event.HubGamePlayerDeathEvent; +import mineplex.hub.hubgame.event.HubGameStateChangeEvent; + +public class PlayerGameModeComponent extends HubGameComponent +{ + + private final GameMode _gameMode; + + public PlayerGameModeComponent(CycledGame game, GameMode gameMode) + { + super(game); + + _gameMode = gameMode; + } + + @EventHandler + public void prepare(HubGameStateChangeEvent event) + { + if (event.getState() != GameState.Prepare) + { + return; + } + + _game.getAlivePlayers().forEach(player -> player.setGameMode(_gameMode)); + } + + @EventHandler + public void playerDeath(HubGamePlayerDeathEvent event) + { + event.getPlayer().setGameMode(GameMode.ADVENTURE); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/PrepareFreezeComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/PrepareFreezeComponent.java new file mode 100644 index 000000000..191239096 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/PrepareFreezeComponent.java @@ -0,0 +1,37 @@ +package mineplex.hub.hubgame.common.general; + +import org.bukkit.Location; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; + +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.common.HubGameComponent; + +public class PrepareFreezeComponent extends HubGameComponent +{ + + public PrepareFreezeComponent(CycledGame game) + { + super(game); + } + + @EventHandler + public void playerMove(PlayerMoveEvent event) + { + if (_game.getGameState() != GameState.Prepare || !_game.isAlive(event.getPlayer())) + { + return; + } + + Location from = event.getFrom(); + Location to = event.getTo(); + + if (from.getX() == to.getX() && from.getZ() == to.getZ()) + { + return; + } + + event.setTo(from); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/SingleWinnerComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/SingleWinnerComponent.java new file mode 100644 index 000000000..52be3a753 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/general/SingleWinnerComponent.java @@ -0,0 +1,61 @@ +package mineplex.hub.hubgame.common.general; + +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilText; +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.HubGameManager; +import mineplex.hub.hubgame.common.HubGameComponent; +import mineplex.hub.hubgame.event.HubGameStateChangeEvent; + +public class SingleWinnerComponent extends HubGameComponent +{ + + public SingleWinnerComponent(CycledGame game) + { + super(game); + } + + @EventHandler + public void displayWinner(HubGameStateChangeEvent event) + { + if (event.getState() != GameState.End || !event.getGame().equals(_game)) + { + return; + } + + CycledGame game = event.getGame(); + List places = game.getPlaces(); + + if (places.isEmpty()) + { + return; + } + + Player winner = places.get(0); + String gameString = _game.getManager().getGameHeader(game); + + for (Player player : places) + { + if (!player.isOnline()) + { + continue; + } + + player.sendMessage(HubGameManager.getHeaderFooter()); + player.sendMessage(gameString); + player.sendMessage(""); + + player.sendMessage(UtilText.centerChat(C.cWhiteB + "Winner " + (winner.equals(player) ? C.cGreen : C.cRed) + winner.getName(), LineFormat.CHAT)); + + player.sendMessage(""); + player.sendMessage(HubGameManager.getHeaderFooter()); + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/map/BlockRecorderComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/map/BlockRecorderComponent.java new file mode 100644 index 000000000..660b6b758 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/map/BlockRecorderComponent.java @@ -0,0 +1,88 @@ +package mineplex.hub.hubgame.common.map; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; + +import mineplex.core.common.Pair; +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.common.HubGameComponent; +import mineplex.hub.hubgame.event.HubGameStateChangeEvent; + +public class BlockRecorderComponent extends HubGameComponent +{ + + private final Map> _blocks; + private final Set _placedBlocks; + private final Location _cornerA; + private final Location _cornerB; + + public BlockRecorderComponent(CycledGame game, Location cornerA, Location cornerB) + { + super(game); + + _placedBlocks = new HashSet<>(); + _blocks = new HashMap<>(500); + + for (Block block : UtilBlock.getInBoundingBox(cornerA, cornerB, false)) + { + _blocks.put(block.getLocation(), Pair.create(block.getType(), block.getData())); + } + + _cornerA = cornerA; + _cornerB = cornerB; + } + + @EventHandler + public void blockBreak(BlockBreakEvent event) + { + Player player = event.getPlayer(); + Location location = event.getBlock().getLocation(); + + if (!_game.isLive() || !_game.isAlive(player) || !_placedBlocks.contains(location)) + { + return; + } + + event.setCancelled(false); + } + + @EventHandler + public void blockPlace(BlockPlaceEvent event) + { + Player player = event.getPlayer(); + Location location = event.getBlock().getLocation(); + + if (!_game.isLive() || !_game.isAlive(player) || !UtilAlg.inBoundingBox(location, _cornerA, _cornerB)) + { + return; + } + + _placedBlocks.add(location); + event.setCancelled(false); + } + + @EventHandler + public void end(HubGameStateChangeEvent event) + { + if (event.getState() != GameState.Waiting || !event.getGame().equals(_game)) + { + return; + } + + _game.getManager().runSyncLater(() -> _blocks.forEach((location, pair) -> MapUtil.QuickChangeBlockAt(location, pair.getLeft(), pair.getRight())), 1); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/map/PreventNonAlivePlayersComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/map/PreventNonAlivePlayersComponent.java new file mode 100644 index 000000000..6e05c9d3d --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/map/PreventNonAlivePlayersComponent.java @@ -0,0 +1,56 @@ +package mineplex.hub.hubgame.common.map; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilServer; +import mineplex.core.gadget.event.GadgetSelectLocationEvent; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.hubgame.HubGame; +import mineplex.hub.hubgame.common.HubGameComponent; + +public class PreventNonAlivePlayersComponent extends HubGameComponent +{ + + private final Location _cornerA; + private final Location _cornerB; + + public PreventNonAlivePlayersComponent(HubGame game, Location cornerA, Location cornerB) + { + super(game); + + _cornerA = cornerA; + _cornerB = cornerB; + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + for (Player player : UtilServer.getPlayersCollection()) + { + if (!_game.isAlive(player) && UtilAlg.inBoundingBox(player.getLocation(), _cornerA, _cornerB)) + { + player.sendMessage(F.main(_game.getManager().getName(), "You are not allowed to enter the game area.")); + player.teleport(_game.getSpawn()); + } + } + } + + @EventHandler + public void gadgetSelectBlock(GadgetSelectLocationEvent event) + { + if (UtilAlg.inBoundingBox(event.getLocation(), _cornerA, _cornerB)) + { + event.setCancelled(true); + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/map/TeleportIntoMapComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/map/TeleportIntoMapComponent.java new file mode 100644 index 000000000..590dd9ee7 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/map/TeleportIntoMapComponent.java @@ -0,0 +1,50 @@ +package mineplex.hub.hubgame.common.map; + +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.util.UtilAlg; +import mineplex.hub.hubgame.CycledGame.GameState; +import mineplex.hub.hubgame.HubGame; +import mineplex.hub.hubgame.common.HubGameComponent; +import mineplex.hub.hubgame.event.HubGameStateChangeEvent; + +public class TeleportIntoMapComponent extends HubGameComponent +{ + + private final List _spawns; + + public TeleportIntoMapComponent(HubGame game, List spawns) + { + super(game); + + _spawns = spawns; + } + + @EventHandler + public void prepare(HubGameStateChangeEvent event) + { + if (event.getState() != GameState.Prepare || !event.getGame().equals(_game)) + { + return; + } + + Location average = UtilAlg.getAverageLocation(_spawns); + int i = 0; + + for (Player player : _game.getAlivePlayers()) + { + Location location = _spawns.get(i++); + + if (location.getYaw() == 0) + { + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, average))); + } + + player.teleport(location); + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/ItemPowerup.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/ItemPowerup.java new file mode 100644 index 000000000..9baaa3827 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/ItemPowerup.java @@ -0,0 +1,78 @@ +package mineplex.hub.hubgame.common.powerup; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilServer; +import mineplex.core.itemstack.ItemBuilder; + +public abstract class ItemPowerup implements Powerup, Listener +{ + + private final String _name; + private final ItemStack _itemStack; + + public ItemPowerup(String name, ItemStack itemStack) + { + _name = name; + _itemStack = new ItemBuilder(itemStack) + .setTitle(name + C.cWhite + " - " + C.cYellowB + "Click") + .build(); + + UtilServer.RegisterEvents(this); + } + + @Override + public void onCollect(Player player) + { + player.getInventory().addItem(_itemStack); + } + + @Override + public String getName() + { + return _name; + } + + @Override + public ItemStack getItemStack() + { + return _itemStack; + } + + public abstract void onInteractItem(Player player); + + @EventHandler + public void playerInteract(PlayerInteractEvent event) + { + if (event.isCancelled()) + { + return; + } + + Player player = event.getPlayer(); + ItemStack itemStack = player.getItemInHand(); + + if (itemStack == null || !itemStack.isSimilar(_itemStack)) + { + return; + } + + event.setCancelled(true); + + if (itemStack.getAmount() == 1) + { + player.setItemInHand(null); + } + else + { + itemStack.setAmount(itemStack.getAmount() - 1); + } + + onInteractItem(player); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/Powerup.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/Powerup.java new file mode 100644 index 000000000..89ed60daa --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/Powerup.java @@ -0,0 +1,15 @@ +package mineplex.hub.hubgame.common.powerup; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public interface Powerup +{ + + void onCollect(Player player); + + String getName(); + + ItemStack getItemStack(); + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/PowerupComponent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/PowerupComponent.java new file mode 100644 index 000000000..e92fcf86b --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/PowerupComponent.java @@ -0,0 +1,112 @@ +package mineplex.hub.hubgame.common.powerup; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.common.HubGameComponent; + +public class PowerupComponent extends HubGameComponent +{ + + private static final int MAX_POWERUPS = 2; + + private final List _powerups; + private final List _spawnedPowerups; + private final List _powerupSpawns; + + public PowerupComponent(CycledGame game, List powerupSpawns) + { + super(game); + + _powerups = new ArrayList<>(); + _spawnedPowerups = new ArrayList<>(); + _powerupSpawns = powerupSpawns; + } + + public void addPowerup(Powerup powerup) + { + _powerups.add(powerup); + } + + @Override + public void deactivate() + { + _spawnedPowerups.forEach(SpawnedPowerup::remove); + + super.deactivate(); + } + + @EventHandler + public void updatePowerupSpawn(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC || !_game.isLive() || !UtilTime.elapsed(_game.getLastStart(), 3000) || _spawnedPowerups.size() == MAX_POWERUPS || Math.random() > 0.1) + { + return; + } + + + Location location = UtilAlg.Random(_powerupSpawns); + + // Too close to another powerup + for (SpawnedPowerup powerup : _spawnedPowerups) + { + if (UtilMath.offset2dSquared(location, powerup.getLocation()) < 2) + { + return; + } + } + + Powerup powerup = UtilAlg.Random(_powerups); + SpawnedPowerup spawnedPowerup = new SpawnedPowerup(powerup, location); + particles(spawnedPowerup); + _spawnedPowerups.add(spawnedPowerup); + } + + @EventHandler + public void updatePowerupCollision(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTEST) + { + return; + } + + for (Player player : _game.getAlivePlayers()) + { + _spawnedPowerups.removeIf(powerup -> + { + if (powerup.collided(player)) + { + particles(powerup); + powerup.getPowerup().onCollect(player); + powerup.remove(); + + player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1); + player.sendMessage(F.main(_game.getManager().getName(), "You collected a " + F.name(powerup.getPowerup().getName()) + " Powerup!")); + return true; + } + + return false; + }); + } + } + + private void particles(SpawnedPowerup powerup) + { + UtilParticle.PlayParticleToAll(ParticleType.LAVA, powerup.getLocation(), 0.4F, 0.4F, 0.4F, 0.1F, 5, ViewDist.NORMAL); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/SpawnedPowerup.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/SpawnedPowerup.java new file mode 100644 index 000000000..b255e2f76 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/SpawnedPowerup.java @@ -0,0 +1,70 @@ +package mineplex.hub.hubgame.common.powerup; + +import org.bukkit.Location; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilMath; + +public class SpawnedPowerup +{ + + private final Powerup _powerup; + private final ArmorStand _itemHolder; + private final ArmorStand _hologram; + + public SpawnedPowerup(Powerup powerup, Location location) + { + _powerup = powerup; + + _itemHolder = spawnStand(location); + _hologram = spawnStand(location.add(0, 0.2, 0)); + _hologram.setCustomName(powerup.getName()); + _hologram.setCustomNameVisible(true); + + Item item = location.getWorld().dropItem(location, powerup.getItemStack()); + item.setPickupDelay(Integer.MAX_VALUE); + _itemHolder.setPassenger(item); + } + + public Powerup getPowerup() + { + return _powerup; + } + + public Location getLocation() + { + return _itemHolder.getLocation().add(0, 2, 0); + } + + public boolean collided(Player player) + { + return UtilMath.offset2dSquared(player, _itemHolder) < 4; + } + + public void remove() + { + if (_itemHolder.getPassenger() != null) + { + _itemHolder.getPassenger().remove(); + } + + _itemHolder.remove(); + _hologram.remove(); + } + + private ArmorStand spawnStand(Location location) + { + ArmorStand stand = location.getWorld().spawn(location, ArmorStand.class); + + UtilEnt.vegetate(stand); + UtilEnt.ghost(stand, true, false); + + stand.setVisible(false); + stand.setGravity(false); + + return stand; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/TimedPowerup.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/TimedPowerup.java new file mode 100644 index 000000000..2eb04a9d4 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/common/powerup/TimedPowerup.java @@ -0,0 +1,114 @@ +package mineplex.hub.hubgame.common.powerup; + +import java.util.HashSet; +import java.util.Set; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextBottom; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class TimedPowerup implements Powerup, Listener +{ + + private final String _name; + private final ItemStack _itemStack; + private final long _length; + + private final Set _data; + + public TimedPowerup(String name, ItemStack itemStack, long length) + { + _name = name; + _itemStack = itemStack; + _length = length; + _data = new HashSet<>(); + + UtilServer.RegisterEvents(this); + } + + @Override + public void onCollect(Player player) + { + _data.add(new TimedData(player, _length)); + onStart(); + } + + @Override + public String getName() + { + return _name; + } + + @Override + public ItemStack getItemStack() + { + return _itemStack; + } + + public void onStart() + { + } + + public void onEnd() + { + } + + public boolean isActive(Player player) + { + for (TimedData data : _data) + { + if (data.Player.equals(player)) + { + return true; + } + } + + return false; + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + _data.removeIf(data -> + { + if (UtilTime.elapsed(data.Start, data.Length)) + { + onEnd(); + return true; + } + + long timeLeft = data.Start + data.Length - System.currentTimeMillis(); + double percentage = (System.currentTimeMillis() - data.Start) / (double) data.Length; + + UtilTextBottom.displayProgress(getName(), percentage, UtilTime.MakeStr(timeLeft), data.Player); + return false; + }); + } + + private class TimedData + { + + Player Player; + long Start; + long Length; + + TimedData(Player player, long length) + { + Player = player; + Start = System.currentTimeMillis(); + Length = length; + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/Duels.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/Duels.java new file mode 100644 index 000000000..8ae663e42 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/Duels.java @@ -0,0 +1,149 @@ +package mineplex.hub.hubgame.duel; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.HubGameManager; +import mineplex.hub.hubgame.HubGameType; +import mineplex.hub.hubgame.common.damage.DamageComponent; +import mineplex.hub.hubgame.common.damage.PVPTrackerComponent; +import mineplex.hub.hubgame.common.general.DoubleJumpComponent; +import mineplex.hub.hubgame.common.general.GameDescriptionComponent; +import mineplex.hub.hubgame.common.general.GameTimeoutComponent; +import mineplex.hub.hubgame.common.general.InventoryEditComponent; +import mineplex.hub.hubgame.common.general.PlayerGameModeComponent; +import mineplex.hub.hubgame.common.general.PrepareFreezeComponent; +import mineplex.hub.hubgame.common.general.SingleWinnerComponent; +import mineplex.hub.hubgame.common.map.BlockRecorderComponent; +import mineplex.hub.hubgame.common.map.PreventNonAlivePlayersComponent; +import mineplex.hub.hubgame.common.map.TeleportIntoMapComponent; +import mineplex.hub.hubgame.ui.HubGamePage; + +public class Duels extends CycledGame +{ + + private static final ItemStack[] ITEMS = { + new ItemBuilder(Material.DIAMOND_SWORD) + .setUnbreakable(true) + .addEnchantment(Enchantment.DAMAGE_ALL, 2) + .build(), + new ItemBuilder(Material.BOW) + .setUnbreakable(true) + .addEnchantment(Enchantment.ARROW_DAMAGE, 2) + .build(), + new ItemBuilder(Material.FISHING_ROD) + .setUnbreakable(true) + .build(), + new ItemStack(Material.GOLDEN_APPLE, 6), + new ItemBuilder(Material.DIAMOND_AXE) + .setUnbreakable(true) + .build(), + new ItemStack(Material.WOOD, 64), + new ItemStack(Material.LAVA_BUCKET), + new ItemStack(Material.WATER_BUCKET), + new ItemStack(Material.ARROW, 16), + }; + private static final ItemStack[] ARMOUR = { + new ItemBuilder(Material.DIAMOND_BOOTS) + .setUnbreakable(true) + .addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2) + .build(), + new ItemBuilder(Material.DIAMOND_LEGGINGS) + .setUnbreakable(true) + .addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2) + .build(), + new ItemBuilder(Material.DIAMOND_CHESTPLATE) + .setUnbreakable(true) + .addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2) + .build(), + new ItemBuilder(Material.DIAMOND_HELMET) + .setUnbreakable(true) + .addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2) + .build(), + }; + + public Duels(HubGameManager manager) + { + super(manager, HubGameType.DUELS); + + registerComponent(new DamageComponent(this)); + registerComponent(new PVPTrackerComponent(this)); + registerComponent(new GameDescriptionComponent(this, player -> + { + for (Player other : getAlivePlayers()) + { + if (!player.equals(other)) + { + return C.cWhiteB + "Opponent " + C.cRedB + other.getName(); + } + } + + return null; + })); + registerComponent(new TeleportIntoMapComponent(this, _worldData.getDataLocation("YELLOW"))); + registerComponent(new PrepareFreezeComponent(this)); + registerComponent(new InventoryEditComponent(this)); + registerComponent(new DoubleJumpComponent(this)); + registerComponent(new GameTimeoutComponent(this, TimeUnit.MINUTES.toMillis(2))); + registerComponent(new SingleWinnerComponent(this)); + registerComponent(new PlayerGameModeComponent(this, GameMode.SURVIVAL)); + + List corners = _worldData.getDataLocation("LIME"); + Location a = corners.get(0); + Location b = corners.get(1); + + registerComponent(new BlockRecorderComponent(this, a, b)); + registerComponent(new PreventNonAlivePlayersComponent(this, a, b)); + } + + @Override + public void onPrepare() + { + for (Player player : getAlivePlayers()) + { + player.getInventory().addItem(ITEMS); + player.getInventory().setArmorContents(ARMOUR); + } + } + + @Override + public boolean endCheck() + { + return getAlivePlayers().size() <= 1; + } + + @EventHandler + public void healthRegain(EntityRegainHealthEvent event) + { + if (event.getRegainReason() != RegainReason.SATIATED || !(event.getEntity() instanceof Player)) + { + return; + } + + Player player = (Player) event.getEntity(); + + if (isAlive(player)) + { + event.setCancelled(true); + } + } + + @Override + public HubGamePage getInformationPage(Player player) + { + return new DuelsUI(getManager(), getManager().getShop(), getManager().getClientManager(), getManager().getDonationManager(), player, this); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/DuelsUI.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/DuelsUI.java new file mode 100644 index 000000000..3c2936e4f --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/DuelsUI.java @@ -0,0 +1,87 @@ +package mineplex.hub.hubgame.duel; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilTime; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.hub.hubgame.HubGameManager; +import mineplex.hub.hubgame.common.damage.PVPTrackerComponent; +import mineplex.hub.hubgame.common.damage.PVPTrackerComponent.Match; +import mineplex.hub.hubgame.ui.HubGamePage; +import mineplex.hub.hubgame.ui.HubGameShop; + +public class DuelsUI extends HubGamePage +{ + + private static final ItemStack NO_MATCH = new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) 14) + .setTitle(C.cRed + "No match info") + .build(); + private static final ItemStack EDIT_KIT = new ItemBuilder(Material.ANVIL) + .setTitle(C.cGreen + "Edit Kit") + .addLore("", "You can edit the order items are", "given to you in the game.", "", C.cRed + "Coming Soon") + .build(); + + public DuelsUI(HubGameManager plugin, HubGameShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, Duels game) + { + super(plugin, shop, clientManager, donationManager, player, game, 45); + } + + @Override + protected void buildPage() + { + super.buildPage(); + + PVPTrackerComponent tracker = _game.getComponent(PVPTrackerComponent.class); + int slot = 20; + int index = 0; + + for (Match match : tracker.getMatches()) + { + index++; + addButton(slot++, getMatchItem(match, getPlayer()), (player, clickType) -> + { + tracker.sendMatch(player, match); + player.closeInventory(); + }); + } + + for (; index < 5; index++) + { + addButtonNoAction(slot++, NO_MATCH); + } + + addButtonNoAction(31, EDIT_KIT); + } + + private ItemStack getMatchItem(Match match, Player player) + { + Player[] players = match.getPlayers(); + boolean playerGame = false; + + for (Player other : players) + { + // Player may relog, thus player objects won't be the same + if (other.getUniqueId().equals(player.getUniqueId())) + { + playerGame = true; + break; + } + } + + return new ItemBuilder(Material.IRON_SWORD) + .setTitle(C.cGreen + players[0].getName() + C.cWhiteB + " v " + C.cGreen + players[1].getName()) + .addLore( + "", + C.cWhite + "Match Time: " + C.mTime + UtilTime.MakeStr(System.currentTimeMillis() - match.getStart()) + C.cWhite + " ago.", + "", + C.cGreen + "Click to find out more information about this match" + ) + .setGlow(playerGame) + .build(); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/event/HubGamePlayerDeathEvent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/event/HubGamePlayerDeathEvent.java new file mode 100644 index 000000000..b5d1dfdd9 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/event/HubGamePlayerDeathEvent.java @@ -0,0 +1,48 @@ +package mineplex.hub.hubgame.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.CycledGame.GameState; + +public class HubGamePlayerDeathEvent extends PlayerEvent +{ + + private static final HandlerList _handlers = new HandlerList(); + + private final CycledGame _game; + private final boolean _end; + + public HubGamePlayerDeathEvent(Player player, CycledGame game, boolean end) + { + super(player); + + _game = game; + _end = end; + } + + public CycledGame getGame() + { + return _game; + } + + public boolean isEnding() + { + return _end; + } + + public static HandlerList getHandlerList() + { + return _handlers; + } + + @Override + public HandlerList getHandlers() + { + return getHandlerList(); + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/event/HubGameStateChangeEvent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/event/HubGameStateChangeEvent.java new file mode 100644 index 000000000..7f6502ccf --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/event/HubGameStateChangeEvent.java @@ -0,0 +1,44 @@ +package mineplex.hub.hubgame.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.CycledGame.GameState; + +public class HubGameStateChangeEvent extends Event +{ + + private static final HandlerList _handlers = new HandlerList(); + + private final CycledGame _game; + private final GameState _state; + + public HubGameStateChangeEvent(CycledGame game, GameState state) + { + _game = game; + _state = state; + } + + public CycledGame getGame() + { + return _game; + } + + public GameState getState() + { + return _state; + } + + public static HandlerList getHandlerList() + { + return _handlers; + } + + @Override + public HandlerList getHandlers() + { + return getHandlerList(); + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/Tron.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/Tron.java new file mode 100644 index 000000000..2aef81f69 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/Tron.java @@ -0,0 +1,162 @@ +package mineplex.hub.hubgame.tron; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.HubGameManager; +import mineplex.hub.hubgame.HubGameType; +import mineplex.hub.hubgame.common.general.GameDescriptionComponent; +import mineplex.hub.hubgame.common.general.GameTimeoutComponent; +import mineplex.hub.hubgame.common.general.PlacesComponent; +import mineplex.hub.hubgame.common.map.PreventNonAlivePlayersComponent; +import mineplex.hub.hubgame.common.map.TeleportIntoMapComponent; +import mineplex.hub.hubgame.common.powerup.PowerupComponent; +import mineplex.hub.hubgame.tron.powerup.JumpPowerup; +import mineplex.hub.hubgame.tron.powerup.SpeedPowerup; + +public class Tron extends CycledGame +{ + + private static final byte[] COLOURS = + { + 1, 5, 3, 10 + }; + private static final int DEFAULT_SIZE = 10; + + private final Map _bikes; + private int _trailSize; + + private final SpeedPowerup _speedPowerup; + + public Tron(HubGameManager manager) + { + super(manager, HubGameType.TRON); + _bikes = new HashMap<>(); + + PowerupComponent powerupComponent = registerComponent(new PowerupComponent(this, _worldData.getDataLocation("ORANGE"))); + _speedPowerup = new SpeedPowerup(); + powerupComponent.addPowerup(_speedPowerup); + powerupComponent.addPowerup(new JumpPowerup()); + + registerComponent(new TeleportIntoMapComponent(this, _worldData.getDataLocation("RED"))); + registerComponent(new GameDescriptionComponent(this)); + registerComponent(new GameTimeoutComponent(this, TimeUnit.MINUTES.toMillis(3))); + registerComponent(new PlacesComponent(this)); + + List corners = _worldData.getDataLocation("WHITE"); + Location a = corners.get(0); + Location b = corners.get(1); + + registerComponent(new PreventNonAlivePlayersComponent(this, a, b)); + } + + @Override + public void onPrepare() + { + _trailSize = DEFAULT_SIZE; + + UtilServer.runSyncLater(() -> + { + int colourId = 0; + + for (Player player : getAlivePlayers()) + { + TronBike bike = new TronBike(this, player, COLOURS[colourId++]); + _bikes.put(player, bike); + } + + }, 1); + } + + @EventHandler + public void updateBikes(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + _bikes.forEach((player, bike) -> + { + if (!isAlive(player)) + { + return; + } + + bike.updateDirection(); + + if (isLive() && bike.updateLocation(_speedPowerup.isActive(player))) + { + Location location = player.getLocation(); + + player.getWorld().playSound(location, Sound.EXPLODE, 1, 1); + UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, location,0, 0, 0, 0.1F, 1, ViewDist.NORMAL); + announce(F.name(player.getName()) + " got vapourised."); + onPlayerDeath(player); + bike.clean(); + } + else if (player.getVehicle() == null || !player.getVehicle().equals(bike.getEntity())) + { + bike.getEntity().setPassenger(player); + } + }); + } + + @EventHandler + public void updateTrailSize(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW || !isLive()) + { + return; + } + + _trailSize++; + } + + @Override + public boolean endCheck() + { + return getAlivePlayers().size() <= 1; + } + + @Override + public void onCleanup() + { + super.onCleanup(); + _bikes.values().forEach(TronBike::clean); + _bikes.clear(); + } + + @Override + public void onCleanupPlayer(Player player) + { + super.onCleanupPlayer(player); + + TronBike bike = _bikes.remove(player); + + if (bike != null) + { + bike.clean(); + } + } + + public int getTrailSize() + { + return _trailSize; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/TronBike.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/TronBike.java new file mode 100644 index 000000000..315159d41 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/TronBike.java @@ -0,0 +1,162 @@ +package mineplex.hub.hubgame.tron; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.server.v1_8_R3.Entity; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; + +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilTime; + +public class TronBike +{ + + private static final long DIRECTION_RATE = 500; + private static final double DELTA_TICK = 0.4; + + private final Tron _game; + private final Player _host; + private final byte _colour; + private final Slime _bike; + private final List _trail; + + private Block _lastBlock; + private float _lastYaw; + private long _lastChange; + private boolean _changeDirection; + + public TronBike(Tron game, Player host, byte colour) + { + _game = game; + _host = host; + _colour = colour; + _bike = host.getWorld().spawn(host.getLocation(), Slime.class); + _trail = new ArrayList<>(); + + _bike.setSize(2); + UtilEnt.vegetate(_bike); + UtilEnt.ghost(_bike, true, false); + UtilEnt.silence(_bike, true); + UtilEnt.setFakeHead(_bike, true); + + _lastBlock = _bike.getLocation().getBlock(); + _lastYaw = -1; + } + + public void updateDirection() + { + if (UtilTime.elapsed(_lastChange, DIRECTION_RATE)) + { + float yaw = (Math.round(_host.getLocation().getYaw() / 90F) & 0x3) * 90F; + + if (_lastYaw != yaw) + { + _lastYaw = yaw; + _lastChange = System.currentTimeMillis(); + _changeDirection = true; + } + } + } + + public boolean updateLocation(boolean speed) + { + Location location = _bike.getLocation().add(0, 0.1, 0); + Block block = location.getBlock(); + + if (block.getType() != Material.AIR) + { + return true; + } + + Entity entity = ((CraftEntity) _bike).getHandle(); + double x = location.getX(); + double z = location.getZ(); + double deltaX = 0; + double deltaZ = 0; + + if (_lastYaw == 0) + { + deltaZ += DELTA_TICK; + } + else if (_lastYaw == 90) + { + deltaX -= DELTA_TICK; + } + else if (_lastYaw == 180) + { + deltaZ -= DELTA_TICK; + } + else + { + deltaX += DELTA_TICK; + } + + if (speed) + { + deltaX *= 1.5; + deltaZ *= 1.5; + } + + if (!block.equals(_lastBlock)) + { + if (_trail.size() >= _game.getTrailSize()) + { + Location remove = _trail.remove(0); + + MapUtil.QuickChangeBlockAt(remove, Material.AIR); + } + + Location lastBlock = _lastBlock.getLocation(); + + _trail.add(lastBlock); + MapUtil.QuickChangeBlockAt(lastBlock, Material.STAINED_GLASS_PANE, _colour); + + _lastBlock = block; + } + + if (_changeDirection) + { + boolean canChange = false; + + if (deltaZ != 0 && x - location.getBlockX() > 0.5) + { + x = location.getBlockX() + 0.5; + canChange = true; + } + else if (deltaX != 0 && z - location.getBlockZ() > 0.5) + { + z = location.getBlockZ() + 0.5; + canChange = true; + } + + if (canChange) + { + _changeDirection = false; + UtilEnt.CreatureLook(_bike, 0, _lastYaw); + } + } + + entity.setPosition(x + deltaX, location.getY() - 0.1, z + deltaZ); + return false; + } + + public void clean() + { + _bike.remove(); + _trail.forEach(location -> MapUtil.QuickChangeBlockAt(location, Material.AIR)); + _trail.clear(); + } + + public Slime getEntity() + { + return _bike; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/powerup/JumpPowerup.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/powerup/JumpPowerup.java new file mode 100644 index 000000000..1e0af3526 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/powerup/JumpPowerup.java @@ -0,0 +1,33 @@ +package mineplex.hub.hubgame.tron.powerup; + +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.C; +import mineplex.hub.hubgame.common.powerup.ItemPowerup; + +public class JumpPowerup extends ItemPowerup +{ + + private static final ItemStack ITEM_STACK = new ItemStack(Material.FEATHER); + private static final Vector DIRECTION = new Vector(0, 1.5, 0); + + public JumpPowerup() + { + super(C.cGoldB + "Jump", ITEM_STACK); + } + + @Override + public void onInteractItem(Player player) + { + Entity entity = player.getVehicle(); + + if (entity != null) + { + entity.setVelocity(DIRECTION); + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/powerup/SpeedPowerup.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/powerup/SpeedPowerup.java new file mode 100644 index 000000000..04c52fc0d --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/powerup/SpeedPowerup.java @@ -0,0 +1,23 @@ +package mineplex.hub.hubgame.tron.powerup; + +import java.util.concurrent.TimeUnit; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.hub.hubgame.common.powerup.TimedPowerup; + +public class SpeedPowerup extends TimedPowerup +{ + + private static final ItemStack ITEM_STACK = new ItemStack(Material.DIAMOND_BOOTS); + private static final long LENGTH = TimeUnit.SECONDS.toMillis(3); + + public SpeedPowerup() + { + super(C.cGreenB + "Speed", ITEM_STACK, LENGTH); + } + + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/ui/HubGamePage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/ui/HubGamePage.java new file mode 100644 index 000000000..c38cc7c6a --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/ui/HubGamePage.java @@ -0,0 +1,77 @@ +package mineplex.hub.hubgame.ui; + +import java.util.List; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.hub.hubgame.CycledGame; +import mineplex.hub.hubgame.HubGame; +import mineplex.hub.hubgame.HubGameManager; +import mineplex.hub.hubgame.HubGameType; + +public class HubGamePage extends ShopPageBase +{ + + protected final T _game; + + public HubGamePage(HubGameManager plugin, HubGameShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, T game) + { + this(plugin, shop, clientManager, donationManager, player, game, 27); + } + + public HubGamePage(HubGameManager plugin, HubGameShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, T game, int slots) + { + super(plugin, shop, clientManager, donationManager, game.getGameType().getName(), player, slots); + + _game = game; + + buildPage(); + } + + @Override + protected void buildPage() + { + HubGameType gameType = _game.getGameType(); + ItemBuilder builder = new ItemBuilder(gameType.getItemStack()); + + builder.setTitle(C.cYellow + gameType.getName()); + builder.addLore(""); + builder.addLore(gameType.getDescription()); + builder.addLore("", "Alive Players: " + C.cYellow + _game.getAlivePlayers().size()); + + if (_game instanceof CycledGame) + { + List queue = ((CycledGame) _game).getQueuedPlayers(); + int index = queue.indexOf(getPlayer()); + + builder.addLore("", "Queue Position: " + C.cYellow + (index == -1 ? "Not in queue" : (index + 1) + C.cGray + "/" + C.cYellow + queue.size())); + builder.addLore("", C.cGreen + (index == -1 ? "Click to join the queue." : "Click to leave the queue.")); + } + + addButton(13, builder.build(), (player, clickType) -> + { + if (_game instanceof CycledGame) + { + CycledGame game = (CycledGame) _game; + List queue = game.getQueuedPlayers(); + int index = queue.indexOf(getPlayer()); + + if (index == -1) + { + _game.getManager().joinQueue(game, player); + } + else + { + _game.getManager().leaveQueue(game, player, false); + } + + player.closeInventory(); + } + }); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/ui/HubGameShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/ui/HubGameShop.java new file mode 100644 index 000000000..b95e96b1f --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/ui/HubGameShop.java @@ -0,0 +1,24 @@ +package mineplex.hub.hubgame.ui; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.hub.hubgame.HubGameManager; + +public class HubGameShop extends ShopBase +{ + + public HubGameShop(HubGameManager plugin, CoreClientManager clientManager, DonationManager donationManager) + { + super(plugin, clientManager, donationManager, "Hub Game"); + } + + @Override + protected ShopPageBase> buildPagesFor(Player player) + { + return null; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java deleted file mode 100644 index fc29c38e8..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java +++ /dev/null @@ -1,77 +0,0 @@ -package mineplex.hub.mail; - -import java.util.List; -import java.util.UUID; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.MiniClientPlugin; -import mineplex.core.common.util.Callback; -import mineplex.hub.notification.NotificationManager; -import mineplex.hub.notification.api.Notification; -import mineplex.hub.notification.api.Notifier; - -public class MailManager extends MiniClientPlugin implements Notifier -{ - private MailRepository _repository; - - public MailManager(JavaPlugin plugin, NotificationManager notificationManager) - { - super("Mail", plugin); - - _repository = new MailRepository(plugin, this); - - notificationManager.addNotifier(this); - } - - @Override - protected PlayerMailData addPlayer(UUID uuid) - { - return new PlayerMailData(); - } - - @EventHandler - protected void loadPlayerData(final PlayerJoinEvent event) - { - runAsync(new Runnable() - { - @Override - public void run() - { - Set(event.getPlayer(), _repository.loadMailData(event.getPlayer().getUniqueId())); - } - }); - } - - public void archive(final MailMessage message, final Callback callback) - { - if (message.isArchived()) - return; - - runAsync(new Runnable() - { - @Override - public void run() - { - final boolean completed = _repository.archive(message); - runSync(new Runnable() - { - @Override - public void run() - { - callback.run(completed); - } - }); - } - }); - } - - @Override - public List getNotifications(Player player) - { - return Get(player).getUnreadMessages(); - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailMessage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailMessage.java deleted file mode 100644 index 46f3851b9..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailMessage.java +++ /dev/null @@ -1,200 +0,0 @@ -package mineplex.hub.mail; - -import java.sql.Timestamp; -import java.util.ArrayList; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; - -import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; -import mineplex.core.common.util.UtilTime; -import mineplex.hub.notification.api.Notification; -import mineplex.hub.notification.api.NotificationPriority; - -public class MailMessage implements Notification -{ - private MailManager _manager; - - private int _messageId; - private String _sender; - private String _message; - private boolean _archived; - private boolean _deleted; - private Timestamp _timeSent; - - public MailMessage(MailManager manager, int messageId, String sender, String message, boolean archived, boolean deleted, Timestamp timeSent) - { - _manager = manager; - - _messageId = messageId; - _sender = sender; - _message = message; - _archived = archived; - _deleted = deleted; - _timeSent = timeSent; - } - - public int getMessageId() - { - return _messageId; - } - - public void setMessageId(int messageId) - { - _messageId = messageId; - } - - public String getSender() - { - return _sender; - } - - public void setSender(String sender) - { - _sender = sender; - } - - public String getMessage() - { - return _message; - } - - public void setMessage(String message) - { - _message = message; - } - - public boolean isArchived() - { - return _archived; - } - - public void setArchived(boolean archived) - { - _archived = archived; - } - - public boolean isDeleted() - { - return _deleted; - } - - public void setDeleted(boolean deleted) - { - _deleted = deleted; - } - - public Timestamp getTimeSent() - { - return _timeSent; - } - - public void setTimeSent(Timestamp timeSent) - { - _timeSent = timeSent; - } - - @Override - public String getTitle() - { - return "Mail Message"; - } - - @Override - public String[] getText() - { - ArrayList lines = new ArrayList(); - - ArrayList message = formatMessage(); - - long timeDifference = System.currentTimeMillis() - getTime(); - - - lines.add(ChatColor.RESET + C.cYellow + "From: " + C.cWhite + _sender); - lines.add(ChatColor.RESET + C.cYellow + "Sent: " + C.cWhite + UtilTime.convertString(timeDifference, 0, UtilTime.TimeUnit.FIT) + " Ago"); - lines.add(" "); - lines.addAll(message); - - return lines.toArray(new String[lines.size()]); - } - - @Override - public long getTime() - { - return _timeSent.getTime(); - } - - @Override - public Material getMaterial() - { - return Material.PAPER; - } - - @Override - public byte getData() - { - return 0; - } - - @Override - public void clicked(final Player player, ClickType clickType) - { - if (clickType == ClickType.SHIFT_RIGHT) - { - _manager.archive(this, new Callback() - { - @Override - public void run(Boolean data) - { - if (data) - { - player.playSound(player.getLocation(), Sound.SPLASH, 1, 0); - } - } - }); - } - } - - @Override - public NotificationPriority getPriority() - { - return NotificationPriority.NORMAL; - } - - private ArrayList formatMessage() - { - String mailMessage = ChatColor.translateAlternateColorCodes('&', _message); // Color the message - - ArrayList parts = new ArrayList(); - int breakIndex = 0; - int charCount = 0; - - for (String s : mailMessage.split("\\\\n")) - { - for (int currIndex = 0; currIndex < s.length(); currIndex++) - { - charCount++; - char c = s.charAt(currIndex); - - if ((charCount >= 36 && c == ' ') || c == '\n') - { - // New Line - parts.add(ChatColor.RESET + s.substring(breakIndex, currIndex).trim()); - breakIndex = currIndex; - charCount = 0; - } - } - // Add final part - parts.add(ChatColor.RESET + s.substring(breakIndex).trim()); - charCount = 0; - breakIndex = 0; - } - - return parts; - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java deleted file mode 100644 index e4440d29c..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java +++ /dev/null @@ -1,70 +0,0 @@ -package mineplex.hub.mail; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.UUID; - -import mineplex.core.database.MinecraftRepository; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.serverdata.database.DBPool; -import mineplex.database.Tables; -import mineplex.database.tables.records.MailRecord; -import mineplex.serverdata.database.RepositoryBase; - -import org.jooq.DSLContext; -import org.jooq.Result; -import org.jooq.impl.DSL; - -public class MailRepository extends RepositoryBase -{ - private MailManager _manager; - - public MailRepository(JavaPlugin plugin, MailManager manager) - { - super(DBPool.getAccount()); - - _manager = manager; - } - - public PlayerMailData loadMailData(ResultSet resultSet) throws SQLException - { - PlayerMailData data = new PlayerMailData(); - - - return data; - } - - public PlayerMailData loadMailData(UUID uuid) - { - PlayerMailData data = new PlayerMailData(); - - DSLContext context = DSL.using(getConnection()); - - Result resultSet = context.selectFrom(Tables.mail).where(Tables.mail.accountId.eq(DSL.select(Tables.accounts.id) - .from(Tables.accounts) - .where(Tables.accounts.uuid.eq(uuid.toString()))) - ).and(Tables.mail.deleted.isFalse()).fetch(); - - for (MailRecord record : resultSet) - { - data.getMessages().add(createMessage(record)); - } - - return data; - } - - private MailMessage createMessage(MailRecord record) - { - return new MailMessage(_manager, record.getId(), record.getSender(), record.getMessage(), (record.getArchived() & 0x01) != 0, (record.getDeleted() & 0x01) != 0, record.getTimeSent()); - } - - public boolean archive(MailMessage mailMessage) - { - DSLContext context = DSL.using(getConnection()); - - int recordsUpdated = context.update(Tables.mail).set(Tables.mail.archived, (byte) 1).where(Tables.mail.id.eq(mailMessage.getMessageId())).execute(); - - return recordsUpdated == 1; - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/PlayerMailData.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/PlayerMailData.java deleted file mode 100644 index 6a2501d11..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/PlayerMailData.java +++ /dev/null @@ -1,34 +0,0 @@ -package mineplex.hub.mail; - -import java.util.ArrayList; -import java.util.List; - -import mineplex.database.tables.records.MailRecord; - -public class PlayerMailData -{ - private List _messages; - - public PlayerMailData() - { - _messages = new ArrayList(); - } - - public List getMessages() - { - return _messages; - } - - public List getUnreadMessages() - { - ArrayList unreadMessages = new ArrayList(); - - for (MailMessage message : _messages) - { - if (!(message.isArchived() || message.isDeleted())) - unreadMessages.add(message); - } - - return unreadMessages; - } - } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/AdminMountManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/AdminMountManager.java deleted file mode 100644 index 2e81a8fe5..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/AdminMountManager.java +++ /dev/null @@ -1,333 +0,0 @@ -package mineplex.hub.modules; - -import java.util.ArrayList; -import java.util.HashMap; - -import org.bukkit.Material; -import org.bukkit.entity.Horse; -import org.bukkit.entity.Horse.Color; -import org.bukkit.entity.Horse.Style; -import org.bukkit.entity.Horse.Variant; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.ItemStack; - -import mineplex.core.MiniPlugin; -import mineplex.core.account.permissions.Permission; -import mineplex.core.account.permissions.PermissionGroup; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.utils.UtilVariant; -import mineplex.hub.HubManager; -import mineplex.hub.commands.HorseSpawn; - -public class AdminMountManager extends MiniPlugin -{ - public enum Perm implements Permission - { - HORSE_COMMAND, - } - - private HubManager Manager; - - private HashMap _mounts = new HashMap(); - - public AdminMountManager(HubManager manager) - { - super("Mount Manager", manager.getPlugin()); - - Manager = manager; - - generatePermissions(); - } - - private void generatePermissions() - { - PermissionGroup.LT.setPermission(Perm.HORSE_COMMAND, true, true); - } - - @Override - public void addCommands() - { - addCommand(new HorseSpawn(this)); - } - - @EventHandler - public void HorseInteract(PlayerInteractEntityEvent event) - { - if (!(event.getRightClicked() instanceof Horse)) - return; - - Player player = event.getPlayer(); - Horse horse = (Horse)event.getRightClicked(); - - //Not Owner - if (!_mounts.containsKey(player) || !_mounts.get(player).equals(horse)) - { - UtilPlayer.message(player, F.main("Mount", "This is not your mount!")); - event.setCancelled(true); - return; - } - } - - @EventHandler - public void PlayerQuit(PlayerQuitEvent event) - { - Horse horse = _mounts.remove(event.getPlayer()); - if (horse != null) - horse.remove(); - } - - public void HorseCommand(Player caller, String[] args) - { - if (args == null || args.length == 0) - { - UtilPlayer.message(caller, F.main("Mount", "Mount Commands;")); - UtilPlayer.message(caller, "spawn / kill / leash / unleash"); - UtilPlayer.message(caller, "age / color / style / armor"); - return; - } - - if (args[0].equalsIgnoreCase("spawn")) - { - Variant var = Variant.HORSE; - if (args.length > 1) - { - try - { - var = Variant.valueOf(args[1].toUpperCase());; - } - catch (Exception e) - { - - } - } - - Spawn(caller, var); - return; - } - - Horse horse = _mounts.get(caller); - if (horse == null) - { - UtilPlayer.message(caller, F.main("Mount", "You do not have a mount.")); - return; - } - - //Leash - else if (args[0].equalsIgnoreCase("leash")) - { - horse.setLeashHolder(caller); - } - - //UnLeash - else if (args[0].equalsIgnoreCase("unleash")) - { - horse.setLeashHolder(null); - } - - //Kill - else if (args[0].equalsIgnoreCase("kill")) - { - horse.remove(); - _mounts.remove(caller); - } - - //Age - else if (args[0].equalsIgnoreCase("age")) - { - if (args.length >= 2) - { - try - { - if (args[1].equalsIgnoreCase("adult")) - { - horse.setAdult(); - } - else if (args[1].equalsIgnoreCase("baby")) - { - horse.setBaby(); - } - return; - } - catch (Exception e) - { - - } - } - - UtilPlayer.message(caller, F.main("Mount", F.value("Age", "baby adult"))); - } - - //Color - else if (args[0].equalsIgnoreCase("color")) - { - if (args.length >= 2) - { - Color color = GetColor(caller, args[1]); - if (color != null) - horse.setColor(color); - } - } - - //Style - else if (args[0].equalsIgnoreCase("style")) - { - if (args.length >= 2) - { - Style style = GetStyle(caller, args[1]); - if (style != null) - horse.setStyle(style); - } - } - - //Variant - else if (args[0].equalsIgnoreCase("variant") || args[0].equalsIgnoreCase("var")) - { - if (args.length >= 2) - { - Variant variant = GetVariant(caller, args[1]); - if (variant != null) - horse.setVariant(variant); - } - } - - //Armor - else if (args[0].equalsIgnoreCase("armor")) - { - if (args.length >= 2) - { - try - { - if (args[1].equalsIgnoreCase("iron")) - { - horse.getInventory().setArmor(new ItemStack(Material.IRON_BARDING)); - return; - } - if (args[1].equalsIgnoreCase("gold")) - { - horse.getInventory().setArmor(new ItemStack(Material.GOLD_BARDING)); - return; - } - if (args[1].equalsIgnoreCase("diamond")) - { - horse.getInventory().setArmor(new ItemStack(Material.DIAMOND_BARDING)); - return; - } - - } - catch (Exception e) - { - - } - } - - UtilPlayer.message(caller, F.main("Mount", F.value("Armor", "iron gold diamond"))); - } - } - - public Style GetStyle(Player caller, String arg) - { - ArrayList