Merge branch 'clans/beta' of https://github.com/Mineplex-LLC/Minecraft-PC into feature/incognito

This commit is contained in:
Ben 2016-03-08 18:07:57 +00:00
commit f24e196efd
120 changed files with 7321 additions and 2464 deletions

View File

@ -0,0 +1,80 @@
package mineplex.core.common;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
public class GsonLocation
{
private String _world;
private double _posX;
private double _posY;
private double _posZ;
private float _yaw;
private float _pitch;
public GsonLocation(Location location)
{
_world = location.getWorld().getName();
_posX = location.getX();
_posY = location.getY();
_posZ = location.getZ();
_yaw = location.getYaw();
_pitch = location.getPitch();
}
public GsonLocation(String world, double x, double y, double z)
{
this(Bukkit.getWorld(world), x, y, z, .0f, .0f);
}
public GsonLocation(String world, double x, double y, double z, float yaw, float pitch)
{
this(Bukkit.getWorld(world), x, y, z, yaw, pitch);
}
public GsonLocation(World world, double x, double y, double z, float yaw, float pitch)
{
_world = world.getName();
_posX = x;
_posY = y;
_posZ = z;
_yaw = yaw;
_pitch = pitch;
}
public GsonLocation(double x, double y, double z)
{
this(x, y, z, .0f, .0f);
}
public GsonLocation(double x, double y, double z, float yaw, float pitch)
{
this("world", x, y, z, yaw, pitch);
}
public Location bukkit()
{
return new Location(Bukkit.getWorld(_world), _posX, _posY, _posZ);
}
public String getWorld()
{
return _world;
}
public double getX()
{
return _posX;
}
public double getY()
{
return _posY;
}
public double getZ()
{
return _posZ;
}
}

View File

@ -8,7 +8,7 @@ public class Pair<L, R> implements Serializable {
private L left;
private R right;
public static <L, R> Pair<L, R> create(L left, R right)
{
return new Pair<L, R>(left, right);

View File

@ -75,6 +75,8 @@ public class C
public static String chatAdminHead = "" + ChatColor.DARK_PURPLE;
public static String chatAdminBody = "" + ChatColor.LIGHT_PURPLE;
public static String cClansNether = "" + ChatColor.RED;
public static String listTitle = "" + ChatColor.WHITE;
public static String listValue = "" + ChatColor.YELLOW;
public static String listValueOn = "" + ChatColor.GREEN;

View File

@ -215,4 +215,9 @@ public class F
? "an" : "a";
}
public static String clansNether(String word)
{
return C.cClansNether + word + C.mBody;
}
}

View File

@ -7,7 +7,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileUtil
public class FileUtil
{
public static void DeleteFolder(File folder)
{

View File

@ -5,11 +5,22 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.function.Consumer;
import java.util.stream.Stream;
public class NautArrayList<Elem>
public class NautArrayList<Elem> implements Iterable<Elem>
{
private ArrayList<Elem> _wrappedArrayList = new ArrayList<Elem>();
public NautArrayList()
{
}
public NautArrayList(Elem[] elements)
{
UtilCollections.addAll(elements, _wrappedArrayList);
}
public boolean add(Elem elem)
{
return _wrappedArrayList.add(elem);
@ -129,4 +140,19 @@ public class NautArrayList<Elem>
{
return _wrappedArrayList.toArray();
}
public void forEach(Consumer<? super Elem> consumer)
{
_wrappedArrayList.forEach(consumer);
}
public Stream<Elem> stream()
{
return _wrappedArrayList.stream();
}
public List<Elem> getWrapped()
{
return _wrappedArrayList;
}
}

View File

@ -3,12 +3,26 @@ package mineplex.core.common.util;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map.Entry;
import org.apache.commons.lang3.Validate;
import java.util.Set;
public class NautHashMap<KeyType, ValueType>
{
private HashMap<KeyType, ValueType> _wrappedHashMap = new HashMap<KeyType, ValueType>();
public NautHashMap()
{
}
public NautHashMap(KeyType[] keys, ValueType[] values)
{
Validate.isTrue(keys.length == values.length, "Keys array and values array must be the same size when making a Map");
UtilCollections.loop(0, keys.length, i -> _wrappedHashMap.put(keys[i.intValue()], values[i.intValue()]));
}
public boolean containsKey(KeyType key)
{
return _wrappedHashMap.containsKey(key);

View File

@ -1,5 +1,7 @@
package mineplex.core.common.util;
import org.bukkit.util.Vector;
public class RGBData
{
private double _red;
@ -50,4 +52,19 @@ public class RGBData
+ "green=" + (int) (_green * 255) + ", "
+ "blue=" + (int) (_blue * 255) + "]";
}
public Vector ToVector()
{
return new Vector(Math.max(0.001, _red), _green, _blue);
}
public RGBData Darken()
{
return new RGBData(getFullRed() - 25, getFullGreen() - 25, getFullBlue() - 25);
}
public RGBData Lighten()
{
return new RGBData(getFullRed() + 25, getFullGreen() + 25, getFullBlue() + 25);
}
}

View File

@ -3,6 +3,7 @@ package mineplex.core.common.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
@ -218,7 +219,7 @@ public class UtilAlg
return cross(vec, getRight(vec));
}
public static Location getAverageLocation(ArrayList<Location> locs)
public static Location getAverageLocation(List<Location> locs)
{
if (locs.isEmpty())
return null;
@ -236,8 +237,27 @@ public class UtilAlg
return vec.toLocation(locs.get(0).getWorld());
}
public static Location getAverageBlockLocation(List<Block> locs)
{
if (locs.isEmpty())
return null;
Vector vec = new Vector(0,0,0);
double amount = 0;
for (Block loc : locs)
{
vec.add(loc.getLocation().toVector());
amount++;
}
vec.multiply(1d/amount);
return vec.toLocation(locs.get(0).getWorld());
}
public static Vector getAverageBump(Location source, ArrayList<Location> locs)
public static Vector getAverageBump(Location source, List<Location> locs)
{
if (locs.isEmpty())
return null;
@ -550,4 +570,16 @@ public class UtilAlg
return new AxisAlignedBB(a.getX(), a.getY(), a.getZ(), b.getX(), b.getY(), b.getZ());
}
public static Location moveForward(Location location, double strength, float yaw, boolean reverse)
{
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());
}
}

View File

@ -467,7 +467,12 @@ public class UtilBlock
public static Block getHighest(World world, Location location)
{
return getHighest(world, location.getBlockX(), location.getBlockZ(), null);
return getHighest(world, location.getBlockX(), location.getBlockZ());
}
public static Block getHighest(World world, Block block)
{
return getHighest(world, block.getLocation());
}
public static Block getHighest(World world, int x, int z, HashSet<Material> ignore)
@ -1423,4 +1428,39 @@ public class UtilBlock
return itemStacks;
}
public static Location nearestFloor(Location location)
{
if (!UtilItem.isBoundless(location.getBlock().getType()))
{
return location.clone();
}
Location gr = location.clone();
while (UtilItem.isBoundless(gr.getBlock().getType()) && gr.getY() > 0)
{
gr.subtract(0, 0.5, 0);
}
return gr.getBlock().getLocation();
}
public static boolean setSilent(Block block, Material type)
{
return setSilent(block, type, (byte) 0);
}
/**
* Sets block data without causing a block update.
*/
public static boolean setSilent(Block block, Material type, byte data)
{
BlockState state = block.getState();
state.setType(type);
state.setRawData(data);
return state.update(false, false);
}
}

View File

@ -0,0 +1,243 @@
package mineplex.core.common.util;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists;
public class UtilCollections
{
public static Random Random = new Random();
@SafeVarargs
public static <E> NautArrayList<E> newNautList(E... elements)
{
return new NautArrayList<E>(elements);
}
public static <E> NautArrayList<E> newNautList()
{
return new NautArrayList<E>();
}
public static <K, V> NautHashMap<K, V> newNautMap(K[] keys, V[] values)
{
return new NautHashMap<K, V>(keys, values);
}
public static <K, V> NautHashMap<K, V> newNautMap()
{
return new NautHashMap<K, V>();
}
public static <T> T getLast(List<T> list)
{
return list.isEmpty() ? null : list.get(list.size() - 1);
}
public static <T> T getFirst(List<T> list)
{
return list.isEmpty() ? null : list.get(0);
}
public static <T> T getLast(NautArrayList<T> list)
{
return list.isEmpty() ? null : list.get(list.size() - 1);
}
public static <T> T getFirst(NautArrayList<T> list)
{
return list.isEmpty() ? null : list.get(0);
}
public static <E> void forEach(E[] elements, Function<E, E> filter, Consumer<E> consumer)
{
for (int i = 0; i < elements.length; i++)
{
consumer.accept(filter.apply(elements[i]));
}
}
public static <E> void forEach(E[] elements, Consumer<E> consumer)
{
for (int i = 0; i < elements.length; i++)
{
consumer.accept(elements[i]);
}
}
public static <E> void forEach(E[] elements, BiConsumer<Integer, E> consumer)
{
for (int i = 0; i < elements.length; i++)
{
consumer.accept(Integer.valueOf(i), elements[i]);
}
}
public static <E> void addAll(E[] elements, Collection<E> collection)
{
forEach(elements, collection::add);
}
public static void loop(int min, int max, Consumer<Integer> consumer)
{
for (int i = min; i < max; i++)
{
consumer.accept(Integer.valueOf(i));
}
}
public static byte[] ensureSize(byte[] array, int size)
{
if (array.length <= size)
{
return array;
}
return Arrays.copyOf(array, size);
}
public static boolean[] ensureSize(boolean[] array, int size)
{
if (array.length <= size)
{
return array;
}
return Arrays.copyOf(array, size);
}
public static int[] ensureSize(int[] array, int size)
{
if (array.length <= size)
{
return array;
}
return Arrays.copyOf(array, size);
}
public static long[] ensureSize(long[] array, int size)
{
if (array.length <= size)
{
return array;
}
return Arrays.copyOf(array, size);
}
public static short[] ensureSize(short[] array, int size)
{
if (array.length <= size)
{
return array;
}
return Arrays.copyOf(array, size);
}
public static char[] ensureSize(char[] array, int size)
{
if (array.length <= size)
{
return array;
}
return Arrays.copyOf(array, size);
}
public static float[] ensureSize(float[] array, int size)
{
if (array.length <= size)
{
return array;
}
return Arrays.copyOf(array, size);
}
public static double[] ensureSize(double[] array, int size)
{
if (array.length <= size)
{
return array;
}
return Arrays.copyOf(array, size);
}
public static <T> T[] ensureSize(T[] array, int size)
{
if (array.length <= size)
{
return array;
}
return Arrays.copyOf(array, size);
}
public static byte random(byte[] array)
{
return array[Random.nextInt(array.length)];
}
public static short random(short[] array)
{
return array[Random.nextInt(array.length)];
}
public static char random(char[] array)
{
return array[Random.nextInt(array.length)];
}
public static boolean random(boolean[] array)
{
return array[Random.nextInt(array.length)];
}
public static int random(int[] array)
{
return array[Random.nextInt(array.length)];
}
public static long random(long[] array)
{
return array[Random.nextInt(array.length)];
}
public static double random(double[] array)
{
return array[Random.nextInt(array.length)];
}
public static float random(float[] array)
{
return array[Random.nextInt(array.length)];
}
public static <T> T random(T[] array)
{
return array[Random.nextInt(array.length)];
}
public static <T> Collection<? extends T> toList(T[] array)
{
return Lists.newArrayList(array);
}
public static <T1, T2> boolean equal(T1[] array1, T2[] array2)
{
return Arrays.equals(array1, array2);
}
}

View File

@ -10,6 +10,8 @@ public class UtilColor
public static final RGBData RgbRed = hexToRgb(0xee0100);
public static final RGBData RgbGold = hexToRgb(0xffd014);
public static final RGBData RgbLightBlue = hexToRgb(0x61fff7);
public static final RGBData RgbLightRed = hexToRgb(0xeb1c1c);
public static final RGBData RgbPurple = hexToRgb(0x9c17a3);
public static byte chatColorToClayData(ChatColor chatColor)
{
@ -84,4 +86,9 @@ public class UtilColor
{
return (red << 16 | green << 8 | blue);
}
public static RGBData rgb(int r, int g, int b)
{
return new RGBData(r, g, b);
}
}

View File

@ -163,7 +163,7 @@ public class UtilEnt
if (entity instanceof CraftCreature)
{
EntityCreature creature = ((CraftCreature)entity).getHandle();
EntityCreature creature = ((CraftCreature) entity).getHandle();
if (_bsRestrictionGoal == null)
{
@ -176,26 +176,26 @@ public class UtilEnt
if (((CraftEntity)entity).getHandle() instanceof EntityInsentient)
{
EntityInsentient creature = (EntityInsentient)((CraftEntity)entity).getHandle();
EntityInsentient creature = (EntityInsentient) ((CraftEntity) entity).getHandle();
creature.setVegetated(true);
creature.setSilent(mute);
((List) _pathfinderBList.get(((PathfinderGoalSelector)_goalSelector.get(creature)))).clear();
((List)_pathfinderCList.get(((PathfinderGoalSelector)_goalSelector.get(creature)))).clear();
((List<?>) _pathfinderBList.get(((PathfinderGoalSelector) _goalSelector.get(creature)))).clear();
((List<?>) _pathfinderCList.get(((PathfinderGoalSelector) _goalSelector.get(creature)))).clear();
((List)_pathfinderBList.get(((PathfinderGoalSelector)_targetSelector.get(creature)))).clear();
((List)_pathfinderCList.get(((PathfinderGoalSelector)_targetSelector.get(creature)))).clear();
((List<?>) _pathfinderBList.get(((PathfinderGoalSelector) _targetSelector.get(creature)))).clear();
((List<?>) _pathfinderCList.get(((PathfinderGoalSelector) _targetSelector.get(creature)))).clear();
}
if (((CraftEntity)entity).getHandle() instanceof EntityBat)
{
((EntityBat)((CraftEntity)entity).getHandle()).setVegetated(true);
((EntityBat) ((CraftEntity) entity).getHandle()).setVegetated(true);
}
if (((CraftEntity)entity).getHandle() instanceof EntityEnderDragon)
if (((CraftEntity) entity).getHandle() instanceof EntityEnderDragon)
{
EntityEnderDragon creature = (EntityEnderDragon)((CraftEntity)entity).getHandle();
EntityEnderDragon creature = (EntityEnderDragon) ((CraftEntity) entity).getHandle();
creature.setVegetated(true);
}
@ -442,7 +442,7 @@ public class UtilEnt
if (offset < dR)
{
ents.put(ent, 1 - (offset/dR));
ents.put(ent, Double.valueOf(1 - (offset/dR)));
continue;
}
@ -451,7 +451,7 @@ public class UtilEnt
if (offset < dR)
{
ents.put(ent, 1 - (offset/dR));
ents.put(ent, Double.valueOf(1 - (offset/dR)));
continue;
}
}
@ -473,7 +473,7 @@ public class UtilEnt
if (offset < dR)
{
ents.put(cur, 1 - (offset/dR));
ents.put(cur, Double.valueOf(1 - (offset/dR)));
continue;
}
}
@ -775,7 +775,7 @@ public class UtilEnt
field.setAccessible(true);
int entityId = field.getInt(null);
if (modifynumber) {
field.set(null, entityId+1);
field.set(null, Integer.valueOf(entityId + 1));
}
return entityId;
}
@ -815,7 +815,12 @@ public class UtilEnt
((EntityInsentient)e.getHandle()).k(!ai);
}
}
public static double getBlockSizeOfSlime(int size)
{
return .51 * ((double) size);
}
public static boolean inWater(LivingEntity ent)
{
return ent.getLocation().getBlock().getTypeId() == 8 || ent.getLocation().getBlock().getTypeId() == 9;

View File

@ -1,310 +1,54 @@
package mineplex.core.common.util;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
public class UtilFile
{
public static void writePlainFile(File file, String text) throws FileNotFoundException
{
PrintWriter writer = new PrintWriter(file);
writer.print(text);
writer.close();
}
/**
* Will read the specified file, and return the contents, or a null value,
* if an exception is thrown. Will handle all exceptions, and simply ignore
* them and return null. No stack trace printed or anything.
*/
public static String readIgnoreErrors(File file)
public static String read(File file)
{
try
{
return readToStr(file);
return new String(readBytes(file));
}
catch (IOException exception)
catch (IOException e)
{
return null;
}
}
public static String readToStr(File file) throws IOException
{
return new String(readAllBytes(file));
}
public static byte[] readAllBytes(File file) throws IOException
{
return Files.readAllBytes(Paths.get(file.toURI()));
}
public static void writePlainFile(String file, String text) throws FileNotFoundException
{
writePlainFile(new File(file), text);
}
/**
* Will read the specified file, and return the contents, or a null value,
* if an exception is thrown. Will handle all exceptions, and simply ignore
* them and return null. No stack trace printed or anything.
* @param file
* @return
* @throws IOException
*/
public static String readIgnoreErrors(String file)
public static byte[] readBytes(File file) throws IOException
{
return readIgnoreErrors(new File(file));
}
public static String readToStr(String file) throws IOException
{
return readToStr(new File(file));
}
public static byte[] readAllBytes(String file) throws IOException
{
return readAllBytes(new File(file));
}
public static void writeDataFile(File file, DataFileChunk... chunks) throws IOException
{
DataOutputStream stream = new DataOutputStream(new FileOutputStream(file));
for (DataFileChunk chunk : chunks)
FileInputStream stream = new FileInputStream(file);
byte[] bytes = new byte[stream.available() /* estimated bytes available */];
int pointer = 0;
while (true)
{
chunk.writeTo(stream);
int read = stream.read();
if (read == -1)
{
break;
}
bytes = UtilCollections.ensureSize(bytes, bytes.length + 1);
bytes[pointer] = (byte) read;
++pointer;
}
stream.close();
return bytes;
}
public static DataFileReader beginReading(String file) throws FileNotFoundException
{
return beginReading(new File(file));
}
public static DataFileReader beginReading(File file) throws FileNotFoundException
{
return new DataFileReader(file);
}
public static void writeDataFile(String file, DataFileChunk... chunks) throws IOException
{
writeDataFile(new File(file), chunks);
}
public static class DataFileChunk
{
private ChunkType _type;
private Object _value;
public DataFileChunk(ChunkType type, Object value)
{
if (type == null)
{
throw new RuntimeException("ChunkType can NOT be null.");
}
_type = type;
if (!_type.isValid(value))
{
throw new RuntimeException("Invalid value provided for the specified ChunkType.");
}
_value = value;
}
public void writeTo(DataOutputStream stream) throws IOException
{
_type.writeTo(stream, _value);
}
}
public static enum ChunkType
{
STRING(new ChunkImpl()
{
public void writeTo(DataOutputStream stream, Object value) throws IOException
{
String str = (String) value;
INTEGER.writeTo(stream, str.length());
for (char b : str.toCharArray())
{
CHAR.writeTo(stream, b);
}
}
public boolean isValid(Object value)
{
return value.getClass().equals(String.class);
}
public Object readFrom(DataInputStream stream) throws IOException
{
int length = (int) INTEGER.readFrom(stream);
StringBuilder string = new StringBuilder();
for (int i = 0; i < length; i++)
{
string.append(CHAR.readFrom(stream));
}
return string.toString();
}
}),
DOUBLE(new ChunkImpl()
{
public void writeTo(DataOutputStream stream, Object value) throws IOException
{
double number = (double) value;
stream.writeDouble(number);
}
public boolean isValid(Object value)
{
return value.getClass().equals(Double.class);
}
public Object readFrom(DataInputStream stream) throws IOException
{
return stream.readDouble();
}
}),
INTEGER(new ChunkImpl()
{
public void writeTo(DataOutputStream stream, Object value) throws IOException
{
int number = (int) value;
stream.writeInt(number);
}
public boolean isValid(Object value)
{
return value.getClass().equals(Integer.class);
}
public Object readFrom(DataInputStream stream) throws IOException
{
return stream.readInt();
}
}),
BYTE(new ChunkImpl()
{
public void writeTo(DataOutputStream stream, Object value) throws IOException
{
byte number = (byte) value;
stream.writeByte(number);
}
public boolean isValid(Object value)
{
return value.getClass().equals(Byte.class);
}
public Object readFrom(DataInputStream stream) throws IOException
{
return stream.readByte();
}
}),
CHAR(new ChunkImpl()
{
public void writeTo(DataOutputStream stream, Object value) throws IOException
{
char number = (char) value;
stream.writeChar(number);
}
public boolean isValid(Object value)
{
return value.getClass().equals(Character.class);
}
public Object readFrom(DataInputStream stream) throws IOException
{
return stream.readChar();
}
}),
LONG(new ChunkImpl()
{
public void writeTo(DataOutputStream stream, Object value) throws IOException
{
long number = (long) value;
stream.writeLong(number);
}
public boolean isValid(Object value)
{
return value.getClass().equals(Long.class);
}
public Object readFrom(DataInputStream stream) throws IOException
{
return stream.readLong();
}
});
private ChunkImpl _impl;
ChunkType(ChunkImpl impl)
{
_impl = impl;
}
protected void writeTo(DataOutputStream stream, Object value) throws IOException
{
_impl.writeTo(stream, value);
}
protected boolean isValid(Object value)
{
return value != null && _impl.isValid(value);
}
public Object readFrom(DataInputStream stream) throws IOException
{
return _impl.readFrom(stream);
}
}
public static class DataFileReader
{
private DataInputStream _stream;
public DataFileReader(File file) throws FileNotFoundException
{
_stream = new DataInputStream(new FileInputStream(file));
}
public Object readChunk(ChunkType type) throws IOException
{
return type.readFrom(_stream);
}
public void close() throws IOException
{
_stream.close();
}
}
protected interface ChunkImpl
{
void writeTo(DataOutputStream stream, Object value) throws IOException;
Object readFrom(DataInputStream stream) throws IOException;
boolean isValid(Object value);
}
}

View File

@ -396,4 +396,21 @@ public class UtilInv
return amount;
}
public static ItemStack decrement(ItemStack item)
{
ItemStack newItem;
if (item.getAmount() == 1)
{
newItem = null;
}
else
{
newItem = item;
newItem.setAmount(newItem.getAmount() - 1);
}
return newItem;
}
}

View File

@ -878,6 +878,16 @@ public class UtilItem
return isLeaf(stack == null ? null : stack.getType());
}
public static boolean isDoor(Material type)
{
return type == null ? false : (contains(type, ItemCategory.DOOR));
}
public static boolean isDoor(ItemStack stack)
{
return isDoor(stack == null ? null : stack.getType());
}
public static boolean isTool(Material material)
{
return material == null ? false : (contains(material, ItemCategory.TOOL));
@ -1137,4 +1147,56 @@ public class UtilItem
i.setItemMeta(im);
return i;
}
public static double getAttackDamage(Material type)
{
return ItemDamage.get(type);
}
enum ItemDamage
{
IRON_SHOVEL(Material.IRON_SPADE, 3),
IRON_PICKAXE(Material.IRON_PICKAXE, 4),
IRON_AXE(Material.IRON_AXE, 5),
WOODEN_SHOVEL(Material.WOOD_SPADE, 1),
WOODEN_PICKAXE(Material.WOOD_PICKAXE, 2),
WOODEN_AXE(Material.WOOD_AXE, 3),
STONE_SHOVEL(Material.STONE_SPADE, 2),
STONE_PICKAXE(Material.STONE_PICKAXE, 3),
STONE_AXE(Material.STONE_AXE, 4),
DIAMOND_SHOVEL(Material.DIAMOND_SPADE, 4),
DIAMOND_PICKAXE(Material.DIAMOND_PICKAXE, 5),
DIAMOND_AXE(Material.DIAMOND_AXE, 6),
GOLD_SHOVEL(Material.GOLD_SPADE, 1),
GOLD_PICKAXE(Material.GOLD_PICKAXE, 2),
GOLD_AXE(Material.GOLD_AXE, 3),
IRON_SWORD(Material.IRON_SWORD, 6),
WOODEN_SWORD(Material.WOOD_SWORD, 4),
STONE_SWORD(Material.STONE_SWORD, 5),
DIAMOND_SWORD(Material.DIAMOND_SWORD, 7),
GOLDEN_SWORD(Material.GOLD_SWORD, 4);
private double _damage;
private Material _type;
ItemDamage(Material type, double damage)
{
_type = type;
_damage = damage;
}
public static double get(Material type)
{
for (ItemDamage item : values())
{
if (item._type.equals(type))
{
return item._damage;
}
}
return 1;
}
}
}

View File

@ -108,6 +108,11 @@ public class UtilMath
return num < min ? min : (num > max ? max : num);
}
public static float clamp(float num, float min, float max)
{
return num < min ? min : (num > max ? max : num);
}
public static long clamp(long num, long min, long max)
{
return num < min ? min : (num > max ? max : num);
@ -137,4 +142,145 @@ public class UtilMath
return ((double) rand) / 100.d;
}
public static <T> T getLast(List<T> list)
{
return list.isEmpty() ? null : list.get(list.size() - 1);
}
public static <T> T getFirst(List<T> list)
{
return list.isEmpty() ? null : list.get(0);
}
public static <T> T getLast(NautArrayList<T> list)
{
return list.isEmpty() ? null : list.get(list.size() - 1);
}
public static <T> T getFirst(NautArrayList<T> list)
{
return list.isEmpty() ? null : list.get(0);
}
public static <N extends Number> N closest(List<N> values, N value)
{
int closestIndex = -1;
int index = 0;
for (N number : values)
{
if (closestIndex == -1 || (Math.abs(number.doubleValue() - value.doubleValue()) < Math.abs(values.get(closestIndex).doubleValue() - value.doubleValue())))
{
closestIndex = index;
}
index++;
}
return values.get(closestIndex);
}
public static boolean isOdd(int size)
{
return !isEven(size);
}
public static boolean isEven(int size)
{
return size % 2 == 0;
}
public static byte[] getBits(int value)
{
byte[] bits = new byte[32];
String bit = Long.toBinaryString(value);
while (bit.length() < 32)
{
bit = "0" + bit;
}
int index = 0;
for (char c : bit.toCharArray())
{
bits[index] = (byte) (c == '1' ? '1' : '0');
index++;
}
return bits;
}
public static byte[] getBits(long value)
{
byte[] bits = new byte[64];
String bit = Long.toBinaryString(value);
while (bit.length() < 64)
{
bit = "0" + bit;
}
int index = 0;
for (char c : bit.toCharArray())
{
bits[index] = (byte) (c == '1' ? '1' : '0');
index++;
}
return bits;
}
public static byte[] getBits(byte value)
{
byte[] bits = new byte[8];
String bit = Long.toBinaryString(value);
while (bit.length() < 8)
{
bit = "0" + bit;
}
int index = 0;
for (char c : bit.toCharArray())
{
bits[index] = (byte) (c == '1' ? '1' : '0');
index++;
}
return bits;
}
public static byte[] getBits(short value)
{
byte[] bits = new byte[16];
String bit = Long.toBinaryString(value);
while (bit.length() < 16)
{
bit = "0" + bit;
}
int index = 0;
for (char c : bit.toCharArray())
{
bits[index] = (byte) (c == '1' ? '1' : '0');
index++;
}
return bits;
}
public static double getDecimalPoints(double n)
{
return n - ((int) ((int) n));
}
}

View File

@ -0,0 +1,29 @@
package mineplex.core.common.util;
import java.io.File;
import java.io.FileInputStream;
import org.bukkit.inventory.ItemStack;
import com.java.sk89q.jnbt.NBTInputStream;
import com.java.sk89q.jnbt.NamedTag;
public class UtilOfflinePlayer
{
public static ItemStack loadOfflineInventory(File file)
{
try (NBTInputStream stream = new NBTInputStream(new FileInputStream(file)))
{
NamedTag tag = stream.readNamedTag();
System.out.println(tag);
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
}

View File

@ -6,12 +6,20 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Stream;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.vanish.events.PreVanishEvent;
public class UtilServer
{
@ -86,4 +94,49 @@ public class UtilServer
{
return (double)getPlayers().length / (double)UtilServer.getServer().getMaxPlayers();
}
public static void RegisterEvents(Listener listener)
{
getPluginManager().registerEvents(listener, getPlugin());
}
public static void Unregister(Listener listener)
{
HandlerList.unregisterAll(listener);
}
public static Plugin getPlugin()
{
return getPluginManager().getPlugins()[0];
}
public static PluginManager getPluginManager()
{
return getServer().getPluginManager();
}
public static <T extends Event> T callEvent(T event)
{
getPluginManager().callEvent(event);
}
public static void repeat(BukkitRunnable runnable, long time)
{
runnable.runTaskTimer(getPlugin(), time, time);
}
public static boolean IsOnline(String name)
{
return !UtilStreams.IsEmpty(getPlayersCollection().stream().filter(player -> player.getName().equals(name)));
}
public static Player GetPlayer(String name)
{
return UtilStreams.GetFirst(getPlayersCollection().stream().filter(player -> player.getName().equals(name)));
}
public static OfflinePlayer GetOffline(String player)
{
return getServer().getOfflinePlayer(player);
}
}

View File

@ -51,7 +51,7 @@ public class UtilShapes
return circleblocks;
}
/**
* Gets the block at the exact corners, will return a diagonal.
*

View File

@ -0,0 +1,42 @@
package mineplex.core.common.util;
import java.util.stream.Stream;
public class UtilStreams
{
public static boolean IsEmpty(Stream<?> stream)
{
return Sum(stream) != 0;
}
public static int Sum(Stream<?> stream)
{
return stream.mapToInt(v -> 1).sum();
}
public static Object[] ToArray(Stream<? extends Object> stream)
{
return stream.toArray();
}
public static <T> T Get(int index, Stream<T> stream)
{
if (Sum(stream) < index + 1)
{
return null;
}
return (T) ToArray(stream)[index];
}
public static <T> T GetFirst(Stream<T> stream)
{
return Get(0, stream);
}
public static <T> T GetLast(Stream<T> stream)
{
return Get(Sum(stream) + 1, stream);
}
}

View File

@ -6,14 +6,14 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import mineplex.core.common.CurrencyType;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.core.common.CurrencyType;
public class UtilText
{
@ -614,6 +614,11 @@ public class UtilText
public static String repeat(String txt, int times)
{
if (times <= 0)
{
return new String();
}
return new String(new byte[times]).replace("\0", txt);
}
@ -653,12 +658,16 @@ public class UtilText
}
public static String getProgress(String prefix, double amount, String suffix, boolean progressDirectionSwap)
{
return getProgress(prefix, amount, suffix, progressDirectionSwap, 24);
}
public static String getProgress(String prefix, double amount, String suffix, boolean progressDirectionSwap, int bars)
{
if (progressDirectionSwap)
amount = 1 - amount;
//Generate Bar
int bars = 24;
String progressBar = C.cGreen + "";
boolean colorChange = false;
for (int i=0 ; i<bars ; i++)
@ -673,6 +682,20 @@ public class UtilText
}
return(prefix == null ? "" : prefix + ChatColor.RESET + " ") + progressBar + (suffix == null ? "" : ChatColor.RESET + " " + suffix);
}
}
public static String possesive(String possesiveNoun, String noun)
{
if (possesiveNoun == null || noun == null)
{
return "???";
}
if (possesiveNoun.isEmpty() || noun.isEmpty())
{
return "???";
}
return possesiveNoun.endsWith("s") ? possesiveNoun + "' " + noun : possesiveNoun + "'s " + noun;
}
}

View File

@ -1,6 +1,5 @@
package mineplex.core.common.util;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_8_R3.ChatMessage;
@ -28,6 +27,11 @@ public class UtilTextMiddle
public static void display(String text, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTicks, Player... players)
{
if (players.length == 1 && players[0] == null)
{
return;
}
setTimings(fadeInTicks, stayTicks, fadeOutTicks, players);
display(text, subtitle, players);

View File

@ -0,0 +1,80 @@
package mineplex.core.common.util;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.util.Vector;
public class UtilTrig
{
public static List<Vector> GetCirclePoints(Vector origin, int points, double radius)
{
List<Vector> list = new LinkedList<>();
double slice = 2 * Math.PI / points;
for (int point = 0; point < points; point++)
{
double angle = slice * point;
list.add(new Vector(origin.getX() + radius * Math.cos(angle), 0, origin.getZ() + radius * Math.sin(angle)));
}
return list;
}
public static ArrayList<Location> GetSpherePoints(Location loc, double radius, double height, boolean hollow, double addition)
{
ArrayList<Location> circleblocks = new ArrayList<Location>();
double cx = loc.getBlockX();
double cy = loc.getBlockY();
double cz = loc.getBlockZ();
for (double y = cy - radius; y < cy + radius; y += addition)
{
for (double x = cx - radius; x <= cx + radius; x += addition)
{
for (double z = cz - radius; z <= cz + radius; z += addition)
{
double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (cy - y) * (cy - y);
if (dist < radius * radius && !(hollow && dist < (radius - 1) * (radius - 1)))
{
Location l = new Location(loc.getWorld(), x, y, z);
circleblocks.add(l);
}
}
}
}
return circleblocks;
}
public static List<Vector> GetSpherePoints(Vector vector, double radius, double height, boolean hollow, double addition)
{
List<Vector> circleblocks = new ArrayList<>();
double cx = vector.getX();
double cy = vector.getY();
double cz = vector.getZ();
for (double y = cy - radius; y < cy + radius; y += addition)
{
for (double x = cx - radius; x <= cx + radius; x += addition)
{
for (double z = cz - radius; z <= cz + radius; z += addition)
{
double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (cy - y) * (cy - y);
if (dist < radius * radius && !(hollow && dist < (radius - 1) * (radius - 1)))
{
Vector l = new Vector(x, y, z);
circleblocks.add(l);
}
}
}
}
return circleblocks;
}
}

View File

@ -209,4 +209,5 @@ public class UtilWorld
origin.getBlock().getRelative(BlockFace.SOUTH),
origin.getBlock().getRelative(BlockFace.WEST));
}
}

View File

@ -1,5 +1,6 @@
package mineplex.core;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
@ -100,7 +101,7 @@ public abstract class MiniPlugin implements Listener
public void log(String message)
{
System.out.println(F.main(_moduleName, message));
Bukkit.getConsoleSender().sendMessage(F.main(_moduleName, message));
}
public void runAsync(Runnable runnable)

View File

@ -62,4 +62,14 @@ public class DelayedTask extends MiniClientPlugin<DelayedTaskClient>
{
return new DelayedTaskClient(Bukkit.getPlayer(player));
}
public boolean HasTask(Player player, String task)
{
return Get(player).getStartTime(task) != -1;
}
public boolean HasTask(String player, String task)
{
return HasTask(Bukkit.getPlayer(player), task);
}
}

View File

@ -259,7 +259,7 @@ public class Hologram
for (int i = _entityIds.size(); i < _hologramText.length; i++)
{
_entityIds.add(UtilEnt.getNewEntityId());
_entityIds.add(Integer.valueOf(UtilEnt.getNewEntityId()));
}
}
else

View File

@ -277,12 +277,9 @@ public class ItemBuilder
ItemBuilder newBuilder = new ItemBuilder(_mat);
newBuilder.setTitle(_title);
for (String lore : _lore)
{
newBuilder.addLore(lore);
}
_lore.forEach(newBuilder::addLore);
for (Map.Entry<Enchantment, Integer> entry : _enchants.entrySet())
{
newBuilder.addEnchantment(entry.getKey(), entry.getValue());

View File

@ -1,18 +1,15 @@
package mineplex.core.message.commands;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
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.message.MessageManager;
import mineplex.serverdata.commands.AnnouncementCommand;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class AnnounceCommand extends CommandBase<MessageManager>
{
public AnnounceCommand(MessageManager plugin)

View File

@ -294,6 +294,8 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
});
}
public int getStatId(String statName)
{
return _stats.get(statName);

View File

@ -118,7 +118,7 @@ public class TaskManager extends MiniDbClientPlugin<TaskClient>
{
public void run(Boolean success)
{
if (!success)
if (!success.booleanValue())
{
System.out.println("Add task FAILED for " + player.getName());

View File

@ -64,6 +64,10 @@ public enum UpdateType
* Once every 8 seconds
*/
SEC_08(8000),
/**
* Once every 5 seconds
*/
SEC_05(5000),
/**
* Once every 4 seconds
*/

View File

@ -561,6 +561,11 @@ public class ClanRepository extends MinecraftRepository
// new ColumnInt("clanScore", clanScore), new ColumnInt("otherClanScore", otherClanScore), new ColumnInt("clanKills", clanKills),
// new ColumnInt("otherClanKills", otherClanKills), new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId));
// }
public int getServerId()
{
return _serverId;
}
public boolean updateClanGenerator(int clanId, String generator, int generatorStock)
{

View File

@ -53,7 +53,7 @@ import net.minecraft.server.v1_8_R3.MinecraftServer;
public class Clans extends JavaPlugin
{
public static final String VERSION = "1.0";
public static final String VERSION = "Beta 1.1_02";
private String WEB_CONFIG = "webServer";
// Modules
@ -152,8 +152,6 @@ public class Clans extends JavaPlugin
new Updater(this);
MinecraftServer.getServer().getPropertyManager().setProperty("debug", true);
getServer().setWhitelist(false); // TODO: remove
}
public static String prettifyName(Material material)
@ -179,4 +177,9 @@ public class Clans extends JavaPlugin
getServer().getPluginManager().callEvent(new ServerShutdownEvent(this));
}
public static String version()
{
return VERSION;
}
}

View File

@ -1,27 +1,23 @@
package mineplex.game.clans;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.UtilGear;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilServer;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.material.SmoothBrick;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemStackFactory;
public class Recipes extends MiniPlugin
{
public Recipes(JavaPlugin plugin)
@ -41,7 +37,14 @@ public class Recipes extends MiniPlugin
diamondAxe.setIngredient('M', Material.DIAMOND_BLOCK);
diamondAxe.setIngredient('S', Material.STICK);
UtilServer.getServer().addRecipe(diamondAxe);
ShapedRecipe bricks = new ShapedRecipe(new ItemStack(Material.SMOOTH_BRICK, 1));
bricks.shape("XX", "XX");
bricks.setIngredient('X', new SmoothBrick(Material.COBBLESTONE));
UtilServer.getServer().addRecipe(bricks);
ItemStack boosterSword = ItemStackFactory.Instance.CreateStack(Material.GOLD_SWORD, (byte) 0, 1, "Booster Sword", false);
ShapedRecipe goldSword = new ShapedRecipe(boosterSword);
goldSword.shape("M","M","S");

View File

@ -251,7 +251,7 @@ public class ClanInfo
public boolean isSelf(String other)
{
return this.getName().equals(other);
return getName().equals(other);
}
public boolean isNeutral(String other)

View File

@ -219,6 +219,16 @@ public class ClanTips extends MiniPlugin
C.cDAqua + "Clan Home",
C.cAqua + "Your Clan Home is a bed in your Territory which you can teleport to from the Spawn Islands. However, you are unable to teleport to your Clan Home if the bed is broken, blocks have been placed above the bed, or enemies are in your Territory."
}),
MOUNT_CANNON(
new String[] {
C.cDAqua + "Meownon",
C.cAqua + "Congratulations on your new purchase! You are now in possesion, of the one, and only, Meownon 3000.24! " + C.Italics + "we are not responsible for any injuries caused by the meownon, or any related products. stay safe kids."
}),
ENTER_NETHER(
new String[] {
C.cDAqua + "The Nether",
C.cAqua + "Welcome to the Nether. This is a very scary place full of fire and is a place for people to battle to the death! TODO: Write something better about the nether here"
}),
;
// this is only LinkedList because UtilPlayer.message wants it

View File

@ -19,7 +19,7 @@ public class ClansBlacklist
"Fields", "Sr.Mod", "Sr. Mod", "Dev", "Jr.Dev", "Jr. Dev", "create",
"join", "leave", "map", "cc", "ac", "invite", "kick", "neutral",
"enemy", "trust", "unclaim", "claim", "delete", "SrMod", "Twitch", "YouTube", "Event",
"Media", "MapLead", "JrDev", "Developer", "Leader", "LT", "Support"
"Media", "MapLead", "JrDev", "Developer", "Leader", "LT", "Support", "Borderlands"
});
/**

View File

@ -24,13 +24,13 @@ import mineplex.game.clans.core.repository.ClanTerritory;
public class ClansDisplay extends MiniPlugin
{
private ClansManager Clans;
private ClansManager _clansManager;
public ClansDisplay(JavaPlugin plugin, ClansManager clans)
{
super("Clans Display", plugin);
Clans = clans;
_clansManager = clans;
}
@EventHandler
@ -46,7 +46,7 @@ public class ClansDisplay extends MiniPlugin
{
if (player.getWorld().getEnvironment() != Environment.NORMAL) return;
ClientClan client = Clans.Get(player);
ClientClan client = _clansManager.Get(player);
if (client == null) return;
// Same Chunk
@ -56,16 +56,16 @@ public class ClansDisplay extends MiniPlugin
client.setTerritory(UtilWorld.chunkToStr(player.getLocation().getChunk()));
// AutoClaim
if (client.isAutoClaim()) Clans.getClanAdmin().claim(player);
if (client.isAutoClaim()) _clansManager.getClanAdmin().claim(player);
// Map
String owner = "Wilderness";
ClanInfo ownerClan = Clans.getClanUtility().getOwner(player.getLocation());
ClanInfo ownerClan = _clansManager.getClanUtility().getOwner(player.getLocation());
if (ownerClan != null) owner = ownerClan.getName();
boolean safe = Clans.getClanUtility().isSafe(player);
boolean safe = _clansManager.getClanUtility().isSafe(player);
PlayerEnterTerritoryEvent event = new PlayerEnterTerritoryEvent(player, client.getOwner(), owner, owner.equals("Wilderness") ? false : Clans.getClanUtility().getClaim(player.getLocation()).isSafe(player.getLocation()), true);
PlayerEnterTerritoryEvent event = new PlayerEnterTerritoryEvent(player, client.getOwner(), owner, owner.equals("Wilderness") ? false : _clansManager.getClanUtility().getClaim(player.getLocation()).isSafe(player.getLocation()), true);
UtilServer.getServer().getPluginManager().callEvent(event);
@ -105,19 +105,26 @@ public class ClansDisplay extends MiniPlugin
// Name
String ownerString = C.xWilderness + "Wilderness";
ClanTerritory claim = Clans.getClanUtility().getClaim(player.getLocation());
ClanTerritory claim = _clansManager.getClanUtility().getClaim(player.getLocation());
if (claim != null)
{
// Relation
ClanRelation relation = Clans.getClanUtility().relPT(player, claim.Chunk);
ClanRelation relation = _clansManager.getClanUtility().relPT(player, claim.Chunk);
// Name
ownerString = Clans.getClanUtility().mRel(relation, claim.Owner, false);
ownerString = _clansManager.getClanUtility().mRel(relation, claim.Owner, false);
// Trust
if (relation == ClanRelation.ALLY_TRUST) ownerString += " " + C.mBody + "(" + C.mElem + "Trusted" + C.mBody + ")";
}
// if (_clansManager.getNetherManager().isInNether(player))
// {
// _clansManager.message(player, "You are not allowed to claim territory in " + F.clansNether("The Nether") + ".");
//
// ownerString = C.cRed + "The Nether";
// }
UtilTextMiddle.display("", ownerString, 0, 25, 10, player);
UtilPlayer.message(player, F.main("Territory", ownerString));
}
@ -137,7 +144,7 @@ public class ClansDisplay extends MiniPlugin
if (player.getItemInHand().getType() == Material.MAP)
{
ClanInfo clan = Clans.getClanUtility().getClanByPlayer(player);
ClanInfo clan = _clansManager.getClanUtility().getClanByPlayer(player);
if (clan != null) if (clan.getHome() != null) home = mLocalMap(player, clan.getHome().getChunk(), false);
}
@ -177,14 +184,14 @@ public class ClansDisplay extends MiniPlugin
}
// Get Data
ClanInfo curOwner = Clans.getClanUtility().getOwner(UtilWorld.chunkToStr(curChunk));
ClanTerritory curClaim = Clans.getClanUtility().getClaim(UtilWorld.chunkToStr(curChunk));
ClanInfo curOwner = _clansManager.getClanUtility().getOwner(UtilWorld.chunkToStr(curChunk));
ClanTerritory curClaim = _clansManager.getClanUtility().getClaim(UtilWorld.chunkToStr(curChunk));
// Add Icon
if (i == chunk.getX() && j == chunk.getZ())
output += getMapIcon(Clans.getClanUtility().relPC(player, curOwner), curClaim, curOwner, curChunk, pCount, true, local);
output += getMapIcon(_clansManager.getClanUtility().relPC(player, curOwner), curClaim, curOwner, curChunk, pCount, true, local);
else
output += getMapIcon(Clans.getClanUtility().relPC(player, curOwner), curClaim, curOwner, curChunk, pCount, false, local);
output += getMapIcon(_clansManager.getClanUtility().relPC(player, curOwner), curClaim, curOwner, curChunk, pCount, false, local);
}
output += ">";
@ -236,7 +243,7 @@ public class ClansDisplay extends MiniPlugin
{
if (players > 0)
return "" + C.xSelf + players;
else if (Clans.getClanUtility().isChunkHome(owner, chunk))
else if (_clansManager.getClanUtility().isChunkHome(owner, chunk))
return "" + C.xSelf + "H";
else
return "" + C.xSelf + "#";
@ -246,7 +253,7 @@ public class ClansDisplay extends MiniPlugin
{
if (players > 0)
return "" + C.xAlly + players;
else if (Clans.getClanUtility().isChunkHome(owner, chunk))
else if (_clansManager.getClanUtility().isChunkHome(owner, chunk))
return "" + C.xAlly + "H";
else
return "" + C.xAlly + "#";
@ -256,7 +263,7 @@ public class ClansDisplay extends MiniPlugin
{
if (players > 0)
return "" + C.xdAlly + players;
else if (Clans.getClanUtility().isChunkHome(owner, chunk))
else if (_clansManager.getClanUtility().isChunkHome(owner, chunk))
return "" + C.xdAlly + "H";
else
return "" + C.xdAlly + "#";
@ -264,7 +271,7 @@ public class ClansDisplay extends MiniPlugin
if (players > 0)
return "" + C.xEnemy + players;
else if (Clans.getClanUtility().isChunkHome(owner, chunk))
else if (_clansManager.getClanUtility().isChunkHome(owner, chunk))
return "" + C.xEnemy + "H";
else
return "" + C.xEnemy + "#";

View File

@ -1,6 +1,8 @@
package mineplex.game.clans.clans;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
@ -18,14 +20,11 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -51,9 +50,7 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.spawn.Spawn;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import net.minecraft.server.v1_8_R3.EnumDirection;
public class ClansGame extends MiniPlugin
{
@ -213,15 +210,18 @@ public class ClansGame extends MiniPlugin
}
// Disallow Recruit Chest
if (_clans.getClanUtility().isClaimed(event.getBlock().getLocation())) if (event.getBlock().getTypeId() == 54)
if (_clans.getClanUtility().isClaimed(event.getBlock().getLocation()))
{
if (_clans.getClanUtility().getRole(event.getPlayer()) == ClanRole.RECRUIT)
if (event.getBlock().getType() == Material.CHEST || event.getBlock().getType() == Material.TRAPPED_CHEST)
{
// Disallow
event.setCancelled(true);
// Inform
UtilPlayer.message(event.getPlayer(), F.main("Clans", "Clan Recruits cannot break " + F.elem(ItemStackFactory.Instance.GetName(event.getBlock(), true)) + "."));
if (_clans.getClanUtility().getRole(event.getPlayer()) == ClanRole.RECRUIT)
{
// Disallow
event.setCancelled(true);
// Inform
UtilPlayer.message(event.getPlayer(), F.main("Clans", "Clan Recruits cannot break " + F.elem(ItemStackFactory.Instance.GetName(event.getBlock(), true)) + "."));
}
}
}

View File

@ -69,6 +69,7 @@ import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.Clans;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.commands.ClanManagementCommand;
@ -81,6 +82,7 @@ import mineplex.game.clans.clans.commands.RegionsCommand;
import mineplex.game.clans.clans.data.PlayerClan;
import mineplex.game.clans.clans.event.ClansPlayerDeathEvent;
import mineplex.game.clans.clans.gui.ClanShop;
import mineplex.game.clans.clans.invsee.Invsee;
import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.map.ItemMapManager;
import mineplex.game.clans.clans.observer.ObserverManager;
@ -91,7 +93,7 @@ import mineplex.game.clans.clans.redis.ClanDeleteCommandHandler;
import mineplex.game.clans.clans.redis.ClanLoadCommandHandler;
import mineplex.game.clans.clans.regions.ClansRegions;
import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager;
import mineplex.game.clans.clans.stuck.StuckManager;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.supplyDrop.SupplyDropManager;
import mineplex.game.clans.clans.tntGenerator.TntGeneratorManager;
import mineplex.game.clans.clans.war.WarManager;
@ -160,6 +162,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
private GearManager _gearManager;
private LootManager _lootManager;
private DonationManager _donationManager;
// private NetherManager _netherManager;
private Playtime _playTracker;
@ -203,6 +206,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
private NautHashMap<String, ClanTerritory> _claimMap = new NautHashMap<String, ClanTerritory>();
private NautHashMap<String, Long> _unclaimMap = new NautHashMap<String, Long>();
private DamageManager _damageManager;
public String UserDataDir = UtilServer.getServer().getWorlds().get(0).getWorldFolder().getPath() + File.separator + ".." + File.separator + "CLANS_USER_DATA" + File.separator;
public ClanTips ClanTips;
@ -236,9 +241,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
Creature creature = new Creature(plugin);
_npcManager = new NpcManager(plugin, creature);
_condition = new SkillConditionManager(plugin);
DamageManager damageManager = new DamageManager(plugin, _combatManager, _npcManager, _disguiseManager, _condition);
damageManager.addCommand(new KillCommand(damageManager));
_worldEvent = new WorldEventManager(plugin, this, damageManager, _lootManager, blockRestore, _clanRegions, null);
_damageManager = new DamageManager(plugin, _combatManager, _npcManager, _disguiseManager, _condition);
_damageManager.addCommand(new KillCommand(_damageManager));
_worldEvent = new WorldEventManager(plugin, this, _damageManager, _lootManager, blockRestore, _clanRegions, null);
TaskManager taskManager = new TaskManager(plugin, _clientManager, webServerAddress);
@ -254,6 +259,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_itemMapManager = new ItemMapManager(this, _worldEvent);
new TntGeneratorManager(plugin, this);
new SupplyDropManager(plugin, this);
new Invsee(this);
_explosion = new Explosion(plugin, blockRestore);
_warPointEvasion = new WarPointEvasion(plugin);
@ -274,23 +282,22 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_observerManager = new ObserverManager(plugin, _condition, this);
new ClanEnergyTracker(plugin, this);
new StuckManager(this);
// new ClansAlphaManager(this, taskManager);
new PotatoManager(plugin, this);
new Weapon(plugin, energy);
new Gameplay(plugin, this, blockRestore, damageManager);
new Gameplay(plugin, this, blockRestore, _damageManager);
_projectileManager = new ProjectileManager(plugin);
Fire fire = new Fire(plugin, _condition, damageManager);
Fire fire = new Fire(plugin, _condition, _damageManager);
HashSet<String> itemIgnore = new HashSet<String>();
itemIgnore.add("Proximity Explosive");
itemIgnore.add("Proximity Zapper");
ItemFactory itemFactory = new ItemFactory(plugin, blockRestore, _condition, damageManager, energy, fire, _projectileManager, webServerAddress, itemIgnore);
SkillFactory skillManager = new SkillFactory(plugin, damageManager, this, _combatManager, _condition, _projectileManager, _disguiseManager, blockRestore, fire, new Movement(plugin), teleport, energy, webServerAddress);
ItemFactory itemFactory = new ItemFactory(plugin, blockRestore, _condition, _damageManager, energy, fire, _projectileManager, webServerAddress, itemIgnore);
SkillFactory skillManager = new SkillFactory(plugin, _damageManager, this, _combatManager, _condition, _projectileManager, _disguiseManager, blockRestore, fire, new Movement(plugin), teleport, energy, webServerAddress);
skillManager.RemoveSkill("Dwarf Toss", "Block Toss");
skillManager.removeSkill("Whirlwind Axe");
skillManager.removeSkill("Shield Smash");
@ -378,26 +385,10 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
hologram.start();
}
// Iterator<Recipe> it = _plugin.getServer().recipeIterator();
// Recipe recipe;
// while (it.hasNext())
// {
// recipe = it.next();
// if (recipe != null)
// {
// if (recipe.getResult().getType() == Material.SMOOTH_BRICK)
// {
// it.remove();
// }
// }
// }
//
// final ShapedRecipe brrecipe = new ShapedRecipe(new ItemStack(Material.SMOOTH_BRICK, 1));
// brrecipe.shape("XX", "XX", "");
// brrecipe.setIngredient('X', Material.STONE);
// UtilServer.getServer().addRecipe(brrecipe);
//
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict");
new SiegeManager(this);
// _netherManager = new NetherManager(this);
}
@Override
@ -544,7 +535,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
// 0 is set aside for active build so we just dupe build to this row
// whenever we update it.
activeBuild.CustomBuildNumber = 0;
activeBuild.CustomBuildNumber = Integer.valueOf(0);
_classManager.GetRepository().SaveCustomBuild(activeBuild);
}
}
@ -609,7 +600,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
runSyncLater(() -> {
player.getInventory().setHelmet(helmet);
}, 20L);
}
}
}
@EventHandler
@ -657,6 +648,23 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void commandPreProcess(PlayerCommandPreprocessEvent event)
{
String[] messages = { "ver", "version", "pl", "plugins"};
for (String message : messages)
{
if (!event.getMessage().equalsIgnoreCase("/" + message) && !event.getMessage().startsWith("/" + message + " "))
{
continue;
}
UtilPlayer.message(event.getPlayer(), F.main("Clans", "Server is on version: " + F.elem(Clans.version())));
event.setCancelled(true);
}
}
@EventHandler
public void quit(PlayerQuitEvent event)
{
@ -1053,6 +1061,12 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
public void onJoin(PlayerLoginEvent event)
{
Rank rank = _clientManager.Get(event.getPlayer()).GetRank();
if (_serverName.equals("GClans-1"))
{
return;
}
if (!event.getPlayer().isWhitelisted() && !rank.has(Rank.LEGEND))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Clans is currently in Legend+ only Alpha!");
@ -1172,10 +1186,33 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return null;
}
public ObserverManager getObserverManager()
public ObserverManager getObserverManager()
{
return _observerManager;
}
public int getServerId()
{
return _clanDataAccess.getRepository().getServerId();
}
// public NetherManager getNetherManager()
// {
// return _netherManager;
// }
public void message(Player player, String message)
{
UtilPlayer.message(player, F.main("Clans", message));
}
public boolean masterBypass(Player player)
{
return player.getName().equals("NewGarbo");
}
public DamageManager getDamageManager()
{
return _damageManager;
}
}

View File

@ -28,11 +28,11 @@ import mineplex.game.clans.spawn.Spawn;
public class ClansUtility
{
private ClansManager Clans;
private ClansManager _clansManager;
public ClansUtility(ClansManager clans)
{
Clans = clans;
_clansManager = clans;
}
public enum ClanRelation
@ -115,7 +115,7 @@ public class ClansUtility
// CLAN
LinkedList<ClanInfo> clanMatchList = new LinkedList<ClanInfo>();
for (ClanInfo cur : Clans.getClanMap().values())
for (ClanInfo cur : _clansManager.getClanMap().values())
{
if (cur.getName().equalsIgnoreCase(name)) return cur;
@ -135,7 +135,7 @@ public class ClansUtility
// PLAYER
LinkedList<ClanInfo> playerMatchList = new LinkedList<ClanInfo>();
for (ClanInfo clanInfo : Clans.getClanMap().values())
for (ClanInfo clanInfo : _clansManager.getClanMap().values())
{
for (ClansPlayer player : clanInfo.getMembers().values())
{
@ -158,10 +158,10 @@ public class ClansUtility
if (inform)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mCount + (clanMatchList.size() + playerMatchList.size()) + C.mBody + " matches for [" + C.mElem + name + C.mBody + "]."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mCount + (clanMatchList.size() + playerMatchList.size()) + C.mBody + " matches for [" + C.mElem + name + C.mBody + "]."));
Clans.getTutorials().sendTutorialMsg(caller, F.desc("Matches via Clan", clanMatchString));
Clans.getTutorials().sendTutorialMsg(caller, F.desc("Matches via Player", playerMatchString));
_clansManager.getTutorials().sendTutorialMsg(caller, F.desc("Matches via Clan", clanMatchString));
_clansManager.getTutorials().sendTutorialMsg(caller, F.desc("Matches via Player", playerMatchString));
}
return null;
@ -171,7 +171,7 @@ public class ClansUtility
{
LinkedList<ClanInfo> matchList = new LinkedList<ClanInfo>();
for (ClanInfo cur : Clans.getClanMap().values())
for (ClanInfo cur : _clansManager.getClanMap().values())
{
if (cur.getName().equalsIgnoreCase(name)) return cur;
@ -184,7 +184,7 @@ public class ClansUtility
if (!inform) return null;
// Inform
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mCount + matchList.size() + C.mBody + " matches for [" + C.mElem + name + C.mBody + "]."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mCount + matchList.size() + C.mBody + " matches for [" + C.mElem + name + C.mBody + "]."));
if (matchList.size() > 0)
{
@ -192,7 +192,7 @@ public class ClansUtility
for (ClanInfo cur : matchList)
matchString += cur.getName() + " ";
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mBody + " Matches [" + C.mElem + matchString + C.mBody + "]."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mBody + " Matches [" + C.mElem + matchString + C.mBody + "]."));
}
return null;
@ -203,7 +203,20 @@ public class ClansUtility
public ClanInfo getClanByClanName(String clan)
{
return Clans.getClan(clan);
return _clansManager.getClan(clan);
}
public ClanInfo getClanById(int id)
{
for (ClanInfo clan : _clansManager.getClanMap().values())
{
if (clan.getId() == id)
{
return clan;
}
}
return null;
}
public ClanInfo getClanByPlayer(Player player)
@ -213,7 +226,7 @@ public class ClansUtility
public ClanInfo getClanByUUID(UUID uuid)
{
return Clans.getClanMemberUuidMap().get(uuid);
return _clansManager.getClanMemberUuidMap().get(uuid);
}
// @Deprecated
@ -239,16 +252,16 @@ public class ClansUtility
public boolean isSafe(Player player)
{
if (!UtilTime.elapsed(Clans.getCombatManager().Get(player).GetLastDamaged(), Spawn.COMBAT_TAG_DURATION)) return false;
if (!UtilTime.elapsed(_clansManager.getCombatManager().Get(player).GetLastDamaged(), Spawn.COMBAT_TAG_DURATION)) return false;
return isSafe(player.getLocation());
}
public boolean isSafe(Location loc)
{
if (!Clans.getClaimMap().containsKey(UtilWorld.chunkToStr(loc.getChunk()))) return false;
if (!_clansManager.getClaimMap().containsKey(UtilWorld.chunkToStr(loc.getChunk()))) return false;
return Clans.getClaimMap().get(UtilWorld.chunkToStr(loc.getChunk())).isSafe(loc);
return _clansManager.getClaimMap().get(UtilWorld.chunkToStr(loc.getChunk())).isSafe(loc);
}
public boolean isChunkHome(ClanInfo clan, Chunk chunk)
@ -263,7 +276,7 @@ public class ClansUtility
public ClanTerritory getClaim(Chunk chunk)
{
String chunkTag = UtilWorld.chunkToStr(chunk);
return Clans.getClaimMap().get(chunkTag);
return _clansManager.getClaimMap().get(chunkTag);
}
/**
@ -281,7 +294,7 @@ public class ClansUtility
public ClanTerritory getClaim(String chunk)
{
return Clans.getClaimMap().get(chunk);
return _clansManager.getClaimMap().get(chunk);
}
public ClanInfo getOwner(String chunk)
@ -348,7 +361,7 @@ public class ClansUtility
{
String chunk = UtilWorld.chunkToStr(loc.getChunk());
return Clans.getClaimMap().containsKey(chunk);
return _clansManager.getClaimMap().containsKey(chunk);
}
// public boolean isAlliance(String player, Location loc)
@ -365,7 +378,7 @@ public class ClansUtility
public boolean isSelf(Player player, Location loc)
{
ClanInfo clan = Clans.getClan(player);
ClanInfo clan = _clansManager.getClan(player);
if (clan == null) return false;
@ -395,9 +408,9 @@ public class ClansUtility
ClanInfo owner = getOwner(loc);
ClanInfo clan = getClanByPlayer(player);
String mimic = Clans.Get(player).getMimic();
String mimic = _clansManager.Get(player).getMimic();
if (mimic.length() != 0) clan = Clans.getClanUtility().searchClanPlayer(player, mimic, false);
if (mimic.length() != 0) clan = _clansManager.getClanUtility().searchClanPlayer(player, mimic, false);
if (owner == null) return ClanRelation.SELF;
@ -553,38 +566,38 @@ public class ClansUtility
public void join(final Player caller, final ClanInfo clanInfo)
{
if (Clans.getClanMemberUuidMap().containsKey(caller.getUniqueId()))
if (_clansManager.getClanMemberUuidMap().containsKey(caller.getUniqueId()))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan."));
return;
}
if (!Clans.Get(caller).canJoin())
if (!_clansManager.Get(caller).canJoin())
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - Clans.Get(caller).getDelay(), 1, UtilTime.TimeUnit.FIT) + C.mBody + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - _clansManager.Get(caller).getDelay(), 1, UtilTime.TimeUnit.FIT) + C.mBody + "."));
return;
}
if (clanInfo == null)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Error: Clan does not exist"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Error: Clan does not exist"));
return;
}
if (!clanInfo.isInvited(caller.getName()))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not invited to " + F.elem("Clan " + clanInfo.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not invited to " + F.elem("Clan " + clanInfo.getName()) + "."));
return;
}
if (clanInfo.getSize() >= clanInfo.getMaxSize())
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "The clan " + F.elem("Clan " + clanInfo.getName()) + " is full and cannot be joined!"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "The clan " + F.elem("Clan " + clanInfo.getName()) + " is full and cannot be joined!"));
return;
}
// Task
Clans.getClanDataAccess().join(clanInfo, caller, ClanRole.RECRUIT, new Callback<Boolean>()
_clansManager.getClanDataAccess().join(clanInfo, caller, ClanRole.RECRUIT, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
@ -592,12 +605,12 @@ public class ClansUtility
if (data)
{
// Inform
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You joined " + F.elem("Clan " + clanInfo.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You joined " + F.elem("Clan " + clanInfo.getName()) + "."));
clanInfo.inform(F.name(caller.getName()) + " has joined your Clan.", caller.getName());
}
else
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request"));
}
}
});
@ -610,13 +623,13 @@ public class ClansUtility
if (clan == null)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (clan.getMembers().get(caller.getUniqueId()).getRole() == ClanRole.LEADER && clan.getMembers().size() > 1)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving."));
return;
}
@ -624,13 +637,13 @@ public class ClansUtility
if (clan.getMembers().size() > 1)
{
// Task
Clans.getClanDataAccess().leave(clan, caller, new Callback<Boolean>()
_clansManager.getClanDataAccess().leave(clan, caller, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
// Inform
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + "."));
clan.inform(F.name(caller.getName()) + " has left your Clan.", null);
clan.left(caller.getName());
@ -649,13 +662,13 @@ public class ClansUtility
if (clan == null)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (getRole(caller) != ClanRole.LEADER)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader can disband the Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader can disband the Clan."));
return;
}
@ -668,21 +681,21 @@ public class ClansUtility
return;
}
Clans.messageClan(clan, C.cYellow + caller.getName() + C.cGray + " has disbanded the Clan.");
_clansManager.messageClan(clan, C.cYellow + caller.getName() + C.cGray + " has disbanded the Clan.");
// Task
Clans.getClanDataAccess().delete(clan, new Callback<Boolean>()
_clansManager.getClanDataAccess().delete(clan, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (!data)
if (!data.booleanValue())
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request. Try again later"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request. Try again later"));
}
else
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You disbanded your Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You disbanded your Clan."));
}
}
});
@ -701,28 +714,28 @@ public class ClansUtility
{
return false;
}
if (clan == null)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return false;
}
if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can claim Territory."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can claim Territory."));
return false;
}
if (!ClansManager.isClaimable(caller.getLocation()))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim territory at this location!"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim territory at this location!"));
return false;
}
if (clan.getEnergy() == 0)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must purchase energy at a shop before you can claim land."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must purchase energy at a shop before you can claim land."));
return false;
}
@ -738,14 +751,14 @@ public class ClansUtility
}
else
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory is owned by " + mRel(Clans.getClanUtility().relPC(caller, ownerClan), ownerClan.getName(), true) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory is owned by " + mRel(_clansManager.getClanUtility().relPC(caller, ownerClan), ownerClan.getName(), true) + "."));
return false;
}
}
if (clan.getClaims() >= clan.getClaimsMax())
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan cannot claim more Territory."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan cannot claim more Territory."));
return false;
}
@ -771,8 +784,8 @@ public class ClansUtility
if (checkBox(caller.getWorld().getChunkAt(caller.getLocation().getChunk().getX() + x, caller.getLocation().getChunk().getZ() + z), 3))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim this Territory, it causes a box."));
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This means a Territory has all sides claimed."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim this Territory, it causes a box."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This means a Territory has all sides claimed."));
return false;
}
@ -782,7 +795,7 @@ public class ClansUtility
}
else if (rel(clan, adjClan) != ClanRelation.SELF)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim Territory next to " + mRel(rel(ownerClan, adjClan), adjClan.getName(), true) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim Territory next to " + mRel(rel(ownerClan, adjClan), adjClan.getName(), true) + "."));
return false;
}
}
@ -791,36 +804,36 @@ public class ClansUtility
// Boxed
if (checkBox(caller.getLocation().getChunk(), 4))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim this Territory, it causes a box."));
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This means a Territory has all sides claimed."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim this Territory, it causes a box."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This means a Territory has all sides claimed."));
return false;
}
if (isNearAdminClaim(caller.getLocation()))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim so close to administrative territory!"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim so close to administrative territory!"));
return false;
}
// Not Next to Self
if (!selfAdj && !clan.getClaimSet().isEmpty())
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must claim next to your other Territory."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must claim next to your other Territory."));
return false;
}
// Claim Timer
if (Clans.getUnclaimMap().containsKey(chunk))
if (_clansManager.getUnclaimMap().containsKey(chunk))
{
if (!UtilTime.elapsed(Clans.getUnclaimMap().get(chunk), Clans.getReclaimTime()))
if (!UtilTime.elapsed(_clansManager.getUnclaimMap().get(chunk).longValue(), _clansManager.getReclaimTime()))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory cannot be claimed for " + F.time(UtilTime.convertString(Clans.getReclaimTime() - (System.currentTimeMillis() - Clans.getUnclaimMap().get(chunk)), 1, UtilTime.TimeUnit.FIT)) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory cannot be claimed for " + F.time(UtilTime.convertString(_clansManager.getReclaimTime() - (System.currentTimeMillis() - _clansManager.getUnclaimMap().get(chunk).longValue()), 1, UtilTime.TimeUnit.FIT)) + "."));
return false;
}
else
{
Clans.getUnclaimMap().remove(chunk);
_clansManager.getUnclaimMap().remove(chunk);
}
}
@ -829,7 +842,7 @@ public class ClansUtility
{
if (UtilMath.offset(cur, caller) < 16) if (playerEnemy(caller, cur))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim while enemies are nearby."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim while enemies are nearby."));
return false;
}
}
@ -848,10 +861,10 @@ public class ClansUtility
}
// Task
Clans.getClanDataAccess().claim(clan.getName(), chunk, caller.getName(), false);
_clansManager.getClanDataAccess().claim(clan.getName(), chunk, caller.getName(), false);
// Inform
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + "."));
clan.inform(F.name(caller.getName()) + " claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".", caller.getName());
return true;
@ -882,19 +895,19 @@ public class ClansUtility
public boolean unclaimSteal(Player caller, ClanInfo clientClan, ClanInfo ownerClan)
{
if (!Clans.canUnclaimChunk(clientClan, ownerClan))
if (!_clansManager.canUnclaimChunk(clientClan, ownerClan))
{
return false;
}
// Change Inform
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can no longer 'steal' territory. " + "You simply unclaim it and it can not be reclaimed by anyone for 30 mintes." + "This was done to improve gameplay. Enjoy!"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can no longer 'steal' territory. " + "You simply unclaim it and it can not be reclaimed by anyone for 30 mintes." + "This was done to improve gameplay. Enjoy!"));
// Inform
UtilServer.broadcast(F.main("Clans", F.elem(clientClan.getName()) + " unclaimed from " + F.elem(ownerClan.getName()) + " at " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + "."));
// Unclaim
Clans.getClanDataAccess().unclaim(UtilWorld.chunkToStr(caller.getLocation().getChunk()), caller.getName(), true);
_clansManager.getClanDataAccess().unclaim(UtilWorld.chunkToStr(caller.getLocation().getChunk()), caller.getName(), true);
return true;
}
@ -905,7 +918,7 @@ public class ClansUtility
if (clan == null)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
@ -916,13 +929,13 @@ public class ClansUtility
if (target.equals(caller.getName()))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot promote yourself."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot promote yourself."));
return;
}
if (self.getRole().ordinal() <= target.getRole().ordinal())
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + "."));
return;
}
@ -930,21 +943,21 @@ public class ClansUtility
String newRank = "?";
if (target.getRole() == ClanRole.RECRUIT)
{
Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.MEMBER);
_clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.MEMBER);
newRank = "Member";
}
else if (target.getRole() == ClanRole.MEMBER)
{
Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.ADMIN);
_clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.ADMIN);
newRank = "Admin";
}
else if (target.getRole() == ClanRole.ADMIN)
{
Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.LEADER);
_clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.LEADER);
newRank = "Leader";
// Give Leader
Clans.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.ADMIN);
_clansManager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.ADMIN);
}
// Inform
@ -957,7 +970,7 @@ public class ClansUtility
if (clan == null)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
@ -968,19 +981,19 @@ public class ClansUtility
if (target.equals(caller.getName()))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot demote yourself."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot demote yourself."));
return;
}
if (self.getRole().ordinal() <= target.getRole().ordinal())
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + "."));
return;
}
if (target.getRole() == ClanRole.RECRUIT)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot demote " + F.name(other) + " any further."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot demote " + F.name(other) + " any further."));
return;
}
@ -988,12 +1001,12 @@ public class ClansUtility
String newRank = "?";
if (target.getRole() == ClanRole.MEMBER)
{
Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.RECRUIT);
_clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.RECRUIT);
newRank = "Recruit";
}
else if (target.getRole() == ClanRole.ADMIN)
{
Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.MEMBER);
_clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.MEMBER);
newRank = "Member";
}
@ -1007,7 +1020,7 @@ public class ClansUtility
if (clan == null)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
@ -1018,20 +1031,20 @@ public class ClansUtility
if (self.getRole() != ClanRole.LEADER && self.getRole() != ClanRole.ADMIN)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can kick members."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can kick members."));
return;
}
if (clansPlayer.getRole() == ClanRole.LEADER)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan leaders cannot be kicked."));
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "To disband a clan, use /c disband"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan leaders cannot be kicked."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "To disband a clan, use /c disband"));
return;
}
if ((clansPlayer.getRole() == ClanRole.LEADER && self.getRole() == ClanRole.ADMIN) || (clansPlayer.getRole() == ClanRole.ADMIN && self.getRole() == ClanRole.ADMIN))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + "."));
return;
}
@ -1043,17 +1056,17 @@ public class ClansUtility
public void run(Boolean data)
{
// Inform
if (player != null) Clans.getTutorials().sendTutorialMsg(player, F.main("Clans", F.name(caller.getName()) + " kicked you from " + F.elem("Clan " + clan.getName()) + "."));
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You kicked " + F.name(other) + " from your Clan."));
if (player != null) _clansManager.getTutorials().sendTutorialMsg(player, F.main("Clans", F.name(caller.getName()) + " kicked you from " + F.elem("Clan " + clan.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You kicked " + F.name(other) + " from your Clan."));
clan.inform(F.main("Clans", F.name(caller.getName()) + " kicked " + F.name(other) + " from your Clan."), caller.getName());
}
};
// Task
if (player != null)
Clans.getClanDataAccess().leave(clan, player, callback);
_clansManager.getClanDataAccess().leave(clan, player, callback);
else
Clans.getClanDataAccess().leave(clan, clansPlayer, callback);
_clansManager.getClanDataAccess().leave(clan, clansPlayer, callback);
}
public boolean unclaim(final Player caller, final Chunk c)
@ -1062,7 +1075,7 @@ public class ClansUtility
if (clan == null)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return false;
}
@ -1075,14 +1088,14 @@ public class ClansUtility
// Role
if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can unclaim Territory."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can unclaim Territory."));
return false;
}
// Not Claimed
if (ownerClan == null || !ownerClan.equals(clan))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory is not owned by you."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory is not owned by you."));
return false;
}
@ -1097,10 +1110,10 @@ public class ClansUtility
}
// Task
Clans.getClanDataAccess().unclaim(chunk, caller.getName(), true);
_clansManager.getClanDataAccess().unclaim(chunk, caller.getName(), true);
// Inform
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You unclaimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You unclaimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + "."));
clan.inform(F.name(caller.getName()) + " unclaimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".", caller.getName());
return true;
@ -1112,13 +1125,13 @@ public class ClansUtility
if (clan == null)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return false;
}
if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader can unclaim all Territory."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader can unclaim all Territory."));
return false;
}
@ -1132,11 +1145,11 @@ public class ClansUtility
for (String chunk : toUnclaim)
{
Clans.getClanDataAccess().unclaim(chunk, caller.getName(), true);
_clansManager.getClanDataAccess().unclaim(chunk, caller.getName(), true);
}
// Inform
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You unclaimed all your Clans Territory."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You unclaimed all your Clans Territory."));
clan.inform(F.name(caller.getName()) + " unclaimed all your Clans Territory.", caller.getName());
return true;
@ -1146,24 +1159,24 @@ public class ClansUtility
{
if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN)
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can send invites."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can send invites."));
return;
}
if (target.getName().equals(caller.getName()))
{
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot invite yourself."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot invite yourself."));
return;
}
// Inform
clan.inform(F.name(caller.getName()) + " invited " + F.name(target.getName()) + " to join your Clan.", caller.getName());
Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You invited " + F.name(target.getName()) + " to join your Clan."));
Clans.getTutorials().sendTutorialMsg(target, F.main("Clans", F.name(caller.getName()) + " invited you to join " + F.elem("Clan " + clan.getName()) + "."));
Clans.getTutorials().sendTutorialMsg(target, F.main("Clans", "Type " + F.elem("/c join " + clan.getName()) + " to accept!"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You invited " + F.name(target.getName()) + " to join your Clan."));
_clansManager.getTutorials().sendTutorialMsg(target, F.main("Clans", F.name(caller.getName()) + " invited you to join " + F.elem("Clan " + clan.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(target, F.main("Clans", "Type " + F.elem("/c join " + clan.getName()) + " to accept!"));
// Task
Clans.getClanDataAccess().invite(clan, target.getName(), caller.getName());
_clansManager.getClanDataAccess().invite(clan, target.getName(), caller.getName());
}
}

View File

@ -0,0 +1,15 @@
package mineplex.game.clans.clans;
import java.io.File;
import java.io.IOException;
import mineplex.core.common.util.UtilOfflinePlayer;
public class Test
{
public static void main(String[] args) throws IOException
{
System.out.println("wtf");
UtilOfflinePlayer.loadOfflineInventory(new File("M:/Clans/a797d3ef-dd25-4e18-a002-6537b19b3603.dat"));
}
}

View File

@ -86,8 +86,8 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
}
else
{
UtilPlayer.message(caller, C.cGold + "/cp <username> <timeInDays(number)/p(ermanent)> <description> - Bans the specified player for the specified amount of time");
UtilPlayer.message(caller, C.cGold + "/cp <username> - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)");
UtilPlayer.message(caller, C.cGold + "/cb <username> <timeInDays(number)/p(ermanent)> <description> - Bans the specified player for the specified amount of time");
UtilPlayer.message(caller, C.cGold + "/cb <username> - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)");
}
}
}

View File

@ -1,3 +1,4 @@
package mineplex.game.clans.clans.commands;
import java.util.Collections;
@ -9,7 +10,6 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.google.common.collect.Lists;
@ -20,7 +20,6 @@ import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilInput;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle;
@ -43,12 +42,12 @@ import net.minecraft.server.v1_8_R3.EnumDirection;
public class ClansCommand extends CommandBase<ClansManager>
{
private ClansManager _manager;
private ClansManager _clansManager;
public ClansCommand(ClansManager plugin)
{
super(plugin, Rank.ALL, "c", "clan", "clans", "factions");
_manager = plugin;
_clansManager = plugin;
}
@Override
@ -56,7 +55,7 @@ public class ClansCommand extends CommandBase<ClansManager>
{
if (args == null || args.length == 0)
{
_manager.getClanShop().attemptShopOpen(caller);
_clansManager.getClanShop().attemptShopOpen(caller);
return;
}
@ -140,7 +139,7 @@ public class ClansCommand extends CommandBase<ClansManager>
{
if (!Plugin.getClientManager().hasRank(caller, Rank.ADMIN) && !caller.getUniqueId().toString().equals("d8646a35-33a8-43c6-9e7c-2e871a6b86c9") /* My UUID (NewGarbo) */)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This requires ADMIN+ permission."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This requires ADMIN+ permission."));
return;
}
@ -150,18 +149,18 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan != null)
{
_manager.getClanUtility().join(caller, clan);
_manager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.LEADER);
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have successfully joined " + F.elem(clan.getName()) + " and are now Leader Role."));
_clansManager.getClanUtility().join(caller, clan);
_clansManager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.LEADER);
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have successfully joined " + F.elem(clan.getName()) + " and are now Leader Role."));
}
else
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan provided does not exist."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan provided does not exist."));
}
}
else
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "No clan provided."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "No clan provided."));
}
}
@ -170,7 +169,7 @@ public class ClansCommand extends CommandBase<ClansManager>
if (args.length == 0)
{
Plugin.Get(caller).setClanChat(!Plugin.Get(caller).isClanChat());
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan Chat: " + F.oo(Plugin.Get(caller).isClanChat())));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan Chat: " + F.oo(Plugin.Get(caller).isClanChat())));
return;
}
@ -179,7 +178,7 @@ public class ClansCommand extends CommandBase<ClansManager>
{
ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller);
if (clan == null)
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
else
Plugin.chatClan(clan, caller, F.combine(args, 0, null, false));
}
@ -190,7 +189,7 @@ public class ClansCommand extends CommandBase<ClansManager>
if (args.length == 0)
{
Plugin.Get(caller).setAllyChat(!Plugin.Get(caller).isAllyChat());
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Ally Chat: " + F.oo(Plugin.Get(caller).isAllyChat())));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Ally Chat: " + F.oo(Plugin.Get(caller).isAllyChat())));
return;
}
@ -199,7 +198,7 @@ public class ClansCommand extends CommandBase<ClansManager>
{
ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller);
if (clan == null)
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
else
Plugin.chatAlly(clan, caller, F.combine(args, 0, null, false));
}
@ -215,32 +214,32 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Commands List;"));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c create <clan>", "Create new Clan", Rank.ALL));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c join <clan>", "Join a Clan", Rank.ALL));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c leave <clan>", "Leave your Clan", Rank.ALL));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c map <toggle>", "View Clan Map", Rank.ALL));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/cc (Message)", "Clan Chat (Toggle)", Rank.ALL));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Commands List;"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c create <clan>", "Create new Clan", Rank.ALL));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c join <clan>", "Join a Clan", Rank.ALL));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c leave <clan>", "Leave your Clan", Rank.ALL));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c map <toggle>", "View Clan Map", Rank.ALL));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/cc (Message)", "Clan Chat (Toggle)", Rank.ALL));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c stuck", "Teleports you to the nearest Wilderness location", Rank.ALL));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c stuck", "Teleports you to the nearest Wilderness location", Rank.ALL));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c promote <player>", "Promote Player in Clan", Rank.MODERATOR));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c demote <player>", "Demote Player in Clan", Rank.MODERATOR));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c promote <player>", "Promote Player in Clan", Rank.MODERATOR));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c demote <player>", "Demote Player in Clan", Rank.MODERATOR));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c home (set)", "Teleport to Clan Home", Rank.MODERATOR));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c home (set)", "Teleport to Clan Home", Rank.MODERATOR));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c invite <player>", "Invite Player to Clan", Rank.ADMIN));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c kick <player>", "Kick Player from Clan", Rank.ADMIN));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c neutral <clan>", "Request Neutrality with Clan", Rank.ADMIN));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c enemy <clan>", "Declare ClanWar with Clan", Rank.ADMIN));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c ally <clan>", "Send Alliance to Clan", Rank.ADMIN));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c trust <clan>", "Give Trust to Clan", Rank.ADMIN));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c claim", "Claim Territory", Rank.ADMIN));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c unclaim (all)", "Unclaim Territory", Rank.ADMIN));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c invite <player>", "Invite Player to Clan", Rank.ADMIN));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c kick <player>", "Kick Player from Clan", Rank.ADMIN));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c neutral <clan>", "Request Neutrality with Clan", Rank.ADMIN));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c enemy <clan>", "Declare ClanWar with Clan", Rank.ADMIN));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c ally <clan>", "Send Alliance to Clan", Rank.ADMIN));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c trust <clan>", "Give Trust to Clan", Rank.ADMIN));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c claim", "Claim Territory", Rank.ADMIN));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c unclaim (all)", "Unclaim Territory", Rank.ADMIN));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c delete", "Delete your Clan", Rank.OWNER));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c delete", "Delete your Clan", Rank.OWNER));
_manager.getTutorials().sendTutorialMsg(caller, F.help("/c <clan>", "View Clan Information", Rank.ALL));
_clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c <clan>", "View Clan Information", Rank.ALL));
}
public void create(final Player caller, final String[] args)
@ -251,13 +250,13 @@ public class ClansCommand extends CommandBase<ClansManager>
if (Plugin.getClanMemberUuidMap().containsKey(caller.getUniqueId()))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan."));
return;
}
if (Plugin.leftRecently(caller.getUniqueId(), 5 * 60 * 1000) != null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot create a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot create a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + "."));
return;
}
@ -270,37 +269,37 @@ public class ClansCommand extends CommandBase<ClansManager>
if (args.length < 2)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan name."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan name."));
return;
}
if (!UtilInput.valid(args[1]))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Invalid characters in Clan name."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Invalid characters in Clan name."));
return;
}
if (args[1].length() < Plugin.getNameMin())
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name too short. Minimum length is " + (Plugin.getNameMin()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name too short. Minimum length is " + (Plugin.getNameMin()) + "."));
return;
}
if (args[1].length() > Plugin.getNameMax())
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name too long. Maximum length is " + (Plugin.getNameMax()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name too long. Maximum length is " + (Plugin.getNameMax()) + "."));
return;
}
if (Plugin.getChat().getFilteredMessage(caller, args[1]).contains("*"))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name inappropriate. Please try a different name"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name inappropriate. Please try a different name"));
return;
}
if (!ClansBlacklist.isValidClanName(args[1]))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name is blacklisted! Please try a different name."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name is blacklisted! Please try a different name."));
return;
}
@ -311,7 +310,7 @@ public class ClansCommand extends CommandBase<ClansManager>
{
if (clanExists)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name is already in use by another Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name is already in use by another Clan."));
}
else
{
@ -323,11 +322,11 @@ public class ClansCommand extends CommandBase<ClansManager>
if (data == null)
{
// Hopefully shouldn't happen!
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error creating the clan. Please try again"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error creating the clan. Please try again"));
}
else
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You created Clan " + C.cYellow + data.getName() + C.cGray + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You created Clan " + C.cYellow + data.getName() + C.cGray + "."));
}
}
});
@ -347,13 +346,13 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (args.length < 2)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input an invitee."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input an invitee."));
return;
}
@ -365,13 +364,27 @@ public class ClansCommand extends CommandBase<ClansManager>
public void stuck(final Player caller)
{
// if (_clansManager.getNetherManager().isInNether(caller))
// {
// _clansManager.message(caller, "You are not allowed to free yourself in " + F.clansNether("The Nether") + ".");
//
// return;
// }
if (DelayedTask.Instance.HasTask(caller, "Spawn Teleport"))
{
_clansManager.message(caller, "You are already unsticking yourself.");
return;
}
ClanTerritory territory = Plugin.getClanUtility().getClaim(caller.getLocation());
String clanName = Plugin.getClanUtility().getClanByPlayer(caller) == null ? null : Plugin.getClanUtility().getClanByPlayer(caller).getName();
if (territory == null || territory.Safe || territory.Owner.equals(clanName))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must be in another Clan's territory to use this."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must be in another Clan's territory to use this."));
return;
}
@ -384,14 +397,14 @@ public class ClansCommand extends CommandBase<ClansManager>
if (loc == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Error whilst finding location to teleport to."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Error whilst finding location to teleport to."));
return;
}
player.getPlayer().teleport(loc);
// Inform
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have been teleported to the Wilderness."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have been teleported to the Wilderness."));
}
}, new Callback<DelayedTaskClient>() {
public void run(DelayedTaskClient client)
@ -444,31 +457,31 @@ public class ClansCommand extends CommandBase<ClansManager>
{
if (Plugin.getClanMemberUuidMap().containsKey(caller.getUniqueId()))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan."));
return;
}
if (Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000) != null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + "."));
return;
}
if (!Plugin.Get(caller).canJoin())
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - Plugin.Get(caller).getDelay(), 1, TimeUnit.FIT) + C.mBody + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - Plugin.Get(caller).getDelay(), 1, TimeUnit.FIT) + C.mBody + "."));
return;
}
if (args.length < 2)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan name."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan name."));
return;
}
if (!UtilInput.valid(args[1]))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Invalid characters in Clan name."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Invalid characters in Clan name."));
return;
}
@ -477,13 +490,13 @@ public class ClansCommand extends CommandBase<ClansManager>
if (!clan.isInvited(caller.getName()))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not invited to " + F.elem("Clan " + clan.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not invited to " + F.elem("Clan " + clan.getName()) + "."));
return;
}
if (clan.getSize() >= clan.getMaxSize())
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "The clan " + F.elem("Clan " + clan.getName()) + " is full and cannot be joined!"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "The clan " + F.elem("Clan " + clan.getName()) + " is full and cannot be joined!"));
return;
}
@ -500,12 +513,12 @@ public class ClansCommand extends CommandBase<ClansManager>
if (data)
{
// Inform
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You joined " + F.elem("Clan " + clan.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You joined " + F.elem("Clan " + clan.getName()) + "."));
clan.inform(F.name(caller.getName()) + " has joined your Clan.", caller.getName());
}
else
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request"));
}
}
});
@ -518,13 +531,13 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (clan.getMembers().get(caller.getUniqueId()).getRole() == ClanRole.LEADER && clan.getMembers().size() > 1)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving."));
return;
}
@ -538,7 +551,7 @@ public class ClansCommand extends CommandBase<ClansManager>
public void run(Boolean data)
{
// Inform
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + "."));
clan.inform(F.name(caller.getName()) + " has left your Clan.", null);
}
});
@ -555,19 +568,19 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (args.length < 2)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Player to kick."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Player to kick."));
return;
}
final String target = UtilPlayer.searchCollection(caller, args[1], clan.getMemberNameSet(), "Clan Member", true);
_manager.getClanUtility().kick(caller, target);
_clansManager.getClanUtility().kick(caller, target);
}
public void promote(Player caller, String[] args)
@ -576,19 +589,19 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (args.length < 2)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input player to promote."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input player to promote."));
return;
}
final String targetName = UtilPlayer.searchCollection(caller, args[1], clan.getMemberNameSet(), "Clan Member", true);
_manager.getClanUtility().promote(caller, targetName);
_clansManager.getClanUtility().promote(caller, targetName);
}
public void demote(Player caller, String[] args)
@ -597,19 +610,19 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (args.length < 2)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input player to demote."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input player to demote."));
return;
}
final String targetName = UtilPlayer.searchCollection(caller, args[1], clan.getMemberNameSet(), "Clan Member", true);
_manager.getClanUtility().demote(caller, targetName);
_clansManager.getClanUtility().demote(caller, targetName);
}
public void ally(Player caller, String[] args)
@ -618,19 +631,19 @@ public class ClansCommand extends CommandBase<ClansManager>
if (cA == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (cA.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && cA.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Alliances."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Alliances."));
return;
}
if (args.length < 2)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan to ally."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan to ally."));
return;
}
@ -640,31 +653,31 @@ public class ClansCommand extends CommandBase<ClansManager>
if (cA.isSelf(cB.getName()))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot ally with yourself."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot ally with yourself."));
return;
}
if (cA.isAlly(cB.getName()))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already allies with Clan" + F.elem(cB.getName())) + ".");
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already allies with Clan" + F.elem(cB.getName())) + ".");
return;
}
if (cA.getAllies() >= cA.getAlliesMax())
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot have any more allies."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot have any more allies."));
return;
}
if (cB.getAllies() >= cB.getAlliesMax())
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan " + F.elem(cB.getName()) + " cannot have any more allies."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan " + F.elem(cB.getName()) + " cannot have any more allies."));
return;
}
if (!Recharge.Instance.usable(caller, "AllyReq" + cB.getName()))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Please do not spam alliance requests."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Please do not spam alliance requests."));
return;
}
@ -674,7 +687,7 @@ public class ClansCommand extends CommandBase<ClansManager>
Plugin.getClanDataAccess().ally(cA, cB, caller.getName());
// Inform
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You accepted alliance with Clan " + F.elem(cB.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You accepted alliance with Clan " + F.elem(cB.getName()) + "."));
cA.inform(F.name(caller.getName()) + " accepted alliance with Clan " + F.elem(cB.getName()) + ".", caller.getName());
cB.inform("Clan " + F.elem(cA.getName()) + " has accepted alliance with you.", null);
}
@ -684,7 +697,7 @@ public class ClansCommand extends CommandBase<ClansManager>
Plugin.getClanDataAccess().requestAlly(cA, cB, caller.getName());
// Inform
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You requested alliance with Clan " + F.elem(cB.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You requested alliance with Clan " + F.elem(cB.getName()) + "."));
cA.inform(F.name(caller.getName()) + " has requested alliance with Clan " + F.elem(cB.getName()) + ".", caller.getName());
cB.inform("Clan " + F.elem(cA.getName()) + " has requested alliance with you.", null);
@ -747,19 +760,19 @@ public class ClansCommand extends CommandBase<ClansManager>
if (cA == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (cA.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && cA.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage relationships."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage relationships."));
return;
}
if (args.length < 2)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan to set neutrality with."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan to set neutrality with."));
return;
}
@ -769,11 +782,11 @@ public class ClansCommand extends CommandBase<ClansManager>
if (cB.isSelf(cA.getName()))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You prefer to think of yourself positively..."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You prefer to think of yourself positively..."));
}
else if (cB.isNeutral(cA.getName()))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already neutral with " + F.elem("Clan " + cB.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already neutral with " + F.elem("Clan " + cB.getName()) + "."));
}
else if (cB.isAlly(cA.getName()))
{
@ -781,7 +794,7 @@ public class ClansCommand extends CommandBase<ClansManager>
Plugin.getClanDataAccess().neutral(cA, cB, caller.getName(), true);
// Inform
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You revoked alliance with " + F.elem("Clan " + cB.getName()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You revoked alliance with " + F.elem("Clan " + cB.getName()) + "."));
cA.inform(F.name(caller.getName()) + " revoked alliance with " + F.elem("Clan " + cB.getName()) + ".", caller.getName());
cB.inform(F.elem("Clan " + cA.getName()) + " has revoked alliance with you.", null);
}
@ -797,11 +810,25 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
// if (_clansManager.getNetherManager().isInNether(caller))
// {
// _clansManager.message(caller, "You are not allowed to claim territory in " + F.clansNether("The Nether") + ".");
//
// return;
// }
Plugin.getClanUtility().claim(caller);
}
public void unclaim(Player caller, String[] args)
{
// if (_clansManager.getNetherManager().isInNether(caller))
// {
// _clansManager.message(caller, "You are not allowed to unclaim territory in " + F.clansNether("The Nether") + ".");
//
// return;
// }
if (args.length > 1)
{
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("a"))
@ -816,13 +843,13 @@ public class ClansCommand extends CommandBase<ClansManager>
public boolean unclaimSteal(Player caller, ClanInfo clientClan, ClanInfo ownerClan)
{
if (!_manager.canUnclaimChunk(clientClan, ownerClan))
if (!_clansManager.canUnclaimChunk(clientClan, ownerClan))
{
return false;
}
// Change Inform
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can no longer 'steal' territory. " + "You simply unclaim it and it can not be reclaimed by anyone for 30 mintes." + "This was done to improve gameplay. Enjoy!"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can no longer 'steal' territory. " + "You simply unclaim it and it can not be reclaimed by anyone for 30 mintes." + "This was done to improve gameplay. Enjoy!"));
// Inform
UtilServer.broadcast(F.main("Clans", F.elem(clientClan.getName()) + " unclaimed from " + F.elem(ownerClan.getName()) + " at " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + "."));
@ -858,19 +885,19 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
if (clan.getHome() == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan has not set a Home"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan has not set a Home"));
return;
}
if (!clan.getClaimSet().contains(UtilWorld.chunkToStr(clan.getHome().getChunk())))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan has lost its Home Territory."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan has lost its Home Territory."));
return;
}
@ -878,7 +905,7 @@ public class ClansCommand extends CommandBase<ClansManager>
if (!(home.getBlock().getType().equals(Material.BED_BLOCK) && home.add(0, 1, 0).getBlock().getType().equals(Material.AIR)) && home.add(0, 2, 0).getBlock().getType().equals(Material.AIR))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan's bed has been destroyed, or is obstructed."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan's bed has been destroyed, or is obstructed."));
return;
}
@ -892,7 +919,7 @@ public class ClansCommand extends CommandBase<ClansManager>
* }
*/
if (!Recharge.Instance.use(caller, "Home Teleport", 5 * 60 * 1000, true, false))
if (!Recharge.Instance.usable(caller, "Home Teleport", true))
{
return;
}
@ -900,11 +927,13 @@ public class ClansCommand extends CommandBase<ClansManager>
DelayedTask.Instance.doDelay(caller, "Home Teleport", new Callback<DelayedTaskClient>() {
public void run(DelayedTaskClient player)
{
Recharge.Instance.use(caller, "Home Teleport", 30 * 60 * 1000, true, false);
// Do
Plugin.getTeleport().TP(caller, clan.getHome().add(0, 1, 0));
// Inform
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + "."));
}
}, new Callback<DelayedTaskClient>() {
public void run(DelayedTaskClient client)
@ -916,7 +945,7 @@ public class ClansCommand extends CommandBase<ClansManager>
{
UtilPlayer.message(client.getPlayer(), F.main("Clans", "Teleport has been cancelled due to movement."));
}
}, (Plugin.getClanUtility().getClaim(caller.getLocation()) != null ? 30 : 20) * 1000, false);
}, 15 * 1000, false);
}
public void homeSet(Player caller)
@ -934,31 +963,38 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
// if (_clansManager.getNetherManager().isInNether(caller))
// {
// _clansManager.message(caller, "You are not allowed to set your Clan Home in " + F.clansNether("The Nether") + ".");
//
// return;
// }
if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Clan Home."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Clan Home."));
return;
}
if (Plugin.getClanUtility().getOwner(caller.getLocation()) == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must set your Clan Home in your own Territory."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must set your Clan Home in your own Territory."));
return;
}
if (!Plugin.getClanUtility().getOwner(caller.getLocation()).isSelf(clan.getName()))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must set your Clan Home in your own Territory."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must set your Clan Home in your own Territory."));
return;
}
if (!(caller.getLocation().add(0, 1, 0).getBlock().getType().equals(Material.AIR) && caller.getLocation().add(0, 2, 0).getBlock().getType().equals(Material.AIR)))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This is not a suitable place for a bed."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This is not a suitable place for a bed."));
return;
}
@ -967,7 +1003,7 @@ public class ClansCommand extends CommandBase<ClansManager>
if (!bedPlaced)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This is not a suitable place for a bed."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This is not a suitable place for a bed."));
return;
}
@ -983,7 +1019,7 @@ public class ClansCommand extends CommandBase<ClansManager>
Plugin.ClanTips.displayTip(TipType.SETHOME, caller);
// Inform
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You set Clan Home to " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + "."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You set Clan Home to " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + "."));
clan.inform(caller.getName() + " set Clan Home to " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + ".", caller.getName());
}
@ -993,7 +1029,7 @@ public class ClansCommand extends CommandBase<ClansManager>
if (search == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter."));
return;
}
@ -1008,20 +1044,20 @@ public class ClansCommand extends CommandBase<ClansManager>
ClanInfo clan = Plugin.getClanUtility().searchClanPlayer(caller, search, true);
if (clan == null) return;
_manager.getClanShop().openClanWho(caller, clan);
_clansManager.getClanShop().openClanWho(caller, clan);
}
public void forceJoinClan(Player caller, String search)
{
if (_manager.getClientManager().hasRank(caller, Rank.ADMIN))
if (_clansManager.getClientManager().hasRank(caller, Rank.ADMIN))
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "No no no, this command is not for you ;-)"));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "No no no, this command is not for you ;-)"));
return;
}
if (search == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter."));
return;
}
@ -1036,8 +1072,8 @@ public class ClansCommand extends CommandBase<ClansManager>
ClanInfo clan = Plugin.getClanUtility().searchClanPlayer(caller, search, true);
if (clan == null) return;
_manager.getClanUtility().join(caller, clan);
_manager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.LEADER);
_clansManager.getClanUtility().join(caller, clan);
_clansManager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.LEADER);
}
@ -1050,7 +1086,7 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan == null)
{
_manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
_clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan."));
return;
}
}
@ -1060,6 +1096,13 @@ public class ClansCommand extends CommandBase<ClansManager>
if (clan == null) return;
_manager.getTutorials().sendTutorialMsg(caller, clan.mTerritory());
// if (_clansManager.getNetherManager().isInNether(caller))
// {
// _clansManager.message(caller, "You are currently in " + F.clansNether("The Nether") + ".");
//
// return;
// }
_clansManager.getTutorials().sendTutorialMsg(caller, clan.mTerritory());
}
}

View File

@ -1,22 +0,0 @@
package mineplex.game.clans.clans.commands;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.game.clans.clans.outpost.Outpost;
import mineplex.game.clans.clans.outpost.OutpostManager;
public class Meow extends CommandBase<OutpostManager>
{
public Meow(OutpostManager plugin)
{
super(plugin, Rank.ALL, "meow");
}
@Override
public void Execute(Player caller, String[] args)
{
caller.getInventory().addItem(Outpost.OUTPOST_ITEM);
}
}

View File

@ -0,0 +1,53 @@
package mineplex.game.clans.clans.event;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class ClansWaterPlaceEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _player;
private Block _block;
private boolean _cancelled;
public ClansWaterPlaceEvent(Player player, Block block)
{
_player = player;
_block = block;
}
public Player getPlayer()
{
return _player;
}
public Block getBlock()
{
return _block;
}
public void setCancelled(boolean cancelled)
{
_cancelled = cancelled;
}
public boolean isCancelled()
{
return _cancelled;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -12,7 +12,7 @@ import mineplex.game.clans.clans.gui.ClanShop;
public abstract class ClanButton implements IButton
{
private ClanShop _shop;
private ClansManager _clansManager;
protected ClansManager _clansManager;
private Player _player;
private ClanInfo _clanInfo;
private ClanRole _clanRole;

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
@ -22,6 +23,13 @@ public class ClanTerritoryButton extends ClanButton
@Override
public void onClick(Player player, ClickType clickType)
{
// if (_clansManager.getNetherManager().isInNether(player))
// {
// _clansManager.message(player, "You are not allowed to do anything with Territory while in " + F.clansNether("The Nether") + ".");
// player.closeInventory();
// return;
// }
if (clickType == ClickType.LEFT)
{
player.closeInventory();

View File

@ -44,7 +44,7 @@ public class ClanMainPage extends ClanPageBase
public ClanMainPage(ClansManager plugin, ClanShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Manage Clan", player, 54);
buildPage();
}

View File

@ -0,0 +1,23 @@
package mineplex.game.clans.clans.invsee;
import mineplex.core.MiniPlugin;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.invsee.commands.InvseeCommand;
public class Invsee extends MiniPlugin
{
private ClansManager _clansManager;
public Invsee(ClansManager clansManager)
{
super("Inventory Viewer", clansManager.getPlugin());
_clansManager = clansManager;
}
public void addCommands()
{
addCommand(new InvseeCommand(this));
}
}

View File

@ -0,0 +1,54 @@
package mineplex.game.clans.clans.invsee.commands;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.game.clans.clans.invsee.Invsee;
import mineplex.game.clans.clans.invsee.ui.InvseeInventory;
public class InvseeCommand extends CommandBase<Invsee>
{
public InvseeCommand(Invsee plugin)
{
super(plugin, Rank.ADMIN, "invsee");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 0)
{
}
else
{
String name = args[0];
OfflinePlayer player;
if (UtilServer.IsOnline(name))
{
player = UtilServer.GetPlayer(name);
}
else
{
player = UtilServer.GetOffline(name);
}
if (player == null)
{
UtilPlayer.message(caller, F.main("Clans", "Specified player is neither online nor is offline. Perhaps they changed their name?"));
return;
}
new InvseeInventory(player).ShowTo(caller);
}
}
}

View File

@ -0,0 +1,95 @@
package mineplex.game.clans.clans.invsee.ui;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilCollections;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class InvseeInventory implements Listener
{
private OfflinePlayer _player;
private Inventory _inventory;
private boolean _online;
private Player _admin;
public InvseeInventory(OfflinePlayer player)
{
_online = (_player = player) instanceof Player;
_inventory = UtilServer.getServer().createInventory(null, 54, player.getName() + " " + (_online ? C.cGreen + "ONLINE" : C.cRed + "OFFLINE"));
UtilServer.RegisterEvents(this);
}
public void ShowTo(Player admin)
{
_admin = admin;
admin.openInventory(_inventory);
}
@EventHandler
public void quit(PlayerQuitEvent event)
{
if (_online && event.getPlayer().equals(_player))
{
_admin.closeInventory();
}
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
if (_online)
{
if (!UtilCollections.equal(_inventory.getContents(), ((Player) _player).getInventory().getContents()))
{
_inventory.setContents(((Player) _player).getInventory().getContents());
}
}
}
@EventHandler
public void inventoryClick(InventoryClickEvent event)
{
if (event.getClickedInventory().equals(_inventory))
{
if (_online)
{
((Player) _player).getInventory().setContents(_inventory.getContents());
}
}
}
@EventHandler
public void closeInventory(InventoryCloseEvent event)
{
if (event.getInventory().equals(_inventory))
{
UtilServer.Unregister(this);
if (!_online)
{
// save offline inv
}
}
}
}

View File

@ -438,6 +438,19 @@ public class ItemMapManager extends MiniPlugin
event.getEntity().remove();
}
}
public void removeMap(Player player)
{
for (int slot = 0; slot < player.getInventory().getSize(); slot++)
{
ItemStack item = player.getInventory().getItem(slot);
if (item != null && item.getType() == Material.MAP && item.getDurability() >= _mapId && item.getDurability() <= _mapId + 100)
{
player.getInventory().setItem(slot, null);
}
}
}
public ClansUtility getClansUtility()
{

View File

@ -0,0 +1,276 @@
package mineplex.game.clans.clans.nether;
import java.io.File;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.block.Block;
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.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilCollections;
import mineplex.core.common.util.UtilFile;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.core.repository.ClanTerritory;
public class NetherManager extends MiniPlugin
{
private ClansManager _clansManager;
private World _netherWorld;
private List<Portal> _portals = Lists.newArrayList();
private File _portalCfg;
public NetherManager(ClansManager clansManager)
{
super("Nether Manager", clansManager.getPlugin());
_clansManager = clansManager;
_portalCfg = new File(UtilServer.getServer().getWorlds().get(0).getWorldFolder().getPath() + File.separator + ".." + File.separator + "nether.cfg");
begin();
}
public void begin()
{
_netherWorld = Bukkit.getWorld("world_nether");
WorldBorder worldBorder = _netherWorld.getWorldBorder();
worldBorder.setCenter(0, 0);
worldBorder.setSize(200 * 2);
parsePortals();
}
private void parsePortals()
{
String data = UtilFile.read(_portalCfg);
if (data.length() < 5)
{
return;
}
UtilCollections.forEach(data.split("\n"), string -> string.trim(), sPortal -> {
String[] destinations = sPortal.split(">>");
Location from = UtilWorld.strToLoc(destinations[0]);
Location to = UtilWorld.strToLoc(destinations[1].split(":")[0]);
Portal portal = Portal.create(from, to, UtilWorld.strToLoc(to.getWorld().getName() + "," + destinations[1].split(":")[1]));
if (portal == null)
{
log("FAILED TO LOAD PORTAL [" + sPortal + "]");
}
else
{
_portals.add(portal);
}
});
}
@EventHandler
public void cmd(PlayerCommandPreprocessEvent event)
{
if (!_clansManager.getClientManager().hasRank(event.getPlayer(), Rank.JNR_DEV))
{
return;
}
if (event.getMessage().startsWith("/nether"))
{
event.getPlayer().teleport(new Location(_netherWorld, 0, 90, 0));
event.setCancelled(true);
}
}
@EventHandler
public void breakBlock(BlockBreakEvent event)
{
Block block = event.getBlock();
Player player = event.getPlayer();
ItemStack item = player.getItemInHand();
if (player.getGameMode() == GameMode.CREATIVE)
{
return;
}
if (!block.getWorld().equals(_netherWorld))
{
return;
}
_portals
.stream()
.filter(portal -> UtilAlg.getAverageBlockLocation(portal.getToBlocks()).distance(block.getLocation()) < 15)
.limit(1)
.forEach(portal -> {
UtilPlayer.message(player, F.main("Clans", "You are not allowed to break this block."));
event.setCancelled(true);
});
if (!item.getType().equals(Material.GOLD_PICKAXE))
{
UtilPlayer.message(player, F.main("Clans", "You can only break blocks in the Nether with a " + F.elem("Golden Pickaxe") + "."));
event.setCancelled(true);
return;
}
if (block.getType().equals(Material.OBSIDIAN) || block.getType().equals(Material.PORTAL))
{
UtilPlayer.message(player, F.main("Clans", "You are not allowed to break this block."));
event.setCancelled(true);
return;
}
}
@EventHandler
public void placeBlock(BlockPlaceEvent event)
{
Block block = event.getBlock();
Player player = event.getPlayer();
ItemStack item = player.getItemInHand();
if (player.getGameMode() == GameMode.CREATIVE)
{
return;
}
if (!block.getWorld().equals(_netherWorld))
{
return;
}
if (!UtilItem.isFromNether(item))
{
UtilPlayer.message(player, F.main("Clans", "You can only place blocks here that come from " + F.clansNether("The Nether") + "."));
event.setCancelled(true);
return;
}
_portals
.stream()
.filter(portal -> UtilAlg.getAverageBlockLocation(portal.getToBlocks()).distance(block.getLocation()) < 15)
.limit(1)
.forEach(portal -> {
UtilPlayer.message(player, F.main("Clans", "You are not allowed to place blocks here."));
event.setCancelled(true);
});
if (block.getType().equals(Material.OBSIDIAN) || block.getType().equals(Material.PORTAL))
{
UtilPlayer.message(player, F.main("Clans", "You are not allowed to place blocks here."));
event.setCancelled(true);
return;
}
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() == UpdateType.FAST)
{
UtilServer.getPlayersCollection()
.stream()
.filter(player -> player.getWorld().equals(_netherWorld))
.forEach(player -> {
player.setCompassTarget(new Location(_netherWorld, -200.d + UtilMath.r(400), player.getLocation().getY(), -200.d + UtilMath.r(400)));
_clansManager.getItemMapManager().removeMap(player);
});
}
if (event.getType() == UpdateType.SLOW)
{
_portals.forEach(portal -> {
portal.getFromObsidianBlocks().forEach(block -> UtilBlock.setSilent(block, Material.OBSIDIAN));
portal.getFromPortalBlocks().forEach(block -> UtilBlock.setSilent(block, Material.PORTAL));
portal.getToObsidianBlocks().forEach(block -> UtilBlock.setSilent(block, Material.OBSIDIAN));
portal.getToPortalBlocks().forEach(block -> UtilBlock.setSilent(block, Material.PORTAL));
});
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPortal(PlayerPortalEvent event)
{
Player player = event.getPlayer();
Location location = player.getLocation();
ClanTerritory territory = _clansManager.getClanUtility().getClaim(location);
if (event.getTo().getWorld().equals(_netherWorld))
{
if (territory != null && territory.Owner.equals("Borderlands"))
{
_portals
.stream()
.filter(portal ->
portal.getFromPortalBlocks()
.stream()
.filter(block -> player.getLocation().distance(block.getLocation()) <= 2)
.iterator().hasNext()
).limit(1)
.forEach(portal -> {
event.setTo(portal.getToOut());
_clansManager.ClanTips.displayTip(TipType.ENTER_NETHER, player);
});
}
}
else
{
_portals
.stream()
.filter(portal ->
portal.getToPortalBlocks()
.stream()
.filter(block -> player.getLocation().distance(block.getLocation()) <= 2)
.iterator().hasNext()
).limit(1)
.forEach(portal -> {
event.setTo(UtilAlg.getAverageBlockLocation(portal.getFromPortalBlocks()));
});
}
}
public World getNetherWorld()
{
return _netherWorld;
}
public boolean isInNether(Player player)
{
return player.getWorld().equals(_netherWorld);
}
}

View File

@ -0,0 +1,143 @@
package mineplex.game.clans.clans.nether;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import com.google.common.collect.Lists;
import mineplex.core.common.util.UtilBlock;
public class Portal
{
private List<Block> _fromPortalBlocks;
private List<Block> _fromObsidianBlocks;
private List<Block> _toPortalBlocks;
private List<Block> _toObsidianBlocks;
private List<Block> _fromBlocks;
private List<Block> _toBlocks;
private Location _toOut;
public final boolean Success;
public Portal(Location from, Location to, Location toOut)
{
_fromPortalBlocks = Lists.newArrayList();
_fromObsidianBlocks = Lists.newArrayList();
_toPortalBlocks = Lists.newArrayList();
_toObsidianBlocks = Lists.newArrayList();
_toOut = toOut;
if (!isValidPortalBlock(from.getBlock()) || !isValidPortalBlock(to.getBlock()))
{
if (!isValidPortalBlock(from.getBlock()))
from = UtilBlock.getInRadius(from.getBlock(), 4).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation();
if (!isValidPortalBlock(to.getBlock()))
to = UtilBlock.getInRadius(to.getBlock(), 4).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation();
if (to == null || from == null)
{
System.out.println("[PORTAL] INVALID PORTAL PROVIDED (" + from + " --> " + to + ")");
Success = false;
return;
}
}
for (Block other : UtilBlock.getInRadius(from, 7.5d).keySet())
{
if (other.getType() == Material.OBSIDIAN)
{
_fromObsidianBlocks.add(other);
}
else if (other.getType() == Material.PORTAL)
{
_fromPortalBlocks.add(other);
}
}
for (Block other : UtilBlock.getInRadius(to, 7.5d).keySet())
{
if (other.getType() == Material.OBSIDIAN)
{
_toObsidianBlocks.add(other);
}
else if (other.getType() == Material.PORTAL)
{
_toPortalBlocks.add(other);
}
}
_fromBlocks = new ArrayList<>();
_toBlocks = new ArrayList<>();
_fromBlocks.addAll(_fromObsidianBlocks);
_fromBlocks.addAll(_fromPortalBlocks);
_toBlocks.addAll(_toObsidianBlocks);
_toBlocks.addAll(_toPortalBlocks);
Success = true;
}
public Location getToOut()
{
return _toOut;
}
public List<Block> getFromPortalBlocks()
{
return _fromPortalBlocks;
}
public List<Block> getFromObsidianBlocks()
{
return _fromObsidianBlocks;
}
public List<Block> getToPortalBlocks()
{
return _toPortalBlocks;
}
public List<Block> getToObsidianBlocks()
{
return _toObsidianBlocks;
}
public List<Block> getFromBlocks()
{
return _fromBlocks;
}
public List<Block> getToBlocks()
{
return _toBlocks;
}
private boolean isValidPortalBlock(Block block)
{
return block.getType() == Material.OBSIDIAN || block.getType() == Material.PORTAL;
}
public static Portal create(Location from, Location to, Location toOut)
{
Portal portal = new Portal(from, to, toOut);
if (!portal.Success)
{
return null;
}
return portal;
}
}

View File

@ -1,483 +0,0 @@
package mineplex.game.clans.clans.outpost;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.FallingBlock;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.ColorFader;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LoopIterator;
import mineplex.core.common.util.NonFinalInteger;
import mineplex.core.common.util.RGBData;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilColor;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilItem;
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.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.hologram.Hologram;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.core.repository.ClanTerritory;
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
public class Outpost implements Listener
{
protected static final long MAX_LIFETIME = 5 * 60 * 1000; // 30 minutes
public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cBlue + "Outpost").setLore(C.cWhite + "It appears to be a contraption of some sort!").build();
public static final byte OUTPOST_BLOCK_DATA = (byte) 137;
private OutpostManager _host;
private ClanInfo _clan;
private Location _startCorner;
private Location _origin;
private Location _endCorner;
private Location _forceFieldStart;
private Location _forceFieldEnd;
private Location _core;
private LinkedHashMap<String, OutpostBlock> _blocks;
private LinkedHashMap<String, OutpostBlock> _buildQueue;
protected OutpostType _type;
private OutpostState _state;
private Hologram _preHologram;
private Hologram _preHologram2;
private LoopIterator<Vector> _circleStages;
private LoopIterator<Vector> _reverseCircleStages;
private List<OutpostBuilder> _builders;
private List<OutpostBuilder> _removalQueue;
private ColorFader _fader = new ColorFader(30, UtilColor.hexToRgb(0x00A296), UtilColor.hexToRgb(0x29E6B6));
private long _spawnTime;
public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type)
{
_host = host;
_clan = clan;
_startCorner = location.clone().subtract(type._size, 1, type._size);
_endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9);
_builders = new ArrayList<>();
_removalQueue = new ArrayList<>();
_forceFieldStart = _startCorner.clone().subtract(3, 0, 3);
_forceFieldEnd = _endCorner.clone().add(3, 0, 3);
_origin = location.clone();
_type = type;
_spawnTime = System.currentTimeMillis();
_core = _type.getCoreLocation(_origin);
_preHologram = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_clan.getName()) + C.cWhite + "'s Outpost block");
_preHologram2 = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true));
_preHologram.start();
_preHologram2.start();
_state = OutpostState.AWAITING;
}
private void cleanup()
{
_blocks = null;
if (_preHologram != null) _preHologram.stop();
if (_preHologram2 != null) _preHologram2.stop();
_preHologram = null;
_preHologram2 = null;
_state = OutpostState.DEAD;
_host.queueForRemoval(_clan.getName());
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (getState() != OutpostState.AWAITING)
{
return;
}
if (!UtilEvent.isAction(event, ActionType.R_BLOCK))
{
return;
}
if (getLifetime() <= 2000)
{
return;
}
if (!_clan.equals(_clan.Clans.getClanUtility().getClanByPlayer(event.getPlayer())))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "This is not yours to activate!"));
return;
}
if (event.getClickedBlock() != null && _origin.equals(event.getClickedBlock().getLocation()))
{
if (event.getClickedBlock().getType().equals(Material.NETHERRACK))
{
_origin.getBlock().setType(Material.AIR);
beginConstruction();
}
}
}
@EventHandler
public void onBlockDamage(BlockDamageEvent event)
{
if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE)
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_clan.getName()) + "'s Outpost!"));
_core.getBlock().setType(Material.AIR);
_clan.inform("Your Outpost has been destroyed!", null);
UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _clan.getOnlinePlayersArray());
if (getState() == OutpostState.AWAITING)
{
cleanup();
}
else
{
kill();
}
event.setCancelled(true);
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{
if (getState() == OutpostState.AWAITING && event.getBlock().getLocation().equals(_origin))
{
_origin.getBlock().setType(Material.AIR);
_origin.getWorld().dropItem(_origin, OUTPOST_ITEM);
_clan.inform("Your Outpost block has been destroyed.", null);
cleanup();
event.setCancelled(true);
return;
}
System.out.println(_blocks);
_blocks.values().stream().filter(event.getBlock().getLocation()::equals).forEach(block -> {
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks in Outposts."));
event.setCancelled(true);
});
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner, _endCorner))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place blocks in Outposts."));
event.setCancelled(true);
}
}
protected void update()
{
if (_state == OutpostState.AWAITING)
{
if (getLifetime() > 60000)
{
_origin.getBlock().setType(Material.AIR);
_clan.inform("You have lost your Outpost block, as no one activated it fast enough!", null);
cleanup();
return;
}
_preHologram2.setText(UtilText.getProgress(null, UtilMath.clamp(getLifetime(), 0., 60000.) / 60000., null, true));
RGBData color = UtilColor.RgbLightBlue;
for (int x = -_type._size; x <= _type._size; x++)
{
for (int z = -_type._size; z <= _type._size; z++)
{
if (x == -_type._size || x == _type._size || z == -_type._size || z == _type._size)
{
UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, UtilBlock.getHighest(_origin.getWorld(), _origin.clone().add(x + .5, .1, z + .5).getBlockX(), _origin.clone().add(x + .5, .1, z + .5).getBlockZ()).getLocation().add(0.5, 0, 0.5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL);
}
}
}
return;
}
if (_state == OutpostState.CONSTRUCTING)
{
if (_buildQueue.isEmpty())
{
_state = OutpostState.LIVE;
return;
}
else
{
Iterator<String> iterator = _buildQueue.keySet().iterator();
if (iterator.hasNext())
{
_buildQueue.remove(iterator.next()).set();
}
}
// Forcefield
RGBData color = UtilColor.RgbLightBlue;
for (int x = -_type._size; x <= _type._size; x++)
{
for (int z = -_type._size; z <= _type._size; z++)
{
if (x == -_type._size || x == _type._size || z == -_type._size || z == _type._size)
{
UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, _origin.clone().add(x + .5, .1, z + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL);
}
}
}
}
RGBData next = _fader.next();
{
RGBData color = _state == OutpostState.LIVE ? next : UtilColor.RgbRed;
Vector nextCircleStage = _circleStages.next();
double circleX = nextCircleStage.getX();
double circleZ = nextCircleStage.getZ();
UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 5.f, 0, ViewDist.NORMAL);
}
{
RGBData color = _state == OutpostState.LIVE ? next : UtilColor.RgbRed;
Vector nextCircleStage = _reverseCircleStages.next();
double circleX = nextCircleStage.getX();
double circleZ = nextCircleStage.getZ();
UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 5.f, 0, ViewDist.NORMAL);
}
}
@EventHandler
public void forcefield(UpdateEvent event)
{
if (!_removalQueue.isEmpty())
{
_builders.remove(_removalQueue.remove(0));
}
if (event.getType() == UpdateType.TICK && getState() == OutpostState.CONSTRUCTING)
{
for (OutpostBuilder builder : _builders)
{
builder.tick();
}
}
if (event.getType() != UpdateType.FAST && getState() == OutpostState.CONSTRUCTING)
{
return;
}
UtilServer.getPlayersCollection().stream()
.filter(player -> !_clan.isMember(player))
.filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd))
.forEach(player -> {
UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), 1, true, 0.8, 0, 1.1, true);
UtilPlayer.message(player, F.main("Clans", "This Outpost is still under construction!"));
player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f);
});
}
public void beginConstruction()
{
// Cleanup pre-Outpost stuff
_preHologram.stop();
_preHologram2.stop();
_preHologram = null;
_preHologram = null;
_state = OutpostState.CONSTRUCTING;
_blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _clan.Clans));
{
Location pos = UtilBlock.getHighest(_startCorner.getWorld(), _startCorner.clone().subtract(1, 0, 1).getBlockX(), _startCorner.clone().subtract(1, 0, 1).getBlockZ()).getLocation();
_builders.add(new OutpostBuilder(pos, "Peasant", _type.getWallLocations(_origin), this));
}
_clan.inform("Siege", "Your Outpost is now being constructed.", null);
_circleStages = new LoopIterator<Vector>(circleAround(new Vector(0., 0., 0.), 40, .6d));
List<Vector> reverse = circleAround(new Vector(0., 0., 0.), 40, .6d);
Collections.reverse(reverse);
_reverseCircleStages = new LoopIterator<Vector>(reverse);
//Inform nearby Clans
for (int chunkX = -3; chunkX < 3; chunkX++)
{
for (int chunkZ = -3; chunkZ < 3; chunkZ++)
{
ClanTerritory territory = _clan.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ));
if (territory != null && ClansBlacklist.isValidClanName(territory.Owner))
{
ClanInfo clan = _clan.Clans.getClanUtility().getClanByClanName(territory.Owner);
clan.inform("A siege has begun near your territory!", null);
UtilTextMiddle.display("Siege", "A Siege has been declared on your Clan!", 20, 100, 20, clan.getOnlinePlayersArray());
}
}
}
}
private List<Vector> circleAround(Vector origin, int points, double radius)
{
List<Vector> list = new LinkedList<>();
double slice = 2 * Math.PI / points;
for (int point = 0; point < points; point++)
{
double angle = slice * point;
list.add(new Vector(origin.getX() + radius * Math.cos(angle), 0, origin.getZ() + radius * Math.sin(angle)));
}
return list;
}
public void instakill()
{
_blocks.values().forEach(OutpostBlock::restore);
cleanup();
}
public void kill()
{
_state = OutpostState.DESTRUCTING;
NonFinalInteger wait = new NonFinalInteger(0);
_blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean()).forEach(block ->
_host.runSyncLater(() -> {
UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, block._loc, new Vector(0,0,0), 1f, 1, ViewDist.NORMAL);
_origin.getWorld().playSound(block._loc, Sound.EXPLODE, 1.0f, 1.0f);
}, wait.add(4 + UtilMath.random.nextInt(4)).get())
);
_host.runSyncLater(() -> {
_blocks.values().forEach(block -> {
Material mat = Material.getMaterial(block._id);
if (UtilItem.isTranslucent(mat))
{
block.restore();
return;
}
FallingBlock fall = block._loc.getWorld().spawnFallingBlock(block._loc, block._id, block._data);
fall.setDropItem(false);
Vector vec = UtilAlg.getTrajectory(fall.getLocation(), getExactMiddle());
UtilAction.velocity(fall, vec, 1, false, 0, 0.6, 10, false);
fall.setMetadata("ClansOutpost", new FixedMetadataValue(_clan.Clans.getPlugin(), _clan.getName()));
block.restore();
});
cleanup();
}, wait.get() + 5L);
_clan.inform("Your Clan's Outpost has been destroyed.", null);
}
public ClanInfo getClan()
{
return _clan;
}
public long getLifetime()
{
return System.currentTimeMillis() - _spawnTime;
}
public AxisAlignedBB getBounds()
{
return UtilAlg.toBoundingBox(_startCorner, _endCorner);
}
public Location getExactMiddle()
{
return UtilAlg.getMidpoint(_startCorner, _endCorner);
}
public OutpostState getState()
{
return _state;
}
public void queueForRemoval(OutpostBuilder builder)
{
_removalQueue.add(builder);
}
}

View File

@ -1,57 +0,0 @@
package mineplex.game.clans.clans.outpost;
import java.util.Map;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import mineplex.core.common.util.UtilWorld;
public class OutpostBlock
{
protected Location _loc;
protected int _id;
protected byte _data;
protected int _originalId;
protected byte _originalData;
public OutpostBlock(Map<String, OutpostBlock> blocks, Location loc, int id, byte data)
{
_loc = loc;
_id = id;
_data = data;
String locStr = UtilWorld.locToStr(loc);
if (blocks.containsKey(locStr))
{
_originalId = blocks.get(locStr)._originalId;
_originalData = blocks.get(locStr)._originalData;
}
else
{
_originalId = _loc.getBlock().getTypeId();
_originalData = _loc.getBlock().getData();
}
}
public void set()
{
_loc.getBlock().setTypeIdAndData(_id, _data, false);
if (_id != 0)
{
_loc.getWorld().playEffect(_loc, Effect.STEP_SOUND, Material.getMaterial(_id), 10);
}
}
public void restore()
{
BlockState state = _loc.getBlock().getState();
state.setTypeId(_originalId);
state.setRawData(_originalData);
state.update(true, false);
}
}

View File

@ -1,130 +0,0 @@
package mineplex.game.clans.clans.outpost;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.inventory.ItemStack;
import com.mojang.authlib.GameProfile;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.game.clans.clans.outpost.pathing.AStar;
import mineplex.game.clans.clans.outpost.pathing.AStar.InvalidPathException;
import mineplex.game.clans.clans.outpost.pathing.PathingResult;
import mineplex.game.clans.clans.outpost.pathing.Tile;
public class OutpostBuilder
{
private Skeleton _entity;
private List<Location> _path;
private int _pathPos;
private List<Location> _moveLocations;
private int _nextLocation;
private long _arrivedTime;
private long _lastMovement;
private Outpost _host;
public OutpostBuilder(Location pos, String name, List<Location> locations, Outpost host)
{
_host = host;
Location spawnLoc = pos;
Skeleton skel = pos.getWorld().spawn(spawnLoc, Skeleton.class);
skel.teleport(spawnLoc);
skel.setHealth(20);
UtilEnt.Vegetate(skel);
UtilEnt.silence(skel, true);
skel.getEquipment().setHelmet(new ItemStack(Material.NETHER_BRICK_ITEM, 1));
skel.getEquipment().setItemInHand(new ItemStack(Material.IRON_PICKAXE, 1));
// Get in range
List<Player> inRange = UtilPlayer.getNearby(spawnLoc, 75d);
// Disguise
DisguisePlayer disguise = new DisguisePlayer(skel, new GameProfile(Bukkit.getOfflinePlayer("Chiss").getUniqueId(), "Chiss"));
host.getClan().Clans.getDisguiseManager().disguise(disguise, inRange.toArray(new Player[inRange.size()]));
_entity = skel;
_moveLocations = locations;
}
public void tick()
{
if (_path == null || _arrivedTime != -1)
{
_nextLocation = UtilMath.random.nextInt(_moveLocations.size());
_path = calculatePath();
_pathPos = 0;
return;
}
if (System.currentTimeMillis() - _lastMovement >= 500)
{
if (_pathPos == _path.size() - 1)
{
_arrivedTime = 1;
}
else
{
_entity.teleport(_path.get(++_pathPos));
_arrivedTime = -1;
}
_lastMovement = System.currentTimeMillis();
}
}
private List<Location> calculatePath()
{
Location start = _entity.getLocation();
Location end = _moveLocations.get(_nextLocation);
int range = _host._type._size * 2;
try
{
AStar pathFinder = new AStar(start, end, range);
ArrayList<Tile> route = pathFinder.iterate();
PathingResult res = pathFinder.getPathingResult();
if (res == PathingResult.NO_PATH)
{
return Arrays.asList(_moveLocations.get(_nextLocation));
}
List<Location> list = new ArrayList<>();
for (Tile tile : route)
{
list.add(tile.getLocation(start));
}
return list;
}
catch (InvalidPathException e)
{
cleanup();
return null;
}
}
private void cleanup()
{
_entity.remove();
_host.queueForRemoval(this);
}
}

View File

@ -1,212 +0,0 @@
package mineplex.game.clans.clans.outpost;
import java.util.ArrayList;
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.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.common.events.ServerShutdownEvent;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent;
public class OutpostManager extends MiniPlugin
{
private ClansManager _clansManager;
private Map<String, Outpost> _outposts = new HashMap<>();
private List<String> _removalQueue;
public OutpostManager(ClansManager clansManager)
{
super("Outpost Manager", clansManager.getPlugin());
_clansManager = clansManager;
_removalQueue = new ArrayList<>();
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlaceBlock(BlockPlaceEvent event)
{
if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM))
{
if (Spawn(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK2))
{
event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA);
}
else
{
event.setCancelled(true);
}
}
}
public boolean Spawn(Player player, Location location, OutpostType type)
{
if (!_clansManager.isInClan(player))
{
UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place an Outpost."));
return false;
}
if (location.getBlockY() < 10)
{
UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this deep."));
return false;
}
ClanInfo clan = _clansManager.getClan(player);
if (UtilItem.isBoundless(location.clone().subtract(0, 1, 0).getBlock().getType()))
{
UtilPlayer.message(player, F.main("Clans", "An Outpost must not be placed floating."));
return false;
}
if (Get(clan) != null)
{
UtilPlayer.message(player, F.main("Clans", "Your clan already has an outpost"));
return false;
}
if (_clansManager.getClanUtility().getClaim(location) != null)
{
UtilPlayer.message(player, F.main("Clans", "An Outpost must be placed in the Wilderness."));
return false;
}
for (Outpost outpost : _outposts.values())
{
if (UtilMath.offset(location, outpost.getExactMiddle()) < 14)
{
UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost near other Outposts."));
return false;
}
}
for (int x = -type._size; x < type._size; x++)
{
for (int y = -1; y < type._ySize; y++)
{
for (int z = -type._size; z < type._size; z++)
{
Location loc = location.clone().add(x, y, z);
if (_clansManager.getClanUtility().isClaimed(loc))
{
UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost where it may intersect with claimed territory."));
return false;
}
if (UtilBlock.airFoliage(location.clone().add(x, -1, z).getBlock()))
{
UtilPlayer.message(player, F.main("Clans", "An Outpost cannot be placed floating."));
return false;
}
}
}
}
_outposts.put(clan.getName(), new Outpost(this, clan, location, type));
_plugin.getServer().getPluginManager().registerEvents(_outposts.get(clan.getName()), _plugin);
return true;
}
@EventHandler
public void onBlockFall(EntityChangeBlockEvent event)
{
if (event.getEntity().hasMetadata("ClansOutpost"))
{
event.setCancelled(true);
}
}
@EventHandler
public void onServerShutdown(ServerShutdownEvent event)
{
for (Outpost outpost : _outposts.values())
{
outpost.instakill();
}
}
@EventHandler
public void onClaim(PlayerClaimTerritoryEvent event)
{
for (Outpost outpost : _outposts.values())
{
if (outpost.getBounds().b(UtilAlg.toBoundingBox(event.getClaimedChunk().getBlock(0, 0, 0).getLocation(), event.getClaimedChunk().getBlock(15, 254, 15).getLocation())))
{
event.setCancelled(true);
UtilPlayer.message(event.getClaimer(), F.main("Clans", "You cannot claim this territory as it overlaps with " + F.elem(outpost.getClan().getName()) + "'s Outpost."));
break;
}
}
}
@EventHandler
public void update(UpdateEvent event)
{
for (Outpost outpost : _outposts.values())
{
if (outpost.getState() != OutpostState.DEAD)
{
if (outpost.getState() == OutpostState.CONSTRUCTING ? event.getType() == UpdateType.TICK : event.getType() == UpdateType.TICK)
{
outpost.update();
}
}
}
if (event.getType() == UpdateType.FASTER)
{
if (!_removalQueue.isEmpty())
{
HandlerList.unregisterAll(_outposts.remove(_removalQueue.remove(0)));
}
}
if (event.getType() == UpdateType.TWOSEC)
{
for (Outpost outpost : _outposts.values())
{
if (outpost.getState() == OutpostState.LIVE && outpost.getLifetime() > Outpost.MAX_LIFETIME)
{
outpost.kill();
}
}
}
}
public Outpost Get(ClanInfo clan)
{
return _outposts.get(clan.getName().toLowerCase());
}
public void queueForRemoval(String name)
{
_removalQueue.add(name);
}
}

View File

@ -1,10 +0,0 @@
package mineplex.game.clans.clans.outpost;
public enum OutpostState
{
AWAITING,
CONSTRUCTING,
LIVE,
DESTRUCTING,
DEAD;
}

View File

@ -1,391 +0,0 @@
/*
* By @Adamki11s
*/
package mineplex.game.clans.clans.outpost.pathing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.material.Gate;
/**
* Not made by meee (NewGarbo)
* https://bukkit.org/threads/lib-a-pathfinding-algorithm.129786/
*/
public class AStar
{
private final int _sx;
private final int _sy;
private final int _sz;
private final int _ex;
private final int _ey;
private final int _ez;
private final World _world;
private PathingResult _result;
private HashMap<String, Tile> _open = new HashMap<String, Tile>();
private HashMap<String, Tile> _closed = new HashMap<String, Tile>();
private void addToOpenList(Tile t, boolean modify)
{
if (_open.containsKey(t.getUID()))
{
if (modify)
{
_open.put(t.getUID(), t);
}
}
else
{
_open.put(t.getUID(), t);
}
}
private void addToClosedList(Tile t)
{
if (!_closed.containsKey(t.getUID()))
{
_closed.put(t.getUID(), t);
}
}
private final int _range;
private final String _endUID;
public AStar(Location start, Location end, int range) throws InvalidPathException
{
boolean s = true, e = true;
if (!(s = isLocationWalkable(start)) || !(e = isLocationWalkable(end)))
{
throw new InvalidPathException(s, e);
}
_world = start.getWorld();
_sx = start.getBlockX();
_sy = start.getBlockY();
_sz = start.getBlockZ();
_ex = end.getBlockX();
_ey = end.getBlockY();
_ez = end.getBlockZ();
_range = range;
short sh = 0;
Tile t = new Tile(sh, sh, sh, null);
t.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true);
_open.put(t.getUID(), t);
processAdjacentTiles(t);
StringBuilder b = new StringBuilder();
b.append(_ex - _sx).append(_ey - _sy).append(_ez - _sz);
_endUID = b.toString();
}
public Location getEndLocation()
{
return new Location(_world, _ex, _ey, _ez);
}
public PathingResult getPathingResult()
{
return _result;
}
protected boolean _checkOnce = false;
private int abs(int i)
{
return (i < 0 ? -i : i);
}
public ArrayList<Tile> iterate()
{
if (!_checkOnce)
{
// invert the boolean flag
_checkOnce ^= true;
if ((abs(_sx - _ex) > _range) || (abs(_sy - _ey) > _range) || (abs(_sz - _ez) > _range))
{
_result = PathingResult.NO_PATH;
return null;// jump out
}
}
// while not at end
Tile current = null;
while (canContinue())
{
// get lowest F cost square on open list
current = getLowestFTile();
// process tiles
processAdjacentTiles(current);
}
if (_result != PathingResult.SUCCESS)
{
return null;
}
else
{
// path found
LinkedList<Tile> routeTrace = new LinkedList<Tile>();
Tile parent;
routeTrace.add(current);
while ((parent = current.getParent()) != null)
{
routeTrace.add(parent);
current = parent;
}
Collections.reverse(routeTrace);
return new ArrayList<Tile>(routeTrace);
}
}
private boolean canContinue()
{
// check if open list is empty, if it is no path has been found
if (_open.size() == 0)
{
_result = PathingResult.NO_PATH;
return false;
}
else
{
if (_closed.containsKey(_endUID))
{
_result = PathingResult.SUCCESS;
return false;
}
else
{
return true;
}
}
}
private Tile getLowestFTile()
{
double f = 0;
Tile drop = null;
// get lowest F cost square
for (Tile t : _open.values())
{
if (f == 0)
{
t.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true);
f = t.getF();
drop = t;
}
else
{
t.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true);
double posF = t.getF();
if (posF < f)
{
f = posF;
drop = t;
}
}
}
// drop from open list and add to closed
_open.remove(drop.getUID());
addToClosedList(drop);
return drop;
}
private boolean isOnClosedList(Tile t)
{
return _closed.containsKey(t.getUID());
}
// pass in the current tile as the parent
private void processAdjacentTiles(Tile current)
{
// set of possible walk to locations adjacent to current tile
HashSet<Tile> possible = new HashSet<Tile>(26);
for (byte x = -1; x <= 1; x++)
{
for (byte y = -1; y <= 1; y++)
{
for (byte z = -1; z <= 1; z++)
{
if (x == 0 && y == 0 && z == 0)
{
continue;// don't check current square
}
Tile t = new Tile((short) (current.getX() + x), (short) (current.getY() + y), (short) (current.getZ() + z), current);
if (!t.isInRange(_range))
{
// if block is out of bounds continue
continue;
}
if (x != 0 && z != 0 && (y == 0 || y == 1))
{
// check to stop jumping through diagonal blocks
Tile xOff = new Tile((short) (current.getX() + x), (short) (current.getY() + y), (short) (current.getZ()), current), zOff = new Tile((short) (current.getX()), (short) (current.getY() + y), (short) (current.getZ() + z), current);
if (!isTileWalkable(xOff) && !isTileWalkable(zOff))
{
continue;
}
}
if (isOnClosedList(t))
{
// ignore tile
continue;
}
// only process the tile if it can be walked on
if (isTileWalkable(t))
{
t.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true);
possible.add(t);
}
}
}
}
for (Tile t : possible)
{
// get the reference of the object in the array
Tile openRef = null;
if ((openRef = isOnOpenList(t)) == null)
{
// not on open list, so add
addToOpenList(t, false);
}
else
{
// is on open list, check if path to that square is better using
// G cost
if (t.getG() < openRef.getG())
{
// if current path is better, change parent
openRef.setParent(current);
// force updates of F, G and H values.
openRef.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true);
}
}
}
}
private Tile isOnOpenList(Tile t)
{
return (_open.containsKey(t.getUID()) ? _open.get(t.getUID()) : null);
/*
* for (Tile o : open) { if (o.equals(t)) { return o; } } return null;
*/
}
private boolean isTileWalkable(Tile t)
{
Location l = new Location(_world, (_sx + t.getX()), (_sy + t.getY()), (_sz + t.getZ()));
Block b = l.getBlock();
int i = b.getTypeId();
// lava, fire, wheat and ladders cannot be walked on, and of course air
// 85, 107 and 113 stops npcs climbing fences and fence gates
if (i != 10 && i != 11 && i != 51 && i != 59 && i != 65 && i != 0 && i != 85 && i != 107 && i != 113 && !canBlockBeWalkedThrough(i))
{
// make sure the blocks above are air
if (b.getRelative(0, 1, 0).getTypeId() == 107)
{
// fench gate check, if closed continue
Gate g = new Gate(b.getRelative(0, 1, 0).getData());
return (g.isOpen() ? (b.getRelative(0, 2, 0).getTypeId() == 0) : false);
}
return (canBlockBeWalkedThrough(b.getRelative(0, 1, 0).getTypeId()) && b.getRelative(0, 2, 0).getTypeId() == 0);
}
else
{
return false;
}
}
private boolean isLocationWalkable(Location l)
{
Block b = l.getBlock();
int i = b.getTypeId();
if (i != 10 && i != 11 && i != 51 && i != 59 && i != 65 && i != 0 && !canBlockBeWalkedThrough(i))
{
// make sure the blocks above are air or can be walked through
return (canBlockBeWalkedThrough(b.getRelative(0, 1, 0).getTypeId()) && b.getRelative(0, 2, 0).getTypeId() == 0);
}
else
{
return false;
}
}
private boolean canBlockBeWalkedThrough(int id)
{
return (id == 0 || id == 6 || id == 50 || id == 63 || id == 30 || id == 31 || id == 32 || id == 37 || id == 38 || id == 39 || id == 40 || id == 55 || id == 66 || id == 75 || id == 76 || id == 78);
}
@SuppressWarnings("serial")
public class InvalidPathException extends Exception
{
private final boolean _s, _e;
public InvalidPathException(boolean s, boolean e)
{
_s = s;
_e = e;
}
public String getErrorReason()
{
StringBuilder sb = new StringBuilder();
if (!_s)
{
sb.append("Start Location was air. ");
}
if (!_e)
{
sb.append("End Location was air.");
}
return sb.toString();
}
public boolean isStartNotSolid()
{
return (!_s);
}
public boolean isEndNotSolid()
{
return (!_e);
}
}
}

View File

@ -1,23 +0,0 @@
package mineplex.game.clans.clans.outpost.pathing;
/**
* Not made by meee (NewGarbo)
* https://bukkit.org/threads/lib-a-pathfinding-algorithm.129786/
*/
public enum PathingResult
{
SUCCESS(0),
NO_PATH(-1);
private final int _ec;
PathingResult(int ec)
{
_ec = ec;
}
public int getEndCode()
{
return _ec;
}
}

View File

@ -1,183 +0,0 @@
/*
* By @Adamki11s
*/
package mineplex.game.clans.clans.outpost.pathing;
import org.bukkit.Location;
/**
* Not made by meee (NewGarbo)
* https://bukkit.org/threads/lib-a-pathfinding-algorithm.129786/
*/
public class Tile
{
// as offset from starting point
private final short _x;
private final short _y;
private final short _z;
private double _g = -1;
private double _h = -1;
private Tile _parent = null;
private final String _uid;
public Tile(short x, short y, short z, Tile parent)
{
_x = x;
_y = y;
_z = z;
_parent = parent;
StringBuilder b = new StringBuilder();
b.append(x);
b.append(y);
b.append(z);
_uid = b.toString();
}
public boolean isInRange(int range)
{
return ((range - abs(_x) >= 0) && (range - abs(_y) >= 0) && (range - abs(_z) >= 0));
}
public void setParent(Tile parent)
{
_parent = parent;
}
public Location getLocation(Location start)
{
return new Location(start.getWorld(), start.getBlockX() + _x, start.getBlockY() + _y, start.getBlockZ() + _z);
}
public Tile getParent()
{
return _parent;
}
public short getX()
{
return _x;
}
public int getX(Location i)
{
return (i.getBlockX() + _x);
}
public short getY()
{
return _y;
}
public int getY(Location i)
{
return (i.getBlockY() + _y);
}
public short getZ()
{
return _z;
}
public int getZ(Location i)
{
return (i.getBlockZ() + _z);
}
public String getUID()
{
return _uid;
}
public boolean equals(Tile t)
{
return (t.getX() == _x && t.getY() == _y && t.getZ() == _z);
}
public void calculateBoth(int sx, int sy, int sz, int ex, int ey, int ez, boolean update)
{
calculateG(sx, sy, sz, update);
calculateH(sx, sy, sz, ex, ey, ez, update);
}
public void calculateH(int sx, int sy, int sz, int ex, int ey, int ez, boolean update)
{
// only update if h hasn't been calculated or if forced
if ((!update && _h == -1) || update)
{
int hx = sx + _x, hy = sy + _y, hz = sz + _z;
_h = getEuclideanDistance(hx, hy, hz, ex, ey, ez);
}
}
// G = the movement cost to move from the starting point A to a given square
// on the grid, following the path generated to get there.
public void calculateG(int sx, int sy, int sz, boolean update)
{
if ((!update && _g == -1) || update)
{
// only update if g hasn't been calculated or if forced
Tile currentParent = getParent(), currentTile = this;
int gCost = 0;
// follow path back to start
while ((currentParent = currentTile.getParent()) != null)
{
int dx = currentTile.getX() - currentParent.getX(), dy = currentTile.getY() - currentParent.getY(), dz = currentTile.getZ() - currentParent.getZ();
dx = abs(dx);
dy = abs(dy);
dz = abs(dz);
if (dx == 1 && dy == 1 && dz == 1)
{
gCost += 1.7;
} else if (((dx == 1 || dz == 1) && dy == 1) || ((dx == 1 || dz == 1) && dy == 0))
{
gCost += 1.4;
}
else
{
gCost += 1.0;
}
// move backwards a tile
currentTile = currentParent;
}
_g = gCost;
}
}
public double getG()
{
return _g;
}
public double getH()
{
return _h;
}
public double getF()
{
// f = h + g
return (_h + _g);
}
private double getEuclideanDistance(int sx, int sy, int sz, int ex, int ey, int ez)
{
double dx = sx - ex, dy = sy - ey, dz = sz - ez;
return Math.sqrt((dx * dx) + (dy * dy) + (dz * dz));
}
private int abs(int i)
{
return (i < 0 ? -i : i);
}
}

View File

@ -14,7 +14,7 @@ public class cemde extends CommandBase<StatsManager>
PvpTimer _timer;
public cemde(StatsManager plugin, PvpTimer timer)
{
super(plugin, Rank.ALL, "rstime");
super(plugin, Rank.SNR_MODERATOR, "rstime");
_timer = timer;
}

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import mineplex.core.MiniClientPlugin;
@ -65,14 +66,27 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
public void disableFor(final Player caller)
{
TaskManager.Instance.completedTask(new Callback<Boolean>() {
@Override
public void run(Boolean data)
{
Get(caller).Skipped = true;
caller.playSound(caller.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 0.75f);
}
}, caller, "PvpTimer.Skipped");
Get(caller).Skipped = true;
caller.playSound(caller.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 0.75f);
TaskManager.Instance.completedTask(null, caller, "PvpTimer.Skipped");
}
@EventHandler
public void fireBow(EntityShootBowEvent event)
{
if (!(event.getEntity() instanceof Player))
{
return;
}
if (hasTimer((Player) event.getEntity()))
{
UtilPlayer.message(event.getEntity(), F.main("Clans", "You may not fire bows while on a PvP timer."));
UtilPlayer.message(event.getEntity(), C.cGoldB + "> " + C.cGold + "To permanently disable PvP Safety, type " + C.cGreen + "/pvp" + C.cGold + ".");
event.setCancelled(true);
}
}
@EventHandler
@ -94,14 +108,7 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
UtilPlayer.message(player, " ");
UtilPlayer.message(player, C.cDRedB + ">>" + C.cRed + " You are not permitted to enter the Borderlands while under PvP Safety.");
new JsonMessage(C.cGoldB + "> " + C.cGold + "To permanently disable PvP Safety, click ")
.extra("here")
.color("yellow")
.click(ClickEvent.RUN_COMMAND, "/pvptimer yesiconfirmthatiwouldliketodisablemypvptimerforever")
.extra(".")
.color("gray")
.sendToPlayer(player);
UtilPlayer.message(player, C.cGoldB + "> " + C.cGold + "To permanently disable PvP Safety, type " + C.cGreen + "/pvp" + C.cGold + ".");
UtilPlayer.message(player, " ");
}

View File

@ -137,7 +137,7 @@ public class ClansRegions extends MiniPlugin
* @param claimOffset - the initial offset in claim (creating a 'hole' with chunk offset radius)
* @param safe - whether the chunk claimed is considered a 'safe' (pvp-free) region.
*/
private void claimArea(final String clanName, final int chunkRadius, final int claimOffset, final boolean safe, final boolean addNegative, final Location... locations)
public void claimArea(final String clanName, final int chunkRadius, final int claimOffset, final boolean safe, final boolean addNegative, final Location... locations)
{
final ClanInfo clan = _manager.getClan(clanName);

View File

@ -9,8 +9,6 @@ import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import net.minecraft.server.v1_8_R3.ScoreboardTeam;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilText;
import mineplex.core.scoreboard.PlayerScoreboard;

View File

@ -45,7 +45,7 @@ public class ClansScoreboardManager extends ScoreboardManager
private void init()
{
setTitle("Clans Alpha " + Clans.VERSION);
setTitle("Clans " + Clans.VERSION);
ScoreboardData data = getData("default", true);

View File

@ -44,6 +44,12 @@ public class ScoreboardElementPlayer implements ScoreboardElement
regionString += C.mBody + "(" + C.mElem + "Trusted" + C.mBody + ")";
}
// if (_clansManager.getNetherManager().isInNether(player))
// {
// regionString = C.cRed + "The Nether";
// }
output.add(regionString);
return output;

View File

@ -0,0 +1,276 @@
package mineplex.game.clans.clans.siege;
import java.util.Stack;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent;
import com.google.gson.Gson;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.commands.CommandSiegeSupplies;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.repository.SiegeWeaponRepository;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.Cannon;
import mineplex.game.clans.clans.siege.weapon.Catapult;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
import mineplex.game.clans.core.repository.ClanTerritory;
public class SiegeManager extends MiniPlugin
{
private ClansManager _clansManager;
private OutpostManager _outpostManager;
public static SiegeManager Instance;
public NautHashMap<Integer, SiegeWeapon> LiveSiegeWeapons = new NautHashMap<>();
private Gson _gson;
private SiegeWeaponRepository _repository;
public SiegeManager(ClansManager clans)
{
super("Siege Manager", clans.getPlugin());
_gson = new Gson();
_clansManager = clans;
_outpostManager = new OutpostManager(clans, this);
addCommand(new CommandSiegeSupplies(_outpostManager));
Instance = this;
_repository = new SiegeWeaponRepository(clans.getPlugin(), this);
_outpostManager.loadOutposts(() -> {
loadSiegeWeapons();
});
}
@EventHandler
public void save(UpdateEvent event)
{
if (event.getType() == UpdateType.SLOWER)
{
_outpostManager.saveOutposts(() -> {
saveSiegeWeapons();
});
}
}
private void loadSiegeWeapons()
{
_repository.getWeaponsByServer(_clansManager.getServerId(), tokens ->
tokens.forEach(token -> {
SiegeWeapon weapon = null;
switch(token.WeaponType)
{
case 1:
weapon = new Catapult(this, token);
break;
case 2:
weapon = new Cannon(this, token);
break;
default:
System.out.println("[WEAPONS] ERROR WHILST LOADING WEAPON: INVALID WEAPON TYPE");
return;
}
if (!weapon.getLocation().getChunk().load())
{
System.out.println("[WEAPONS] SKIPPING & REMOVING WEAPON [" + token.UniqueId + "] BECAUSE OF CHUNK LOADING FAILURE");
weapon.kill();
_repository.deleteWeapon(token.UniqueId);
return;
}
System.out.println("[WEAPONS] LOADED SIEGE WEAPON " + weapon.getClass().getSimpleName() + " [" + token.UniqueId + "]");
LiveSiegeWeapons.put(Integer.valueOf(token.UniqueId), weapon);
})
);
}
private void saveSiegeWeapons()
{
final Stack<Runnable> queue = new Stack<>();
for (final SiegeWeapon weapon : LiveSiegeWeapons.values())
{
final SiegeWeaponToken token = weapon.toToken();
queue.push(() -> {
_repository.updateWeapon(token);
});
}
runAsync(() -> {
while (!queue.isEmpty())
{
queue.pop().run();
}
});
runAsync(() ->
_repository.getWeaponsByServer(_clansManager.getServerId(), tokens ->
tokens.forEach(token -> {
if (!LiveSiegeWeapons.containsKey(Integer.valueOf(token.UniqueId)))
{
_repository.deleteWeapon(token.UniqueId);
}
})
)
);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
if (event.getItemInHand().isSimilar(Cannon.CANNON_ITEM))
{
event.setCancelled(true);
if (trySpawnCannon(event.getPlayer(), event.getBlock().getLocation()))
{
event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand()));
return;
}
}
// if (event.getItemInHand().isSimilar(Catapult.CATAPULT_ITEM))
// {
// event.setCancelled(true);
//
// if (trySpawnCatapult(event.getPlayer(), event.getBlock().getLocation()))
// {
// event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand()));
// return;
// }
// }
}
public boolean trySpawnCannon(Player player, Location location)
{
// if (_clansManager.getNetherManager().isInNether(player))
// {
// _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + ".");
//
// return false;
// }
if (!_clansManager.isInClan(player))
{
UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a Cannon."));
return false;
}
ClanTerritory claim = _clansManager.getClanUtility().getClaim(location);
if (claim != null && !claim.Owner.equals(_clansManager.getClan(player).getName()))
{
UtilPlayer.message(player, F.main("Clans", "You must place a Cannon in the Wilderness or your own Territory."));
return false;
}
spawnCannon(player, location);
return true;
}
public void spawnCannon(Player player, Location location)
{
Cannon cannon = new Cannon(location, _clansManager.getClan(player), this);
LiveSiegeWeapons.put(Integer.valueOf(cannon.getUniqueId()), cannon);
}
public boolean trySpawnCatapult(Player player, Location location)
{
// if (_clansManager.getNetherManager().isInNether(player))
// {
// _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + ".");
//
// return false;
// }
if (!_clansManager.isInClan(player))
{
UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a Catapult."));
return false;
}
ClanTerritory claim = _clansManager.getClanUtility().getClaim(location);
if (claim != null && !claim.Owner.equals(_clansManager.getClan(player).getName()))
{
UtilPlayer.message(player, F.main("Clans", "You must place a Catapult in the Wilderness or your own Territory."));
return false;
}
spawnCatapult(player, location);
return true;
}
public void spawnCatapult(Player player, Location location)
{
Catapult catapult = new Catapult(location, _clansManager.getClan(player), this);
LiveSiegeWeapons.put(Integer.valueOf(catapult.getUniqueId()), catapult);
}
public void dead(SiegeWeapon weapon)
{
LiveSiegeWeapons.remove(Integer.valueOf(weapon.getUniqueId()));
_repository.deleteWeapon(weapon.getUniqueId());
}
public OutpostManager getOutpostManager()
{
return _outpostManager;
}
public Gson getGson()
{
return _gson;
}
public ClansManager getClansManager()
{
return _clansManager;
}
public int randomId()
{
/**
* prevents id from ever being 0 (which is used internally as NULL)
*/
return 1 + UtilMath.random.nextInt(Integer.MAX_VALUE - 1);
}
public SiegeWeaponRepository getRepository()
{
return _repository;
}
}

View File

@ -0,0 +1,39 @@
package mineplex.game.clans.clans.siege.commands;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.weapon.Cannon;
import mineplex.game.clans.clans.siege.weapon.Catapult;
public class CommandSiegeSupplies extends CommandBase<OutpostManager>
{
public CommandSiegeSupplies(OutpostManager plugin)
{
super(plugin, Rank.MODERATOR, "siege");
}
@Override
public void Execute(Player caller, String[] args)
{
ItemStack outpost = new ItemStack(Outpost.OUTPOST_ITEM);
ItemStack cannons = new ItemStack(Cannon.CANNON_ITEM);
// ItemStack catapults = new ItemStack(Catapult.CATAPULT_ITEM);
outpost.setAmount(64);
cannons.setAmount(64);
// catapults.setAmount(64);
caller.getInventory().addItem(outpost);
caller.getInventory().addItem(cannons);
// caller.getInventory().addItem(catapults);
UtilPlayer.message(caller, F.main("Clans", "Received supplies for a siege."));
}
}

View File

@ -0,0 +1,53 @@
package mineplex.game.clans.clans.siege.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
public class SiegeWeaponExplodeEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private SiegeWeapon _weapon;
private WeaponProjectile _projectile;
private boolean _cancelled;
public SiegeWeaponExplodeEvent(SiegeWeapon weapon, WeaponProjectile projectile)
{
_weapon = weapon;
_projectile = projectile;
}
public SiegeWeapon getWeapon()
{
return _weapon;
}
public WeaponProjectile getProjectile()
{
return _projectile;
}
public boolean isCancelled()
{
return _cancelled;
}
public void setCancelled(boolean cancelled)
{
_cancelled = cancelled;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -0,0 +1,638 @@
package mineplex.game.clans.clans.siege.outpost;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.FallingBlock;
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.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Door;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.ColorFader;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LoopIterator;
import mineplex.core.common.util.NonFinalInteger;
import mineplex.core.common.util.RGBData;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilColor;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilItem;
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.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTrig;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramInteraction;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.event.ClansWaterPlaceEvent;
import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent;
import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock;
import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken;
import mineplex.game.clans.core.repository.ClanTerritory;
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
public class Outpost implements Listener
{
protected static final long MAX_LIFETIME = 30 * 60 * 1000; // 30 minutes
public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cBlue + "Outpost").setLore(C.cWhite + "It appears to be a contraption of some sort!").build();
public static final long PREP_TIME = 2 * 60 * 1000;
private OutpostManager _outpostManager;
private final int _uniqueId;
private ClanInfo _ownerClan;
private Location _startCorner;
private Location _origin;
private Location _endCorner;
private Location _forceFieldStart;
private Location _forceFieldEnd;
private Location _core;
private LinkedHashMap<String, OutpostBlock> _blocks;
private LinkedHashMap<String, OutpostBlock> _buildQueue;
protected OutpostType _type;
private OutpostState _state;
private Hologram _preHologram;
private Hologram _preHologram2;
private LoopIterator<Vector> _circleStages;
private LoopIterator<Vector> _reverseCircleStages;
private ColorFader _fader = new ColorFader(30, UtilColor.hexToRgb(0x00A296), UtilColor.hexToRgb(0x29E6B6));
private long _timeSpawned;
public ClanInfo _againstClan;
private List<Hologram> _nameHolograms;
private Hologram _lifetimeLeft;
public Outpost(OutpostManager outpostManager, OutpostToken token)
{
_outpostManager = outpostManager;
_uniqueId = token.UniqueId;
_ownerClan = token.OwnerClan;
_nameHolograms = new ArrayList<>();
_startCorner = token.Origin.clone().subtract(token.Type._size, 1.1, token.Type._size);
_endCorner = token.Origin.clone().add(token.Type._size + .9, token.Type._ySize - 1, token.Type._size + .9);
_forceFieldStart = _startCorner.clone().subtract(4, 0, 4);
_forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5);
_origin = token.Origin.clone();
_type = token.Type;
_timeSpawned = token.TimeSpawned;
_core = _type.getCoreLocation(_origin);
_preHologram = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)");
_preHologram2 = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true));
_lifetimeLeft = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 1.5, 0.5), "Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME)));
_lifetimeLeft.setInteraction(new HologramInteraction()
{
public void onClick(Player player, ClickType clickType)
{
if (_ownerClan.isMember(player) || _state != OutpostState.LIVE)
return;
if (clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT)
kill();
}
});
if (token.OutpostState == OutpostState.AWAITING)
{
_preHologram.start();
_preHologram2.start();
}
_blocks = _type.createBuildQueue(_origin, _ownerClan.Clans);
_state = token.OutpostState;
_circleStages = new LoopIterator<Vector>(UtilTrig.GetCirclePoints(new Vector(0., 0., 0.), 40, .6d));
List<Vector> reverse = UtilTrig.GetCirclePoints(new Vector(0., 0., 0.), 40, .6d);
Collections.reverse(reverse);
_reverseCircleStages = new LoopIterator<Vector>(reverse);
if (token.OutpostState == OutpostState.CONSTRUCTING || token.OutpostState == OutpostState.LIVE)
{
_nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0).add(2, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName()));
_nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0).subtract(2, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName()));
_nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1).add(0, 0, 2).add(.5, 0, .5), C.cGreen + _ownerClan.getName()));
_nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1).subtract(0, 0, 2).add(.5, 0, .5), C.cGreen + _ownerClan.getName()));
_nameHolograms.forEach(Hologram::start);
_nameHolograms.forEach(hologram ->
hologram.setInteraction((player, click) ->
UtilBlock.getInRadius(hologram.getLocation(), 2, 2).forEach((block, dist) -> {
if (block.getType() == Material.IRON_DOOR)
{
Door door = (Door) block.getState();
door.setOpen(!door.isOpen());
}
})
)
);
_lifetimeLeft.start();
}
}
public Outpost(OutpostManager outpostManager, ClanInfo clan, Location location, OutpostType type)
{
_outpostManager = outpostManager;
_uniqueId = outpostManager.getSiegeManager().randomId();
_ownerClan = clan;
_startCorner = location.clone().subtract(type._size, 1.1, type._size);
_endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9);
_forceFieldStart = _startCorner.clone().subtract(4, 0, 4);
_forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5);
_origin = location.clone();
_type = type;
_timeSpawned = System.currentTimeMillis();
_core = _type.getCoreLocation(_origin);
_nameHolograms = new ArrayList<>();
_preHologram = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)");
_preHologram2 = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true));
_preHologram.start();
_preHologram2.start();
_state = OutpostState.AWAITING;
_outpostManager.getRepository().insertOutpost(toToken());
_circleStages = new LoopIterator<Vector>(UtilTrig.GetCirclePoints(new Vector(0., 0., 0.), 40, .6d));
List<Vector> reverse = UtilTrig.GetCirclePoints(new Vector(0., 0., 0.), 40, .6d);
Collections.reverse(reverse);
_reverseCircleStages = new LoopIterator<Vector>(reverse);
UtilServer.RegisterEvents(this);
_lifetimeLeft = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 1.5, 0.5), "Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME)));
_lifetimeLeft.setInteraction(new HologramInteraction()
{
public void onClick(Player player, ClickType clickType)
{
if (_ownerClan.isMember(player) || _state != OutpostState.LIVE)
return;
if (clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT)
kill();
}
});
_nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0).add(2, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName()));
_nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0).subtract(2, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName()));
_nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1).add(0, 0, 2).add(.5, 0, .5), C.cGreen + _ownerClan.getName()));
_nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1).subtract(0, 0, 2).add(.5, 0, .5), C.cGreen + _ownerClan.getName()));
}
private void cleanup()
{
_blocks = null;
if (_preHologram != null) _preHologram.stop();
if (_preHologram2 != null) _preHologram2.stop();
_preHologram = null;
_preHologram2 = null;
_state = OutpostState.DEAD;
_nameHolograms.forEach(Hologram::stop);
_outpostManager.queueForRemoval(_ownerClan.getName());
}
@EventHandler(priority = EventPriority.HIGH)
public void onInteract(PlayerInteractEvent event)
{
if (getState() == OutpostState.LIVE)
{
do
{
if (event.getClickedBlock() == null)
break;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
break;
if (!UtilItem.isDoor(event.getClickedBlock().getType()))
break;
if (_ownerClan.isMember(event.getPlayer()))
break;
if (UtilAlg.inBoundingBox(event.getClickedBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You cannot open the doors of this Outpost."));
event.setCancelled(true);
return;
}
} while(false);
}
if (getState() != OutpostState.AWAITING)
return;
if (!UtilEvent.isAction(event, ActionType.R_BLOCK))
return;
if (getLifetime() <= 2000)
return;
if (!_ownerClan.equals(_ownerClan.Clans.getClanUtility().getClanByPlayer(event.getPlayer())))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "This is not yours to activate!"));
return;
}
if (event.getClickedBlock() != null && _origin.equals(event.getClickedBlock().getLocation()))
{
if (event.getClickedBlock().getType().equals(Material.NETHERRACK))
{
_origin.getBlock().setType(Material.AIR);
beginConstruction();
}
}
}
@EventHandler
public void onBlockDamage(BlockDamageEvent event)
{
if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE)
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!"));
_core.getBlock().setType(Material.AIR);
_ownerClan.inform("Your Outpost has been destroyed!", null);
UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray());
if (getState() == OutpostState.AWAITING)
cleanup();
else
kill();
event.setCancelled(true);
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{
if (getState() == OutpostState.AWAITING && event.getBlock().getLocation().equals(_origin))
{
_origin.getBlock().setType(Material.AIR);
_origin.getWorld().dropItem(_origin, OUTPOST_ITEM);
_ownerClan.inform("Your Outpost block has been destroyed.", null);
cleanup();
event.setCancelled(true);
return;
}
if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE)
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!"));
_core.getBlock().setType(Material.AIR);
_ownerClan.inform("Your Outpost has been destroyed!", null);
UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray());
if (getState() == OutpostState.AWAITING)
cleanup();
else
kill();
event.setCancelled(true);
return;
}
if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks in Outposts."));
event.setCancelled(true);
}
}
@EventHandler
public void onWaterPlace(ClansWaterPlaceEvent event)
{
if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place water in Outposts."));
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event)
{
if (event.isCancelled())
return;
if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place blocks in Outposts."));
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void claimTerritory(PlayerClaimTerritoryEvent event)
{
if (UtilMath.offset2d(event.getClaimedChunk().getBlock(8, 0, 8).getLocation(), _origin) < 32)
{
UtilPlayer.message(event.getClaimer(), F.main("Clans", "You may not claim this close to an Outpost."));
event.setCancelled(true);
}
}
protected void update()
{
if (_state == OutpostState.AWAITING)
{
if (getLifetime() > 60000)
{
_origin.getBlock().setType(Material.AIR);
_ownerClan.inform("You have lost your Outpost block, as no one activated it fast enough!", null);
cleanup();
return;
}
_preHologram2.setText(UtilText.getProgress(null, UtilMath.clamp(getLifetime(), 0., 60000.) / 60000., null, true));
RGBData color = UtilColor.RgbLightBlue;
for (int x = -_type._size; x <= _type._size; x++)
for (int z = -_type._size; z <= _type._size; z++)
if (x == -_type._size || x == _type._size || z == -_type._size || z == _type._size)
UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, UtilBlock.getHighest(_origin.getWorld(), _origin.clone().add(x + .5, .1, z + .5).getBlockX(), _origin.clone().add(x + .5, .1, z + .5).getBlockZ()).getLocation().add(0.5, 0, 0.5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL);
return;
}
if (_lifetimeLeft != null)
_lifetimeLeft.setText("Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME - (System.currentTimeMillis() - _timeSpawned))));
if (_state == OutpostState.CONSTRUCTING)
{
if (_buildQueue.isEmpty())
{
_state = OutpostState.LIVE;
return;
}
else
{
Iterator<String> iterator = _buildQueue.keySet().iterator();
if (iterator.hasNext())
_buildQueue.remove(iterator.next()).set();
}
// Forcefield
RGBData color = UtilColor.RgbLightBlue;
for (int x = _forceFieldStart.getBlockX(); x <= _forceFieldEnd.getBlockX(); x++)
for (int z = _forceFieldStart.getBlockZ(); z <= _forceFieldEnd.getBlockZ(); z++)
if (x == _forceFieldStart.getBlockX() || x == _forceFieldEnd.getBlockX() || z == _forceFieldStart.getBlockZ() || z == _forceFieldEnd.getBlockZ())
UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, new Location(_core.getWorld(), x + .5, UtilBlock.getHighest(_core.getWorld(), x, z).getY() + .15, z + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL);
}
RGBData next = _fader.next();
{
RGBData color = _state == OutpostState.LIVE ? next : UtilColor.RgbRed;
Vector nextCircleStage = _circleStages.next();
double circleX = nextCircleStage.getX();
double circleZ = nextCircleStage.getZ();
UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1.f, 0, ViewDist.NORMAL);
}
{
RGBData color = _state == OutpostState.LIVE ? next : UtilColor.RgbRed;
Vector nextCircleStage = _reverseCircleStages.next();
double circleX = nextCircleStage.getX();
double circleZ = nextCircleStage.getZ();
UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1.f, 0, ViewDist.NORMAL);
}
}
@EventHandler
public void forcefield(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST || getState() != OutpostState.CONSTRUCTING)
return;
UtilServer.getPlayersCollection().stream()
.filter(player -> !_ownerClan.isMember(player))
.filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd))
.forEach(player -> {
UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .77, true, 0.8, 0, 1.1, true);
UtilPlayer.message(player, F.main("Clans", "This Outpost is still under construction!"));
player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f);
});
}
public void beginConstruction()
{
// Cleanup pre-Outpost stuff
_preHologram.stop();
_preHologram2.stop();
_preHologram = null;
_preHologram = null;
_lifetimeLeft.start();
_state = OutpostState.CONSTRUCTING;
_blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _ownerClan.Clans));
_ownerClan.inform("Siege", "Your Outpost is now being constructed.", null);
//Inform nearby Clans
for (int chunkX = -3; chunkX < 3; chunkX++)
for (int chunkZ = -3; chunkZ < 3; chunkZ++)
{
ClanTerritory territory = _ownerClan.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ));
if (territory != null && ClansBlacklist.isValidClanName(territory.Owner))
{
ClanInfo clan = _ownerClan.Clans.getClanUtility().getClanByClanName(territory.Owner);
clan.inform("A siege has begun near your territory!", null);
UtilTextMiddle.display("Siege", "A Siege has been declared on your Clan!", 20, 100, 20, clan.getOnlinePlayersArray());
}
}
_nameHolograms.forEach(Hologram::start);
}
public void kill()
{
_state = OutpostState.DESTRUCTING;
NonFinalInteger wait = new NonFinalInteger(0);
_blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(13).forEach(block ->
_outpostManager.runSyncLater(() -> {
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, block.getLocation(), new Vector(0,0,0), 1f, 1, ViewDist.MAX);
_origin.getWorld().playSound(block.getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
}, wait.add(4 + UtilMath.random.nextInt(4)).get())
);
_outpostManager.runSyncLater(() -> {
_blocks.values().stream().forEach(OutpostBlock::restore);
}, wait.get() + 5L);
_outpostManager.runSyncLater(() -> {
_blocks.values().stream().forEach(block -> {
Material mat = Material.getMaterial(block.getId());
if (UtilItem.isTranslucent(mat))
{
block.restore();
return;
}
FallingBlock fall = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(), block.getId(), block.getData());
fall.setDropItem(false);
Vector vec = UtilAlg.getTrajectory(fall.getLocation(), getExactMiddle());
UtilAction.velocity(fall, vec, 1, false, 0, 0.6, 10, false);
fall.setMetadata("ClansOutpost", new FixedMetadataValue(_ownerClan.Clans.getPlugin(), _ownerClan.getName()));
block.restore();
});
cleanup();
}, wait.get() + 6L);
if (_lifetimeLeft != null) _lifetimeLeft.stop();
_lifetimeLeft = null;
_ownerClan.inform("Your Clan's Outpost has been destroyed.", null);
}
public ClanInfo getOwner()
{
return _ownerClan;
}
public long getLifetime()
{
return System.currentTimeMillis() - _timeSpawned;
}
public AxisAlignedBB getBounds()
{
return UtilAlg.toBoundingBox(_startCorner, _endCorner);
}
public Location getExactMiddle()
{
return UtilAlg.getMidpoint(_startCorner, _endCorner);
}
public OutpostState getState()
{
return _state;
}
public ClanInfo getAgainst()
{
return _againstClan;
}
public int getUniqueId()
{
return _uniqueId;
}
public OutpostToken toToken()
{
OutpostToken token = new OutpostToken();
token.UniqueId = _uniqueId;
token.Origin = _origin;
token.Type = _type;
token.OwnerClan = _ownerClan;
token.TimeSpawned = _timeSpawned;
token.OutpostState = _state;
return token;
}
}

View File

@ -0,0 +1,315 @@
package mineplex.game.clans.clans.siege.outpost;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.repository.OutpostRepository;
import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken;
import mineplex.game.clans.core.repository.ClanTerritory;
public class OutpostManager extends MiniPlugin
{
private ClansManager _clansManager;
private NautHashMap<String, Outpost> _outposts = new NautHashMap<>();
private NautHashMap<Integer, Outpost> _idToOutpost = new NautHashMap<>();
private List<String> _removalQueue;
private SiegeManager _siegeManager;
private OutpostRepository _repository;
public OutpostManager(ClansManager clansManager, SiegeManager siegeManager)
{
super("Outpost Manager", clansManager.getPlugin());
_siegeManager = siegeManager;
_clansManager = clansManager;
_repository = new OutpostRepository(clansManager.getPlugin(), this);
_removalQueue = new ArrayList<>();
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlaceBlock(BlockPlaceEvent event)
{
if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM))
if (!spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK_III))
event.setCancelled(true);
}
public boolean spawnOutpost(Player player, Location location, OutpostType type)
{
// if (_clansManager.getNetherManager().isInNether(player))
// {
// _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + ".");
//
// return false;
// }
if (!_clansManager.isInClan(player))
{
UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place an Outpost."));
return false;
}
if (location.getBlockY() < 30)
{
UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this deep."));
return false;
}
ClanInfo clan = _clansManager.getClan(player);
if (UtilItem.isBoundless(location.clone().subtract(0, 1, 0).getBlock().getType()))
{
UtilPlayer.message(player, F.main("Clans", "An Outpost must not be placed floating."));
return false;
}
if (Get(clan) != null)
{
UtilPlayer.message(player, F.main("Clans", "Your Clan already has an outpost."));
return false;
}
if (_clansManager.getClanUtility().getClaim(location) != null)
{
UtilPlayer.message(player, F.main("Clans", "An Outpost must be placed in the Wilderness."));
return false;
}
for (Outpost outpost : _outposts.values())
{
if (UtilMath.offset(location, outpost.getExactMiddle()) < type._size + 8)
{
UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost near other Outposts."));
return false;
}
}
for (int x = -4; x < 4; x++)
for (int z = -4; z < 4; z++)
{
Chunk chunk = location.getWorld().getChunkAt(location.getChunk().getX() + x, location.getChunk().getZ() + z);
ClanTerritory claim = _clansManager.getClanUtility().getClaim(chunk);
if (claim != null)
{
if (!claim.Owner.equals(clan.getName()) && ClansBlacklist.isValidClanName(claim.Owner))
{
UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this close to a Clan's Territory."));
return false;
}
}
}
boolean gut = false;
for (int x = -6; x < 6; x++)
for (int z = -6; z < 6; z++)
{
Chunk chunk = location.getWorld().getChunkAt(location.getChunk().getX() + x, location.getChunk().getZ() + z);
ClanTerritory claim = _clansManager.getClanUtility().getClaim(chunk);
if (claim != null)
{
System.out.println(claim.Owner + ", " + clan.getName());
if (!claim.Owner.equals(clan.getName()) && ClansBlacklist.isValidClanName(claim.Owner))
{
gut = true; /* das ist gut!!! */
break;
}
}
}
/* das ist schlecht */
if (!gut)
{
UtilPlayer.message(player, F.main("Clans", "An Outpost must be placed near a rival Clan's Territory."));
return false;
}
for (int x = -type._size; x < type._size; x++)
for (int y = -1; y < type._ySize; y++)
for (int z = -type._size; z < type._size; z++)
{
Location loc = location.clone().add(x, y, z);
if (_clansManager.getClanUtility().isClaimed(loc))
{
UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost where it may intersect with claimed territory."));
return false;
}
}
_outposts.put(clan.getName(), new Outpost(this, clan, location, type));
_idToOutpost.put(_outposts.get(clan.getName()).getUniqueId(), _outposts.get(clan.getName()));
return true;
}
@EventHandler
public void onBlockFall(EntityChangeBlockEvent event)
{
if (event.getEntity().hasMetadata("ClansOutpost"))
event.setCancelled(true);
}
@EventHandler
public void onClaim(PlayerClaimTerritoryEvent event)
{
for (Outpost outpost : _outposts.values())
if (outpost.getBounds().b(UtilAlg.toBoundingBox(event.getClaimedChunk().getBlock(0, 0, 0).getLocation(), event.getClaimedChunk().getBlock(15, 254, 15).getLocation())))
{
event.setCancelled(true);
UtilPlayer.message(event.getClaimer(), F.main("Clans", "You cannot claim this territory as it overlaps with " + F.elem(outpost.getOwner().getName()) + "'s Outpost."));
break;
}
}
@EventHandler
public void update(UpdateEvent event)
{
_outposts.values()
.stream()
.filter(outpost -> outpost.getState() == OutpostState.CONSTRUCTING ? event.getType() == UpdateType.TICK : event.getType() == UpdateType.TICK)
.forEach(Outpost::update);
if (event.getType() == UpdateType.FASTER)
if (!_removalQueue.isEmpty())
HandlerList.unregisterAll(_idToOutpost.remove(Integer.valueOf(_outposts.remove(_removalQueue.remove(0)).getUniqueId())));
if (event.getType() == UpdateType.TWOSEC)
_outposts.values()
.stream()
.filter(outpost -> outpost.getState() == OutpostState.LIVE && outpost.getLifetime() > Outpost.MAX_LIFETIME)
.forEach(Outpost::kill);
}
public Outpost Get(ClanInfo clan)
{
return clan == null ? null : _outposts.get(clan.getName().toLowerCase());
}
public void queueForRemoval(String name)
{
_removalQueue.add(name);
}
public SiegeManager getSiegeManager()
{
return _siegeManager;
}
public List<Outpost> getOutposts()
{
return Lists.newArrayList(_outposts.values());
}
public Outpost Get(int outpostId)
{
return _idToOutpost.get(Integer.valueOf(outpostId));
}
public ClansManager getClansManager()
{
return _clansManager;
}
public void loadOutposts(Runnable post)
{
System.out.println("[OUTPOSTS] LOADING OUTPOSTS FROM DATABASE");
_repository.getOutpostsByServer(_clansManager.getServerId(), tokens -> {
tokens.forEach(token -> {
Outpost outpost = new Outpost(this, token);
if ((System.currentTimeMillis() - token.TimeSpawned) > Outpost.MAX_LIFETIME)
{
System.out.println("[OUTPOSTS] SKIPPING & REMOVING OUTPOST [" + token.UniqueId + "] BECAUSE OF OLD AGE");
_repository.deleteOutpost(token.UniqueId);
outpost.kill();
return;
}
System.out.println("[OUTPOSTS] INITIALIZED OUTPOST FROM DATABASE SAVE");
_outposts.put(token.OwnerClan.getName(), outpost);
});
if (post != null)
post.run();
});
}
public void saveOutposts(Runnable post)
{
final Stack<Runnable> queue = new Stack<>();
_outposts.values().forEach(outpost -> {
final OutpostToken token = outpost.toToken();
queue.push(() -> _repository.updateOutpost(token));
});
runAsync(() -> {
while (!queue.isEmpty())
queue.pop().run();
});
runAsync(() ->
_repository.getOutpostsByServer(_clansManager.getServerId(), tokens ->
tokens.forEach(token -> {
if (!_idToOutpost.containsKey(Integer.valueOf(token.UniqueId)))
{
System.out.println("[OUTPOSTS] OUTPOST [" + token.UniqueId + "] NO LONGER EXISTS, DELETING");
_repository.deleteOutpost(token.UniqueId);
}
})
)
);
}
public OutpostRepository getRepository()
{
return _repository;
}
}

View File

@ -0,0 +1,38 @@
package mineplex.game.clans.clans.siege.outpost;
public enum OutpostState
{
/**
* this much space between them so that there is some room for any potential new states.
*/
AWAITING(10),
CONSTRUCTING(20),
LIVE(30),
DESTRUCTING(40),
DEAD(50);
private byte _id;
OutpostState(int id)
{
_id = (byte) id;
}
public static OutpostState ById(byte id)
{
for (OutpostState state : values())
{
if (state._id == id)
{
return state;
}
}
return null;
}
public byte getId()
{
return _id;
}
}

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.outpost;
package mineplex.game.clans.clans.siege.outpost;
import java.io.File;
import java.io.FileInputStream;
@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -13,11 +14,13 @@ import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock;
import mineplex.game.clans.clans.siege.outpost.build.OutpostBlockBanner;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
public enum OutpostType
{
ORIGINAL_CLANS(3, 6) {
MK_I(1, 3, 6) {
public LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans)
{
LinkedHashMap<String, OutpostBlock> build = new LinkedHashMap<>();
@ -228,7 +231,7 @@ public enum OutpostType
return location.clone().subtract(0, 1, 0);
}
},
MK2(5, 25) {
MK_II(2, 5, 25) {
public LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans)
{
try
@ -236,7 +239,6 @@ public enum OutpostType
LinkedHashMap<String, OutpostBlock> build = new LinkedHashMap<>();
File file = new File("schematic" + File.separator + "outpost_mk_II.schematic");
System.out.println(file.getAbsolutePath());
Schematic schematic = UtilSchematic.loadSchematic(file);
for (int y = 0; y < schematic.getHeight(); y++)
@ -284,6 +286,71 @@ public enum OutpostType
return list;
}
public Location getCoreLocation(Location location)
{
return location.clone().subtract(0, 1, 0);
}
},
MK_III(3, 5, 25) {
public LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans)
{
try
{
LinkedHashMap<String, OutpostBlock> build = new LinkedHashMap<>();
File file = new File("schematic" + File.separator + "outpost_mk_III.schematic");
Schematic schematic = UtilSchematic.loadSchematic(file);
for (int y = 0; y < schematic.getHeight(); y++)
{
for (int x = 0; x < schematic.getWidth(); x++)
{
for (int z = 0; z < schematic.getLength(); z++)
{
int relativeX = -(schematic.getWidth() / 2) + x;
int relativeZ = -(schematic.getLength() / 2) + z;
Location loc = location.clone().add(relativeX, y - 1, relativeZ);
if (schematic.getBlock(x, y, z) == 0 && loc.getBlock().getType() == Material.AIR)
{
continue;
}
if (Material.getMaterial(schematic.getBlock(x, y, z)).name().contains("BANNER"))
{
build.put(UtilWorld.locToStr(loc), new OutpostBlockBanner(build, loc, schematic.getBlock(x, y, z), schematic.getData(x, y, z), DyeColor.RED));
}
else
build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, schematic.getBlock(x, y, z), schematic.getData(x, y, z)));
}
}
}
//Core
build.put(UtilWorld.locToStr(getCoreLocation(location)), new OutpostBlock(build, getCoreLocation(location), Material.DIAMOND_BLOCK.getId(), (byte)0));
return build;
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
public List<Location> getWallLocations(Location middle)
{
List<Location> list = new ArrayList<>();
list.add(middle.clone().add(_size / 2, 0, 0).add(1, 0, 0));
list.add(middle.clone().add(_size / 2, 0, -(_size / 2)).add(1, 0, -1));
list.add(middle.clone().add(-(_size / 2), 0, -(_size / 2)).add(-1, 0, -1));
list.add(middle.clone().add(-(_size / 2), 0, 0).add(-1, 0, 0));
return list;
}
public Location getCoreLocation(Location location)
{
return location.clone().subtract(0, 1, 0);
@ -293,10 +360,18 @@ public enum OutpostType
protected int _size;
protected int _ySize;
OutpostType(int size, int ySize)
private int _id;
OutpostType(int id, int size, int ySize)
{
_size = size;
_ySize = ySize;
_id = id;
}
public int getId()
{
return _id;
}
public abstract LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans);
@ -304,4 +379,17 @@ public enum OutpostType
public abstract Location getCoreLocation(Location location);
public abstract List<Location> getWallLocations(Location location);
public static OutpostType ById(byte id)
{
for (OutpostType type : values())
{
if (type._id == id)
{
return type;
}
}
return null;
}
}

View File

@ -0,0 +1,82 @@
package mineplex.game.clans.clans.siege.outpost.build;
import java.util.Map;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import mineplex.core.common.util.UtilWorld;
public class OutpostBlock
{
private Location _location;
private int _id;
private byte _data;
private int _originalId;
private byte _originalData;
public OutpostBlock(Map<String, OutpostBlock> blocks, Location loc, int id, byte data)
{
_location = loc;
_id = id;
_data = data;
String locStr = UtilWorld.locToStr(loc);
if (blocks.containsKey(locStr))
{
_originalId = blocks.get(locStr)._originalId;
_originalData = blocks.get(locStr)._originalData;
}
else
{
_originalId = _location.getBlock().getTypeId();
_originalData = _location.getBlock().getData();
}
}
public void set()
{
_location.getBlock().setTypeIdAndData(_id, _data, false);
if (_id != 0)
{
_location.getWorld().playEffect(_location, Effect.STEP_SOUND, Material.getMaterial(_id), 10);
}
}
public void restore()
{
BlockState state = _location.getBlock().getState();
state.setTypeId(_originalId);
state.setRawData(_originalData);
state.update(true, false);
}
public int getId()
{
return _id;
}
public byte getData()
{
return _data;
}
public int getOriginalId()
{
return _originalId;
}
public int getOriginalData()
{
return _originalData;
}
public Location getLocation()
{
return _location;
}
}

View File

@ -0,0 +1,40 @@
package mineplex.game.clans.clans.siege.outpost.build;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.block.Banner;
import org.bukkit.block.banner.Pattern;
/**
* Special block for Mk III Outpost
*
*/
public class OutpostBlockBanner extends OutpostBlock
{
private DyeColor _baseColor;
private List<Pattern> _patterns;
public OutpostBlockBanner(Map<String, OutpostBlock> blocks, Location loc, int id, byte data, DyeColor color, Pattern... patterns)
{
super(blocks, loc, id, data);
_baseColor = color;
_patterns = new ArrayList<>(Arrays.asList(patterns));
}
@Override
public void set()
{
super.set();
Banner banner = (Banner) getLocation().getBlock().getState();
banner.setBaseColor(_baseColor);
banner.setPatterns(_patterns);
banner.update(true, false);
}
}

View File

@ -0,0 +1,140 @@
package mineplex.game.clans.clans.siege.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Lists;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.outpost.OutpostState;
import mineplex.game.clans.clans.siege.outpost.OutpostType;
import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnByte;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnTimestamp;
import mineplex.serverdata.database.column.ColumnVarChar;
public class OutpostRepository extends RepositoryBase
{
private OutpostManager _manager;
private static final String CREATE = "CREATE TABLE IF NOT EXISTS clansOutposts (uniqueId INT NOT NULL,"
+ "serverId INT NOT NULL,"
+ "origin VARCHAR(30),"
+ "outpostType TINYINT NOT NULL,"
+ "ownerClan INT NOT NULL,"
+ "timeSpawned LONG,"
+ "outpostState TINYINT NOT NULL);";
private static final String GET_OUTPOST_BY_ID = "SELECT * FROM clansOutposts WHERE uniqueId=?;";
private static final String GET_OUTPOST_BY_CLAN = "SELECT * FROM clansOutposts WHERE ownerClan=?;";
private static final String GET_OUTPOSTS_BY_SERVER = "SELECT * FROM clansOutposts WHERE serverId=?;";
private static final String UPDATE_OUTPOST = "UPDATE clansOutposts SET outpostState=? WHERE uniqueId=?;";
private static final String INSERT_OUTPOST = "INSERT INTO clansOutposts VALUES (?, ?, ?, ?, ?, ?, ?);";
private static final String DELETE_OUTPOST = "DELETE FROM clansOutposts WHERE uniqueId=?;";
public OutpostRepository(JavaPlugin plugin, OutpostManager manager)
{
super(DBPool.getAccount());
_manager = manager;
}
public void deleteOutpost(final int uniqueId)
{
executeUpdate(DELETE_OUTPOST, new ColumnInt("uniqueId", uniqueId));
}
public void getOutpostById(final int uniqueId, final Callback<OutpostToken> callback)
{
executeQuery(GET_OUTPOST_BY_ID, resultSet -> {
OutpostToken token = new OutpostToken();
resultSet.next();
load(token, resultSet);
callback.run(token);
}, new ColumnInt("uniqueId", uniqueId));
}
public void getOutpostByClan(final ClanInfo clan, final Callback<OutpostToken> callback)
{
executeQuery(GET_OUTPOST_BY_CLAN, resultSet -> {
resultSet.next();
OutpostToken token = new OutpostToken();
load(token, resultSet);
callback.run(token);
}, new ColumnInt("ownerClan", clan.getId()));
}
public void getOutpostsByServer(final int serverId, final Callback<List<OutpostToken>> callback)
{
executeQuery(GET_OUTPOSTS_BY_SERVER, resultSet -> {
List<OutpostToken> tokens = Lists.newArrayList();
while (resultSet.next())
{
OutpostToken token = new OutpostToken();
load(token, resultSet);
tokens.add(token);
}
callback.run(tokens);
}, new ColumnInt("serverId", serverId));
}
private void load(OutpostToken token, ResultSet columns) throws SQLException
{
token.UniqueId = columns.getInt("uniqueId");
token.Origin = UtilWorld.strToLoc(columns.getString("origin"));
token.Type = OutpostType.ById(columns.getByte("outpostType"));
token.OwnerClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan"));
token.TimeSpawned = columns.getTimestamp("timeSpawned").getTime();
token.OutpostState = OutpostState.ById(columns.getByte("outpostState"));
}
@Override
protected void initialize()
{
executeUpdate(CREATE);
}
@Override
protected void update()
{
}
public void updateOutpost(OutpostToken token)
{
executeUpdate(UPDATE_OUTPOST,
new ColumnByte("outpostState", Byte.valueOf(token.OutpostState.getId())),
new ColumnInt("uniqueId", token.UniqueId));
}
public void insertOutpost(OutpostToken token)
{
executeUpdate(INSERT_OUTPOST,
new ColumnInt("uniqueId", token.UniqueId),
new ColumnInt("serverId", _manager.getClansManager().getServerId()),
new ColumnVarChar("origin", 30, UtilWorld.locToStr(token.Origin)),
new ColumnInt("outpostType", token.Type.getId()),
new ColumnInt("ownerClan", token.OwnerClan.getId()),
new ColumnTimestamp("timeSpawned", new Timestamp(token.TimeSpawned)),
new ColumnByte("outpostState", Byte.valueOf(token.OutpostState.getId())));
}
}

View File

@ -0,0 +1,149 @@
package mineplex.game.clans.clans.siege.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Lists;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnTimestamp;
import mineplex.serverdata.database.column.ColumnVarChar;
public class SiegeWeaponRepository extends RepositoryBase
{
private SiegeManager _manager;
private static final String CREATE = "CREATE TABLE IF NOT EXISTS clansSiegeWeapons (uniqueId INT NOT NULL,"
+ "serverId INT NOT NULL,"
+ "location VARCHAR(30),"
+ "ownerClan INT NOT NULL,"
+ "weaponType TINYINT NOT NULL,"
+ "health INT NOT NULL,"
+ "yaw INT NOT NULL,"
+ "lastFired LONG);";
private static final String GET_WEAPON_BY_ID = "SELECT * FROM clansSiegeWeapons WHERE uniqueId=?;";
private static final String GET_WEAPONS_BY_CLAN = "SELECT * FROM clansSiegeWeapons WHERE ownerClan=?;";
private static final String GET_WEAPONS_BY_SERVER = "SELECT * FROM clansSiegeWeapons WHERE serverId=?;";
private static final String UPDATE_WEAPON = "UPDATE clansSiegeWeapons SET health=?,yaw=?,lastFired=? WHERE uniqueId=?;";
private static final String INSERT_WEAPON = "INSERT INTO clansSiegeWeapons VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
private static final String DELETE_WEAPON = "DELETE FROM clansSiegeWeapons WHERE uniqueId=?;";
public SiegeWeaponRepository(JavaPlugin plugin, SiegeManager manager)
{
super(DBPool.getAccount());
_manager = manager;
}
public void deleteWeapon(final int uniqueId)
{
executeUpdate(DELETE_WEAPON, new ColumnInt("uniqueId", uniqueId));
}
public void getWeaponById(final int uniqueId, final Callback<SiegeWeaponToken> callback)
{
executeQuery(GET_WEAPON_BY_ID, resultSet -> {
SiegeWeaponToken token = new SiegeWeaponToken();
resultSet.next();
load(token, resultSet);
callback.run(token);
}, new ColumnInt("uniqueId", uniqueId));
}
public void getWeaponsByServer(final int serverId, final Callback<List<SiegeWeaponToken>> callback)
{
executeQuery(GET_WEAPONS_BY_SERVER, resultSet -> {
List<SiegeWeaponToken> tokens = Lists.newArrayList();
while (resultSet.next())
{
SiegeWeaponToken token = new SiegeWeaponToken();
load(token, resultSet);
tokens.add(token);
}
callback.run(tokens);
}, new ColumnInt("serverId", serverId));
}
public void getWeaponsByClan(final ClanInfo clan, final Callback<List<SiegeWeaponToken>> callback)
{
executeQuery(GET_WEAPONS_BY_CLAN, resultSet -> {
List<SiegeWeaponToken> tokens = Lists.newArrayList();
while (resultSet.next())
{
SiegeWeaponToken token = new SiegeWeaponToken();
load(token, resultSet);
tokens.add(token);
}
callback.run(tokens);
}, new ColumnInt("ownerClan", clan.getId()));
}
private void load(SiegeWeaponToken token, ResultSet columns) throws SQLException
{
token.UniqueId = columns.getInt("uniqueId");
token.Location = UtilWorld.strToLoc(columns.getString("location"));
token.OwnerClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan"));
token.WeaponType = columns.getByte("weaponType");
token.Health = columns.getShort("health");
token.Yaw = columns.getShort("yaw");
token.LastFired = columns.getTimestamp("lastFired").getTime();
}
public void updateWeapon(SiegeWeaponToken token)
{
executeUpdate(UPDATE_WEAPON,
new ColumnInt("health", token.Health),
new ColumnInt("yaw", token.Yaw),
new ColumnTimestamp("lastFired", new Timestamp(token.LastFired)),
new ColumnInt("uniqueId", token.UniqueId));
}
public void insertWeapon(SiegeWeaponToken token)
{
executeUpdate(INSERT_WEAPON,
new ColumnInt("uniqueId", token.UniqueId),
new ColumnInt("serverId", _manager.getClansManager().getServerId()),
new ColumnVarChar("location", 30, UtilWorld.locToStr(token.Location)),
new ColumnInt("ownerClan", token.OwnerClan.getId()),
new ColumnInt("weaponType", token.WeaponType),
new ColumnInt("health", token.Health),
new ColumnInt("yaw", token.Yaw),
new ColumnTimestamp("lastFired", new Timestamp(token.LastFired)));
}
@Override
protected void initialize()
{
executeUpdate(CREATE);
}
@Override
protected void update()
{
}
}

View File

@ -0,0 +1,17 @@
package mineplex.game.clans.clans.siege.repository.tokens;
import org.bukkit.Location;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.outpost.OutpostState;
import mineplex.game.clans.clans.siege.outpost.OutpostType;
public class OutpostToken
{
public int UniqueId;
public Location Origin;
public OutpostType Type;
public ClanInfo OwnerClan;
public long TimeSpawned;
public OutpostState OutpostState;
}

View File

@ -0,0 +1,16 @@
package mineplex.game.clans.clans.siege.repository.tokens;
import org.bukkit.Location;
import mineplex.game.clans.clans.ClanInfo;
public class SiegeWeaponToken
{
public int UniqueId;
public ClanInfo OwnerClan;
public byte WeaponType;
public Location Location;
public int Health;
public int Yaw;
public long LastFired;
}

View File

@ -0,0 +1,377 @@
package mineplex.game.clans.clans.siege.weapon;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import com.google.common.collect.Lists;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
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.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
import mineplex.game.clans.clans.siege.weapon.util.AccessType;
import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo;
public class Cannon extends SiegeWeapon
{
public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build();
private int _firepower = 1;
public Cannon(SiegeManager siegeManager, SiegeWeaponToken token)
{
super(1400, "Cannon", token, siegeManager.getClansManager(), siegeManager);
setBoundingBox(1);
setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1));
setStateInfo("Loaded", new WeaponStateInfo(Material.SPONGE, (byte) 0));
setAmmunitionType(Material.TNT);
setAmmunitionSlot(4);
setMaximumAmmunitionPerSlot(1);
_baseDamage = 650;
setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(2.d));
setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> {
if (!isRiding(player))
{
return false;
}
if (!_ownerClan.isMember(player))
{
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
return false;
}
if (!canBeFired())
{
UtilPlayer.message(player, F.main("Clans", "Cannon is not loaded correctly."));
return false;
}
if (System.currentTimeMillis() - _lastFired < 20000)
{
UtilPlayer.message(player, F.main("Clans", "Cannon is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")"));
return false;
}
return true;
}));
enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider())));
setRideable(new AccessRule(AccessType.RCLICK_BB, player -> {
if (!_ownerClan.isMember(player))
{
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
return false;
}
if (getRider() != null && !getRider().equals(player))
{
UtilPlayer.message(player, F.main("Clans", "Someone is already riding this cannon."));
return false;
}
return !player.equals(getRider());
}));
}
public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager)
{
super(2, location, 1400, "Cannon", clan, clan.Clans, siegeManager);
setBoundingBox(1);
setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1));
setStateInfo("Loaded", new WeaponStateInfo(Material.SPONGE, (byte) 0));
loadEntities();
setFirepowerType(Material.SULPHUR);
setAmmunitionType(Material.TNT);
setFirepowerSlots(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7));
setMaximumFirepowerPerSlot(3);
setAmmunitionSlot(4);
setMaximumAmmunitionPerSlot(1);
_baseDamage = 650;
setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(2.d));
setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> {
if (!isRiding(player))
{
return false;
}
if (!_ownerClan.isMember(player))
{
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
return false;
}
if (!canBeFired())
{
UtilPlayer.message(player, F.main("Clans", "Cannon is not loaded correctly."));
return false;
}
if (System.currentTimeMillis() - _lastFired < 20000)
{
UtilPlayer.message(player, F.main("Clans", "Cannon is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")"));
return false;
}
return true;
}));
enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider())));
setRideable(new AccessRule(AccessType.RCLICK_BB, player -> {
if (!_ownerClan.isMember(player))
{
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
return false;
}
if (getRider() != null && !getRider().equals(player))
{
UtilPlayer.message(player, F.main("Clans", "Someone is already riding this cannon."));
return false;
}
return !player.equals(getRider());
}));
}
@EventHandler
protected void InventoryClick(InventoryClickEvent event)
{
if (!event.getClickedInventory().equals(_inventory))
{
return;
}
if (event.getSlot() == 0)
{
int oldFirepower = _firepower;
_firepower = UtilMath.clamp(--_firepower, 1, 3);
if (oldFirepower != _firepower)
{
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f);
}
else
{
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f);
}
event.setCancelled(true);
}
else if (event.getSlot() == 1)
{
event.setCancelled(true);
}
else if (event.getSlot() == 2)
{
int oldFirepower = _firepower;
_firepower = UtilMath.clamp(++_firepower, 1, 3);
if (oldFirepower != _firepower)
{
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f);
}
else
{
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f);
}
event.setCancelled(true);
}
}
private void updateInventory()
{
_inventory.setItem(0, new ItemBuilder(Material.LEVER).setTitle(C.cRed + "-1 Firepower").build());
_inventory.setItem(1, new ItemBuilder(Material.SULPHUR).setTitle(C.cWhiteB + "Firepower: " + C.cYellow + _firepower).build());
_inventory.setItem(2, new ItemBuilder(Material.LEVER).setTitle(C.cGreen + "+1 Firepower").build());
}
protected boolean CustomInventoryValid(int slot, ItemStack item)
{
return slot == 0 || slot == 1 || slot == 2;
}
protected void ResetEntities()
{
removeEntity("Filler_1");
removeEntity("PLAYERMOUNT");
removeEntity("WEAPON");
loadEntities();
getEntity("PLAYERMOUNT").setPassenger(_rider);
}
private void loadEntities()
{
Slime filler = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), Slime.class);
UtilEnt.silence(filler, true);
UtilEnt.Vegetate(filler);
filler.setSize(-1);
filler.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
addEntity(filler, "Filler_1");
Slime playerMount = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), Slime.class);
UtilEnt.silence(playerMount, true);
UtilEnt.Vegetate(playerMount);
playerMount.setSize(-1);
playerMount.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
getEntity("Filler_1").setPassenger(playerMount);
addEntity(playerMount, "PLAYERMOUNT");
ArmorStand weapon = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), ArmorStand.class);
UtilEnt.setFakeHead(weapon, true);
weapon.teleport(_location);
weapon.setVisible(false);
weapon.setGravity(false);
weapon.setPassenger(getEntity("Filler_1"));
addEntity(weapon, "WEAPON");
weapon.setMetadata("WeaponId", new FixedMetadataValue(_siegeManager.getPlugin(), Integer.valueOf(_uniqueId)));
}
@Override
public void FindEntities()
{
Lists.newArrayList(_location.getChunk().getEntities())
.stream()
.filter(entity -> entity.getType().equals(EntityType.ARMOR_STAND))
.filter(entity -> entity.hasMetadata("WeaponId"))
.filter(entity -> entity.getMetadata("WeaponId").get(0).asInt() == _uniqueId)
.filter(entity -> entity.getPassenger() != null)
.filter(entity -> entity.getPassenger().getPassenger() != null)
.limit(1l)
.forEach(entity -> {
addEntity(entity, "WEAPON");
addEntity(entity.getPassenger(), "Filler_1");
addEntity(entity.getPassenger().getPassenger(), "PLAYERMOUNT");
});
if (getEntity("WEAPON") == null || getEntity("Filler_1") == null || getEntity("PLAYERMOUNT") == null)
{
kill();
}
}
@Override
public void CustomFire(WeaponProjectile projectile)
{
projectile.setLocation(projectile.getLocation().add(.0, .2, .0));
UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX);
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f));
}
@Override
public String GetNextState()
{
if (getAmmunition() > 0)
{
return "Loaded";
}
return "Unloaded";
}
protected int getPowerLevel()
{
return _firepower;
}
@Override
protected void CustomTick()
{
updateInventory();
if (getProjectile() != null)
{
UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX);
}
}
@Override
protected double[] GetProjectileVelocity()
{
int firepower = getPowerLevel();
double hMult = 0;
double yAdd = 0;
if (firepower == 1)
{
hMult = 1.2;
yAdd = 0.5;
}
else if (firepower == 2)
{
hMult = 1.7;
yAdd = 0.55;
}
else if (firepower >= 3)
{
hMult = 2.35;
yAdd = 0.6;
}
return new double[] { yAdd, hMult };
}
}

View File

@ -0,0 +1,311 @@
package mineplex.game.clans.clans.siege.weapon;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Slime;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import com.google.common.collect.Lists;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt;
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.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
import mineplex.game.clans.clans.siege.weapon.util.AccessType;
import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo;
public class Catapult extends SiegeWeapon
{
// public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build();
public Catapult(SiegeManager siegeManager, SiegeWeaponToken token)
{
super(1400, "Catapult", token, siegeManager.getClansManager(), siegeManager);
setBoundingBox(3, 0);
setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0));
setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0));
setStateInfo("Fired", new WeaponStateInfo(Material.LAPIS_BLOCK, (byte) 0));
setFirepowerType(Material.FIREBALL);
setAmmunitionType(Material.COBBLESTONE);
setFirepowerSlots(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7));
setMaximumFirepowerPerSlot(3);
setAmmunitionSlot(4);
setMaximumAmmunitionPerSlot(1);
setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d));
_invertRotation = true;
_baseDamage = 550;
_rotSpeed = 60.0f;
setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> {
if (!isRiding(player))
{
return false;
}
if (!_ownerClan.isMember(player))
{
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false;
}
if (!canBeFired())
{
UtilPlayer.message(player, F.main("Clans", "Catapult is not loaded correctly."));
return false;
}
if (System.currentTimeMillis() - _lastFired < 20000)
{
UtilPlayer.message(player, F.main("Clans", "Catapult is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")"));
return false;
}
return true;
}));
enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider())));
setRideable(new AccessRule(AccessType.RCLICK_BB, player -> {
if (!_ownerClan.isMember(player))
{
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false;
}
if (getRider() != null && !getRider().equals(player))
{
UtilPlayer.message(player, F.main("Clans", "Someone is already riding this Catapult."));
return false;
}
return !player.equals(getRider());
}));
}
public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager)
{
super(1, location, 2500, "Catapult", clan, clan.Clans, siegeManager);
setBoundingBox(3, 0);
setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0));
setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0));
setStateInfo("Fired", new WeaponStateInfo(Material.LAPIS_BLOCK, (byte) 0));
loadEntities();
setFirepowerType(Material.FIREBALL);
setAmmunitionType(Material.COBBLESTONE);
setFirepowerSlots(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7));
setMaximumFirepowerPerSlot(3);
setAmmunitionSlot(4);
setMaximumAmmunitionPerSlot(1);
setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d));
_baseDamage = 550;
_rotSpeed = 60.0f;
setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> {
if (!isRiding(player))
{
return false;
}
if (!_ownerClan.isMember(player))
{
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false;
}
if (!canBeFired())
{
UtilPlayer.message(player, F.main("Clans", "Catapult is not loaded correctly."));
return false;
}
if (System.currentTimeMillis() - _lastFired < 20000)
{
UtilPlayer.message(player, F.main("Clans", "Catapult is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")"));
return false;
}
return true;
}));
enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider())));
setRideable(new AccessRule(AccessType.RCLICK_BB, player -> {
if (!_ownerClan.isMember(player))
{
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false;
}
if (getRider() != null && !getRider().equals(player))
{
UtilPlayer.message(player, F.main("Clans", "Someone is already riding this Catapult."));
return false;
}
return !player.equals(getRider());
}));
}
private void loadEntities()
{
Slime filler = _location.getWorld().spawn(_location, Slime.class);
UtilEnt.silence(filler, true);
UtilEnt.Vegetate(filler);
filler.setSize(-1);
filler.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
addEntity(filler, "Filler_1");
Slime playerMount = _location.getWorld().spawn(_location, Slime.class);
UtilEnt.silence(playerMount, true);
UtilEnt.Vegetate(playerMount);
playerMount.setSize(-1);
playerMount.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
getEntity("Filler_1").setPassenger(playerMount);
addEntity(playerMount, "PLAYERMOUNT");
ArmorStand weapon = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), ArmorStand.class);
UtilEnt.setFakeHead(weapon, true);
weapon.teleport(_location);
weapon.setVisible(false);
weapon.setGravity(false);
weapon.setPassenger(getEntity("Filler_1"));
addEntity(weapon, "WEAPON");
weapon.setMetadata("WeaponId", new FixedMetadataValue(_siegeManager.getPlugin(), Integer.valueOf(_uniqueId)));
}
@Override
public void FindEntities()
{
Lists.newArrayList(_location.getChunk().getEntities())
.stream()
.filter(entity -> entity.getType().equals(EntityType.ARMOR_STAND))
.filter(entity -> entity.hasMetadata("WeaponId"))
.filter(entity -> entity.getMetadata("WeaponId").get(0).asInt() == _uniqueId)
.filter(entity -> entity.getPassenger() != null)
.filter(entity -> entity.getPassenger().getPassenger() != null)
.limit(1l)
.forEach(entity -> {
addEntity(entity, "WEAPON");
addEntity(entity.getPassenger(), "Filler_1");
addEntity(entity.getPassenger().getPassenger(), "PLAYERMOUNT");
});
if (getEntity("WEAPON") == null || getEntity("Filler_1") == null || getEntity("PLAYERMOUNT") == null)
{
kill();
}
}
@Override
public void CustomFire(WeaponProjectile projectile)
{
projectile.setLocation(projectile.getLocation().add(.0, 2.7, .0));
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.BAT_TAKEOFF, 2.f, .45f));
}
@Override
public String GetNextState()
{
if (System.currentTimeMillis() - _lastFired < 4500)
{
return "Fired";
}
if (getAmmunition() > 0)
{
return "Loaded";
}
return "Unloaded";
}
@Override
protected void CustomTick()
{
if (getProjectile() != null)
{
UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX);
}
}
@Override
protected double[] GetProjectileVelocity()
{
int firepower = getPowerLevel();
double hMult = 0;
double yAdd = 0;
if (firepower == 1)
{
hMult = 0.6;
yAdd = 0.8;
}
else if (firepower == 2)
{
hMult = 1;
yAdd = 1.2;
}
else if (firepower >= 3)
{
hMult = 1.5;
yAdd = 1.35;
}
return new double[] { hMult, yAdd };
}
}

View File

@ -0,0 +1,840 @@
package mineplex.game.clans.clans.siege.weapon;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;
import org.spigotmc.event.entity.EntityDismountEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautArrayList;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilCollections;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.hologram.Hologram;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
import mineplex.game.clans.clans.siege.weapon.util.AccessType;
import mineplex.game.clans.clans.siege.weapon.util.BarrierCollisionBox;
import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo;
import mineplex.game.clans.items.PlayerGear;
import mineplex.game.clans.items.legendaries.AlligatorsTooth;
import mineplex.game.clans.items.legendaries.GiantsBroadsword;
import mineplex.game.clans.items.legendaries.HyperAxe;
import mineplex.game.clans.items.legendaries.LegendaryItem;
import mineplex.game.clans.items.legendaries.MagneticMaul;
import mineplex.game.clans.items.legendaries.WindBlade;
public abstract class SiegeWeapon implements Listener
{
// Constants
protected final int _maxHealth;
protected final byte _weaponTypeIdentifier;
// Managers
protected ClansManager _clans;
protected SiegeManager _siegeManager;
// Info
protected final int _uniqueId;
protected final ClanInfo _ownerClan;
protected final Location _location;
protected final String _name;
protected int _health;
protected String _currentState;
protected boolean _alive = true;
// Mechanics
protected final NautArrayList<Entity> _comprisedOf;
protected Player _rider;
protected Inventory _inventory;
protected AccessRule _inventoryAccess;
protected BarrierCollisionBox _collisionBox;
protected AccessRule _fireAccess;
protected int _boundingBoxSize;
protected double _yaw;
protected long _lastRight = -1;
protected long _lastLeft = -1;
protected long _lastFired = -1;
// Display
protected Hologram _infoHologram;
// Utility
protected final NautHashMap<String, WeaponStateInfo> _registeredStates;
protected final NautHashMap<String, Entity> _entityMapping;
// Customizability
protected boolean _isRideable;
protected boolean _invertRotation;
protected AccessRule _mountAccess;
protected float _rotSpeed = 20.f;
protected int _ammunitionSlot;
protected Material _ammunitionType;
protected int _maxAmmunition;
protected NautArrayList<Integer> _firepowerSlots;
protected Material _firepowerType;
protected int _maxFirepowerPerSlot;
protected int _baseDamage;
protected ProjectileAttributes _projectileAttributes;
protected WeaponProjectile _projectile;
public SiegeWeapon(int maxHealth, String name, SiegeWeaponToken token, ClansManager clansManager, SiegeManager siegeManager)
{
_weaponTypeIdentifier = token.WeaponType;
_uniqueId = token.UniqueId;
_siegeManager = siegeManager;
_location = token.Location;
_name = name;
_health = _maxHealth = maxHealth;
_ownerClan = token.OwnerClan;
_comprisedOf = new NautArrayList<>();
_registeredStates = new NautHashMap<>();
_entityMapping = new NautHashMap<>();
_infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth());
_infoHologram.start();
UtilServer.RegisterEvents(this);
_clans = clansManager;
_yaw = token.Yaw;
_lastFired = token.LastFired;
_health = token.Health;
FindEntities();
}
public SiegeWeapon(int typeId, Location location, int maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager)
{
_uniqueId = siegeManager.randomId();
_weaponTypeIdentifier = (byte) typeId;
_siegeManager = siegeManager;
_location = location;
_name = name;
_health = _maxHealth = maxHealth;
_ownerClan = owner;
_comprisedOf = new NautArrayList<>();
_registeredStates = new NautHashMap<>();
_entityMapping = new NautHashMap<>();
_infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth());
_infoHologram.start();
_siegeManager.getRepository().insertWeapon(toToken());
UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin());
_clans = clansManager;
}
protected int calculateDamage(Player player)
{
ItemStack stack = player.getItemInHand();
PlayerGear gear = _clans.getGearManager().getPlayerGear(player);
if (stack == null)
return 1;
if (gear.getWeapon() != null && gear.getWeapon() instanceof LegendaryItem)
if (gear.getWeapon() instanceof AlligatorsTooth)
return 8;
else if (gear.getWeapon() instanceof GiantsBroadsword)
return 10;
else if (gear.getWeapon() instanceof HyperAxe)
return 3;
else if (gear.getWeapon() instanceof MagneticMaul)
return 8;
else if (gear.getWeapon() instanceof WindBlade)
return 7;
return (int) UtilItem.getAttackDamage(stack.getType());
}
protected void enableInventory(Inventory inventory, AccessRule accessRule)
{
_inventory = inventory;
_inventoryAccess = accessRule;
}
protected void setBoundingBox(int size)
{
Validate.isTrue(size > 0, "Size must be a positive number.");
Validate.isTrue(UtilMath.isOdd(size), "Size must be an odd number.");
_boundingBoxSize = size;
_collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .2, size - 1, ((size - 1) / 2) + .2));
_collisionBox.Construct();
_collisionBox.registerRight((block, player) -> handleRightClick(player));
_collisionBox.registerLeft((block, player) -> handleLeftClick(player));
}
protected void setBoundingBox(int size, int y)
{
Validate.isTrue(size > 0, "Size must be a positive number.");
Validate.isTrue(UtilMath.isOdd(size), "Size must be an odd number.");
_boundingBoxSize = size;
_collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .2, y, ((size - 1) / 2) + .2));
_collisionBox.Construct();
_collisionBox.registerRight((block, player) -> handleRightClick(player));
_collisionBox.registerLeft((block, player) -> handleLeftClick(player));
}
private void update()
{
if (getEntity("WEAPON") == null || getEntity("PLAYERMOUNT") == null)
{
kill();
return;
}
if (_inventory != null)
checkInventory();
_rider = (Player) getEntity("PLAYERMOUNT").getPassenger();
if (!GetNextState().equals(_currentState))
setState(GetNextState());
if (_projectile != null && _projectile.hasDied())
_projectile = null;
ArmorStand armorStand = (ArmorStand) getEntity("WEAPON");
double standYaw = _yaw % 360;
if (getRider() != null)
{
double riderYaw = (getRider().getLocation().getYaw() + (_invertRotation ? 180 : 0)) % 360;
double dif = riderYaw - standYaw;
if (dif > 180) dif -= 360;
if (dif < -180) dif += 360;
double yaw = (float) ((float)standYaw + Math.min(dif / _rotSpeed, 4f));
armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(CustomRotate(_yaw = yaw)), 0));
}
}
protected boolean canBeFired()
{
return getPowerLevel() > 0 && getAmmunition() > 0 && _projectile == null;
}
private void fire(Player player)
{
_lastFired = System.currentTimeMillis();
double[] vel = GetProjectileVelocity();
_inventory.clear();
CustomFire(_projectile = new WeaponProjectile(this, _location.clone().add(.5, 0, .5), _projectileAttributes, ((ArmorStand) getEntity("WEAPON")).getHeadPose().getY(), vel[0], vel[1]));
}
protected void setFireRule(AccessRule rule)
{
_fireAccess = rule;
}
protected void setFirepowerType(Material type)
{
_firepowerType = type;
}
protected void setAmmunitionType(Material type)
{
_ammunitionType = type;
}
protected void setFirepowerSlots(Integer... slots)
{
_firepowerSlots = UtilCollections.newNautList(slots);
}
protected void setMaximumFirepowerPerSlot(int maxFirepowerPerSlot)
{
_maxFirepowerPerSlot = maxFirepowerPerSlot;
}
protected void setAmmunitionSlot(int ammunitionSlot)
{
_ammunitionSlot = ammunitionSlot;
}
protected void setMaximumAmmunitionPerSlot(int maxAmmunition)
{
_maxAmmunition = maxAmmunition;
}
protected void setProjectileAttributes(ProjectileAttributes projectileAttributes)
{
_projectileAttributes = projectileAttributes;
}
protected boolean isRiding(Player player)
{
return player.equals(getRider());
}
protected void setRideable(AccessRule accessRule)
{
_isRideable = true;
_mountAccess = accessRule;
}
public void kill()
{
CustomCleanup();
_comprisedOf.forEach(Entity::remove);
_entityMapping.clear();
_comprisedOf.clear();
_infoHologram.stop();
_siegeManager.dead(this);
_alive = false;
HandlerList.unregisterAll(this);
}
private void handleMount(Player player)
{
if (!CustomMount(player))
{
getEntity("PLAYERMOUNT").setPassenger(player);
}
CustomOnMount(player);
}
private void handleInventoryOpen(Player player)
{
player.openInventory(_inventory);
}
private void handleRightClick(Player player)
{
if (_lastRight == -1)
{
_lastRight = System.currentTimeMillis();
}
else
{
if (System.currentTimeMillis() - _lastRight <= 40)
{
return;
}
}
_lastRight = System.currentTimeMillis();
CustomRightClick(player);
if (_isRideable && _mountAccess.allow(AccessType.RCLICK_BB, player))
{
handleMount(player);
return;
}
if (_inventory != null && _inventoryAccess.allow(AccessType.RCLICK_BB, player))
{
handleInventoryOpen(player);
return;
}
if (_fireAccess.allow(AccessType.RCLICK_BB, player))
{
fire(player);
}
}
protected boolean CustomInventoryValid(int slot, ItemStack item)
{
return false;
}
private void dismount(Player player)
{
player.teleport(player.getLocation().add(0, 1, 0));
}
private void handleLeftClick(Player player)
{
if (_lastLeft == -1)
{
_lastLeft = System.currentTimeMillis();
}
else
{
if (System.currentTimeMillis() - _lastLeft <= 40)
{
return;
}
}
_lastLeft = System.currentTimeMillis();
CustomLeftClick(player);
if (_isRideable && _mountAccess.allow(AccessType.LCLICK_BB, player))
{
handleMount(player);
return;
}
if (_inventory != null && _inventoryAccess.allow(AccessType.LCLICK_BB, player))
{
handleInventoryOpen(player);
return;
}
if (_fireAccess.allow(AccessType.LCLICK_BB, player))
{
fire(player);
return;
}
if (!_ownerClan.isMember(player))
{
int health = calculateDamage(player);
removeHealth(health);
UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 0, 10, 0, player);
}
}
protected abstract double[] GetProjectileVelocity();
protected abstract String GetNextState();
protected abstract void FindEntities();
protected void ResetEntities() { return; }
protected void CustomTick() { return; }
protected void CustomOnMount(Player player) { return; }
protected void CustomLeftClick(Player player) { return; }
protected void CustomRightClick(Player player) { return; }
protected void CustomCleanup() { return; }
protected void CustomUpdateState(String state) { return; }
protected void CustomFire(WeaponProjectile projectile) { return; }
protected double CustomRotate(double yaw) { return yaw; }
protected boolean CustomDismount(Player player, Entity entity) { return false; }
protected boolean CustomMount(Player player) { return false; }
protected final void addEntity(Entity entity, String uniqueName)
{
_comprisedOf.add(entity);
_entityMapping.put(uniqueName, entity);
}
protected final void removeEntity(String uniqueName)
{
Entity entity = _entityMapping.get(uniqueName);
_entityMapping.remove(uniqueName);
_comprisedOf.remove(entity);
entity.remove();
}
protected final Entity getEntity(String uniqueName)
{
return _entityMapping.get(uniqueName);
}
public final int getHealth()
{
return _health;
}
public final String getDisplayHealth()
{
return UtilText.getProgress(null, ((double) _health) / ((double) _maxHealth), null, false, 12);
}
public final void setHealth(int health)
{
_health = UtilMath.clamp(health, 0, _maxHealth);
_infoHologram.setText(_name + " Health", getDisplayHealth());
if (_health == 0)
kill();
}
public final void removeHealth(int health)
{
setHealth(_health - health);
}
public final void addHealth(int health)
{
setHealth(_health + health);
}
public final void setState(String state)
{
Validate.isTrue(_registeredStates.containsKey(state), "Provided state has not yet been registered.");
((ArmorStand) getEntity("WEAPON")).setHelmet(new ItemStack(_registeredStates.get(state).getType(), 1, (short) 0, (byte) _registeredStates.get(state).getData()));
CustomUpdateState(_currentState = state);
}
public final void setStateInfo(String state, WeaponStateInfo info)
{
_registeredStates.put(state, info);
}
public final WeaponStateInfo getStateInfo(String state)
{
if (!_registeredStates.containsKey(state))
_registeredStates.put(state, new WeaponStateInfo(Material.STONE, (byte) 101));
return _registeredStates.get(state);
}
public void checkInventory()
{
for (int slot = 0; slot < _inventory.getSize(); slot++)
{
ItemStack item = _inventory.getItem(slot);
if (item == null)
continue;
if (slot == _ammunitionSlot)
{
if (item.getType() != _ammunitionType)
{
if (CustomInventoryValid(slot, item))
continue;
if (getRider() != null)
getRider().getInventory().addItem(item);
else
_location.getWorld().dropItem(_location, item);
_inventory.setItem(slot, null);
}
else
{
if (item.getAmount() > _maxAmmunition)
{
if (getRider() != null)
getRider().getInventory().addItem(new ItemStack(_ammunitionType, item.getAmount() - _maxAmmunition));
else
_location.getWorld().dropItem(_location, item);
_inventory.setItem(slot, new ItemStack(_ammunitionType, _maxAmmunition));
}
}
}
else if (_firepowerSlots.contains(Integer.valueOf(slot)))
{
if (item.getType() != _firepowerType)
{
if (CustomInventoryValid(slot, item))
continue;
if (getRider() != null)
getRider().getInventory().addItem(item);
else
_location.getWorld().dropItem(_location, item);
_inventory.setItem(slot, null);
}
else
{
if (item.getAmount() > _maxFirepowerPerSlot)
{
if (getRider() != null)
getRider().getInventory().addItem(new ItemStack(_firepowerType, item.getAmount() - _maxFirepowerPerSlot));
else
_location.getWorld().dropItem(_location, item);
_inventory.setItem(slot, new ItemStack(_firepowerType, _maxFirepowerPerSlot));
}
}
}
else
{
if (CustomInventoryValid(slot, item))
continue;
if (getRider() != null)
getRider().getInventory().addItem(item);
else
_location.getWorld().dropItem(_location, item);
_inventory.setItem(slot, null);
}
}
}
@EventHandler
public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event)
{
if (UtilAlg.inBoundingBox(event.getProjectile().getLocation(), _location.clone().subtract(3, 2, 3), _location.clone().add(3, 2, 3)))
{
kill();
_ownerClan.inform("One of your Cannons has been destroyed!", null);
UtilTextMiddle.display("Damage", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".", 10, 60, 10, event.getWeapon().getRider());
UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + "."));
}
}
@EventHandler
public void onDamage(EntityDamageEvent event)
{
if (_comprisedOf.contains(event.getEntity()))
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onDmg(EntityDamageByEntityEvent event)
{
if (!_comprisedOf.contains(event.getEntity()) && event.getDamager() instanceof Player)
handleLeftClick((Player) event.getDamager());
}
@EventHandler
public void onCloseInv(InventoryCloseEvent event)
{
if (!event.getInventory().equals(_inventory))
return;
ClansManager.getInstance().runSyncLater(() -> {
if (!event.getPlayer().getInventory().equals(_inventory) && canBeFired())
UtilTextMiddle.display(_name + " Ready", "Power Level: " + C.cGreen + UtilText.repeat("", getPowerLevel()) + C.cRed + UtilText.repeat("", _maxFirepowerPerSlot - getPowerLevel()), 20, 100, 20, (Player) event.getPlayer());
}, 3L);
}
@EventHandler
public void onDismount(EntityDismountEvent event)
{
if (event.getEntity() instanceof Player && (event.getDismounted().equals(getEntity("PLAYERMOUNT")) || CustomDismount((Player) event.getEntity(), event.getDismounted())))
dismount((Player) event.getEntity());
}
@EventHandler
public void onInteract(PlayerInteractAtEntityEvent event)
{
if (_comprisedOf.contains(event.getRightClicked()))
{
handleRightClick(event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler
public void onInteract(PlayerInteractEntityEvent event)
{
if (_comprisedOf.contains(event.getRightClicked()))
{
handleRightClick(event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{
if (event.getBlock().getLocation().distance(_location) < _boundingBoxSize + 1.65 && event.getBlock().getLocation().getY() <= _location.getY())
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks near a Siege Weapon"));
event.setCancelled(true);
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
if (event.getBlock().getLocation().distance(_location) < _boundingBoxSize + 1.65 && event.getBlock().getLocation().getY() <= _location.getY())
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place blocks near a Siege Weapon"));
event.setCancelled(true);
}
}
public boolean inProtection(Block block)
{
return block.getLocation().distance(_location) < _boundingBoxSize + 1.65 && block.getLocation().getY() <= _location.getY() + 2;
}
@EventHandler
public void onInteract(PlayerArmorStandManipulateEvent event)
{
if (_comprisedOf.contains(event.getRightClicked()))
{
handleRightClick(event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler
public void chunkUnload(ChunkUnloadEvent event)
{
if (_comprisedOf.stream().anyMatch(entity -> entity.getLocation().getChunk().equals(event.getChunk())))
event.setCancelled(true);
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
update();
CustomTick();
}
public Location getLocation()
{
return _location;
}
public double getSize()
{
return _boundingBoxSize;
}
public int getBaseDamage()
{
return _baseDamage;
}
public ClanInfo getOwner()
{
return _ownerClan;
}
public ClansManager getClans()
{
return _clans;
}
protected WeaponProjectile getProjectile()
{
return _projectile;
}
protected int getAmmunition()
{
ItemStack item = _inventory.getItem(_ammunitionSlot);
if (item != null && item.getType().equals(_ammunitionType))
return item.getAmount();
return 0;
}
protected int getPowerLevel()
{
int power = 0;
for (int slot : _firepowerSlots)
{
ItemStack item = _inventory.getItem(slot);
if (item == null || !item.getType().equals(_firepowerType))
continue;
power += _inventory.getItem(slot).getAmount();
}
return power / 4;
}
public int getUniqueId()
{
return _uniqueId;
}
public Player getRider()
{
return _rider;
}
public final String getState()
{
return _currentState;
}
public SiegeWeaponToken toToken()
{
SiegeWeaponToken token = new SiegeWeaponToken();
token.UniqueId = _uniqueId;
token.OwnerClan = _ownerClan;
token.WeaponType = _weaponTypeIdentifier;
token.Location = _location;
token.Health = _health;
token.Yaw = (int) _yaw;
return token;
}
}

View File

@ -0,0 +1,206 @@
package mineplex.game.clans.clans.siege.weapon.projectile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilItem;
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.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
import mineplex.game.clans.core.repository.ClanTerritory;
public class Crater implements Listener
{
public static final Material CHARRED_TYPE = Material.OBSIDIAN;
private final SiegeWeapon _weapon;
private final Location _origin;
private final long _birthTime;
private final int _size;
private final double _airChance;
private final boolean _fire;
private final List<CraterBlock> _blocks;
public Crater(SiegeWeapon weapon, WeaponProjectile projectile, Location origin, int size, double airChance, boolean doFire)
{
_weapon = weapon;
_origin = origin;
_birthTime = System.currentTimeMillis();
_blocks = new ArrayList<>();
_size = size;
_airChance = airChance;
_fire = doFire;
UtilServer.getPluginManager().registerEvents(this, _weapon.getClans().getPlugin());
createExplosion();
}
@EventHandler
public void updateEffects(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
_blocks.stream().filter(block -> block.Type == CHARRED_TYPE).forEach(block -> {
long lifetime = System.currentTimeMillis() - _birthTime;
long max = 80000;
if (block.Location.getBlock().getType() != CHARRED_TYPE)
{
return;
}
// Water touching the charred blocks
if (UtilBlock.getInRadius(block.Location, 1.6).keySet().stream().filter(water -> water.getType() == Material.WATER).iterator().hasNext())
{
return;
}
if (lifetime < max)
{
UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX);
UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX);
}
else
{
HandlerList.unregisterAll(this);
}
});
}
private void createExplosion()
{
ClanTerritory terr = _weapon.getClans().getClanUtility().getClaim(_origin);
if (terr != null && !ClansBlacklist.isValidClanName(terr.Owner))
{
return;
}
_blocks.add(new CraterBlock(_origin, 0, Material.AIR));
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
int iR = (int) _size + 1;
for (int x = -iR; x <= iR; x++)
{
for (int z = -iR; z <= iR; z++)
{
for (int y = -iR; y <= iR; y++)
{
Block curBlock = _origin.getBlock().getRelative(x, y, z);
double offset = UtilMath.offset(_origin, curBlock.getLocation());
if (offset <= _size)
{
blockList.put(curBlock, Double.valueOf(offset));
}
}
}
}
for (Entry<Block, Double> entry : blockList.entrySet())
{
Block block = entry.getKey();
ClanTerritory territory = _weapon.getClans().getClanUtility().getClaim(block.getLocation());
if (territory != null && !ClansBlacklist.isValidClanName(territory.Owner))
{
continue;
}
double distance = entry.getValue().doubleValue();
boolean air = distance <= _airChance || (Math.random() > (distance) / 3.65d);
if (block.getType() == Material.AIR) continue;
if (air)
{
_blocks.add(new CraterBlock(block.getLocation(), distance, Material.AIR));
Block above = block;
while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType()))
{
_blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR));
}
if (!UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()))
{
if (_fire && Math.random() >= .5)
{
_blocks.add(new CraterBlock(block.getLocation(), distance, Material.FIRE));
}
}
}
}
_blocks.forEach(CraterBlock::set);
for (Entry<Block, Double> entry : blockList.entrySet())
{
Block block = entry.getKey();
ClanTerritory territory = _weapon.getClans().getClanUtility().getClaim(block.getLocation());
if (territory != null && !ClansBlacklist.isValidClanName(territory.Owner))
{
continue;
}
double distance = entry.getValue().doubleValue();
if (block.getType() == Material.AIR) continue;
if (
distance > _airChance &&
Math.random() > .75 &&
UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) &&
!UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) &&
!block.getRelative(BlockFace.UP).getType().equals(CHARRED_TYPE) &&
!block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE))
{
_blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE));
if (_fire)
{
_blocks.add(new CraterBlock(block.getRelative(BlockFace.UP).getLocation(), distance, Material.FIRE));
}
}
}
_blocks.forEach(CraterBlock::set);
}
}

View File

@ -0,0 +1,32 @@
package mineplex.game.clans.clans.siege.weapon.projectile;
import org.bukkit.Location;
import org.bukkit.Material;
public class CraterBlock
{
public Material Type;
public byte Data;
public double DistanceToOrigin;
public Location Location;
public CraterBlock(Location location, double dist, Material type, byte data)
{
Location = location;
DistanceToOrigin = dist;
Type = type;
Data = data;
}
public CraterBlock(Location location, double dist, Material type)
{
this(location, dist, type, (byte) 0);
}
public void set()
{
Location.getBlock().setType(Type);
Location.getBlock().setData(Data);
}
}

View File

@ -0,0 +1,75 @@
package mineplex.game.clans.clans.siege.weapon.projectile;
import org.bukkit.Material;
public class ProjectileAttributes
{
protected boolean _isFallingBlock;
protected Material _fallingBlockType;
protected byte _fallingBlockData;
protected boolean _isPrimedTnt;
protected boolean _doCrater;
protected int _craterSize;
protected double _craterChanceOfAir;
protected boolean _craterDoFire;
public ProjectileAttributes setFallingBlock()
{
_isFallingBlock = true;
return this;
}
public ProjectileAttributes setFallingBlockType(Material type)
{
_fallingBlockType = type;
return this;
}
public ProjectileAttributes setFallingBlockData(byte data)
{
_fallingBlockData = data;
return this;
}
public ProjectileAttributes setPrimedTnt()
{
_isPrimedTnt = true;
return this;
}
public ProjectileAttributes setDoCrater()
{
_doCrater = true;
return this;
}
public ProjectileAttributes craterSize(int size)
{
_craterSize = size;
return this;
}
public ProjectileAttributes craterDoFire(boolean doFire)
{
_craterDoFire = doFire;
return this;
}
public ProjectileAttributes craterChanceOfAir(double chance)
{
_craterChanceOfAir = chance;
return this;
}
}

View File

@ -0,0 +1,7 @@
package mineplex.game.clans.clans.siege.weapon.projectile;
public enum ProjectileType
{
PRIMED_TNT,
FALLING_BLOCK;
}

View File

@ -0,0 +1,184 @@
package mineplex.game.clans.clans.siege.weapon.projectile;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
public class WeaponProjectile implements Listener
{
private ProjectileAttributes _attributes;
private Location _origin;
private Entity _projectileEntity;
private SiegeWeapon _weapon;
private double _yRot;
private double _xMulti;
private double _yVel;
private boolean _dead;
public WeaponProjectile(SiegeWeapon weapon, Location origin, ProjectileAttributes attributes, double yRot, double yVel, double xMulti)
{
_weapon = weapon;
_origin = origin;
_attributes = attributes;
_yRot = yRot;
_yVel = yVel;
_xMulti = xMulti;
UtilServer.getPluginManager().registerEvents(this, weapon.getClans().getPlugin());
spawn();
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onTntExplode(EntityExplodeEvent event)
{
if (!_attributes._isPrimedTnt)
{
return;
}
if (event.getEntity().equals(_projectileEntity))
{
event.setCancelled(true);
}
}
@EventHandler
public void onBlockFall(EntityChangeBlockEvent event)
{
if (!_dead && event.getEntity().equals(_projectileEntity))
{
die();
event.setCancelled(true);
}
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
if (_dead || _projectileEntity == null)
{
die();
return;
}
if ((Math.abs(_projectileEntity.getVelocity().getX()) < 0.01
|| Math.abs(_projectileEntity.getVelocity().getZ()) < 0.01)
&& UtilBlock.getInRadius(_projectileEntity.getLocation(), 2)
.keySet()
.stream()
.filter(block -> !UtilItem.isBoundless(block.getType()))
.iterator().hasNext() && _projectileEntity.getTicksLived() >= 10)
{
SiegeWeaponExplodeEvent newEvent = new SiegeWeaponExplodeEvent(_weapon, this);
UtilServer.getPluginManager().callEvent(newEvent);
if (!newEvent.isCancelled())
{
new Crater(_weapon, this, UtilBlock.nearestFloor(_projectileEntity.getLocation()), _attributes._craterSize, _attributes._craterChanceOfAir, _attributes._craterDoFire);
}
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectileEntity.getLocation(), Sound.EXPLODE, 1.f, 1.f));
die();
}
}
public boolean hasDied()
{
return _dead;
}
public Location getLocation()
{
return _projectileEntity.getLocation();
}
public void setLocation(Location location)
{
_projectileEntity.teleport(location);
}
private void die()
{
HandlerList.unregisterAll(this);
if (_projectileEntity != null)
{
_projectileEntity.remove();
_projectileEntity = null;
}
_dead = true;
}
private void spawn()
{
if (_attributes._isFallingBlock)
{
FallingBlock fallingBlock = _origin.getWorld().spawnFallingBlock(_origin, _attributes._fallingBlockType, _attributes._fallingBlockData);
_projectileEntity = fallingBlock;
Vector velocity = UtilAlg.getTrajectory(
_origin,
UtilAlg.moveForward(
_origin,
2.,
(float) Math.toDegrees(_yRot), false))
.multiply(_xMulti)
.setY(_yVel);
fallingBlock.setVelocity(velocity);
}
else if (_attributes._isPrimedTnt)
{
TNTPrimed tnt = _origin.getWorld().spawn(_origin, TNTPrimed.class);
_projectileEntity = tnt;
Vector velocity = UtilAlg.getTrajectory(
_origin,
UtilAlg.moveForward(
_origin,
2.,
(float) Math.toDegrees(_yRot), false))
.multiply(_xMulti)
.setY(_yVel);
tnt.setVelocity(velocity);
}
}
public int getCraterSize()
{
return _attributes._craterSize;
}
}

View File

@ -0,0 +1,23 @@
package mineplex.game.clans.clans.siege.weapon.util;
import java.util.function.Predicate;
import org.bukkit.entity.Player;
public class AccessRule
{
private Predicate<Player> _access;
private AccessType _type;
public AccessRule(AccessType type, Predicate<Player> access)
{
_type = type;
_access = access;
}
public boolean allow(AccessType type, Player player)
{
return type.equals(_type) && _access.test(player);
}
}

View File

@ -0,0 +1,7 @@
package mineplex.game.clans.clans.siege.weapon.util;
public enum AccessType
{
RCLICK_BB,
LCLICK_BB,
}

View File

@ -0,0 +1,250 @@
package mineplex.game.clans.clans.siege.weapon.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class BarrierCollisionBox implements Listener
{
private List<Location> _collisionBlocks;
private List<BiConsumer<Location, Player>> _leftClickListeners;
private List<BiConsumer<Location, Player>> _rightClickListeners;
BarrierCollisionBox()
{
_collisionBlocks = new ArrayList<>();
_leftClickListeners = new ArrayList<>();
_rightClickListeners = new ArrayList<>();
}
BarrierCollisionBox(List<Location> locations)
{
this();
_collisionBlocks.addAll(locations);
}
BarrierCollisionBox(Location start, Location end)
{
this();
UtilBlock.getInBoundingBox(start.getBlock().getLocation(), end.getBlock().getLocation(), false).forEach(block -> _collisionBlocks.add(block.getLocation()));
}
public void Construct()
{
setBlocks();
UtilServer.RegisterEvents(this);
}
public void Destruct()
{
HandlerList.unregisterAll(this);
resetBlocks();
_leftClickListeners.clear();
_rightClickListeners.clear();
_collisionBlocks.clear();
}
public void Update()
{
setBlocks();
}
public void registerLeft(BiConsumer<Location, Player> listener)
{
_leftClickListeners.add(listener);
}
public void registerRight(BiConsumer<Location, Player> listener)
{
_rightClickListeners.add(listener);
}
public void unregisterLeft(BiConsumer<Location, Player> listener)
{
_leftClickListeners.remove(listener);
}
public void unregisterRight(BiConsumer<Location, Player> listener)
{
_rightClickListeners.remove(listener);
}
private void onLeftClick(Location location, Player player)
{
_leftClickListeners.forEach(listener -> listener.accept(location, player));
}
private void onRightClick(Location location, Player player)
{
_rightClickListeners.forEach(listener -> listener.accept(location, player));
}
private void resetBlocks()
{
_collisionBlocks
.stream()
.filter(location -> location.getBlock().getType().equals(Material.BARRIER))
.forEach(location -> location.getBlock().setType(Material.AIR));
}
private void setBlocks()
{
for (Location location : _collisionBlocks)
{
location.getBlock().setType(Material.BARRIER);
}
}
public boolean isInBox(Location location)
{
for (Location other : _collisionBlocks)
{
if (other.equals(location))
{
return true;
}
}
return false;
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() == UpdateType.FAST)
{
Update();
}
}
// Events for interaction with the collision box;
@EventHandler
public void blockDamage(BlockDamageEvent event)
{
if (isInBox(event.getBlock().getLocation()))
{
onLeftClick(event.getBlock().getLocation(), event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler
public void blockBreak(BlockBreakEvent event)
{
if (isInBox(event.getBlock().getLocation()))
{
onLeftClick(event.getBlock().getLocation(), event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler
public void interact(PlayerInteractEvent event)
{
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
{
return;
}
if (isInBox(event.getClickedBlock().getLocation()))
{
onRightClick(event.getClickedBlock().getLocation(), event.getPlayer());
event.setCancelled(true);
}
}
public BarrierCollisionBox add(Location... location)
{
_collisionBlocks.addAll(Arrays.asList(location));
Update();
return this;
}
public BarrierCollisionBox add(List<Location> location)
{
_collisionBlocks.addAll(location);
Update();
return this;
}
public BarrierCollisionBox remove(Location... location)
{
_collisionBlocks.removeAll(Arrays.asList(location));
Update();
return this;
}
public BarrierCollisionBox add(BarrierCollisionBox box, boolean destructOld, boolean cloneListeners)
{
_collisionBlocks.addAll(box._collisionBlocks);
if (cloneListeners)
{
_leftClickListeners.addAll(box._leftClickListeners);
_rightClickListeners.addAll(box._rightClickListeners);
}
if (destructOld)
{
box.Destruct();
}
Update();
return this;
}
public BarrierCollisionBox add(BarrierCollisionBox box)
{
return add(box, false, false);
}
public BarrierCollisionBox addAll(Location start, Location end)
{
UtilBlock.getInBoundingBox(start, end).forEach(block -> _collisionBlocks.add(block.getLocation()));
Update();
return this;
}
public static BarrierCollisionBox all(Location start, Location end)
{
return new BarrierCollisionBox(start, end);
}
public static BarrierCollisionBox single(Location location)
{
return new BarrierCollisionBox(new ArrayList<>(Arrays.asList(location.getBlock().getLocation())));
}
}

View File

@ -0,0 +1,25 @@
package mineplex.game.clans.clans.siege.weapon.util;
import org.bukkit.Material;
public class WeaponStateInfo
{
private Material _material;
private byte _data;
public WeaponStateInfo(Material material, byte data)
{
_material = material;
_data = data;
}
public Material getType()
{
return _material;
}
public byte getData()
{
return _data;
}
}

View File

@ -1,15 +0,0 @@
package mineplex.game.clans.clans.stuck;
import org.bukkit.Location;
public class StuckClient
{
public Location StartLoc = null;
public long UnstickStartTime = -1;
public long UnstickEndTime = -1;
public long getTimeLeft()
{
return UnstickEndTime - System.currentTimeMillis();
}
}

View File

@ -1,109 +0,0 @@
package mineplex.game.clans.clans.stuck;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.MiniClientPlugin;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.stuck.commands.StuckCommand;
import mineplex.game.clans.spawn.Spawn;
public class StuckManager extends MiniClientPlugin<StuckClient>
{
public static final long UNSTICK_WAIT_TIME = UtilTime.convert(35, TimeUnit.SECONDS, TimeUnit.MILLISECONDS);
public StuckManager(ClansManager clans)
{
super("Stuck Handler", clans.getPlugin());
}
@Override
public void addCommands()
{
addCommand(new StuckCommand(this));
}
@Override
protected StuckClient AddPlayer(String player)
{
return new StuckClient();
}
public void unstick(Player player)
{
Get(player).UnstickStartTime = System.currentTimeMillis();
Get(player).UnstickEndTime = Get(player).UnstickStartTime + UNSTICK_WAIT_TIME;
Get(player).StartLoc = player.getLocation();
}
public boolean isUnsticking(Player caller)
{
return Get(caller).UnstickStartTime != -1;
}
@EventHandler
public void updateTeleport(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTER)
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (isUnsticking(player))
{
if (player.getLocation().distance(Get(player).StartLoc) >= 0.75)
{
cancelTeleport(player);
break;
}
UtilTextMiddle.display("", "Teleporting to Spawn in " + F.elem(UtilTime.MakeStr(Get(player).getTimeLeft())), 0, 20, 60, player);
if (Get(player).getTimeLeft() <= 500)
{
teleport(player);
}
}
}
}
}
private void cancelTeleport(Player player)
{
UtilPlayer.message(player, F.main("Clans", "You have moved, and cancelled the teleport."));
Get(player).UnstickStartTime = -1;
Get(player).UnstickEndTime = -1;
Get(player).StartLoc = null;
}
private void teleport(Player player)
{
Recharge.Instance.use(player, "Spawn Teleport", UtilTime.convert(15, TimeUnit.MINUTES, TimeUnit.MILLISECONDS), false, false);
UtilPlayer.message(player, F.main("Clans", "You have been teleported to Spawn."));
Get(player).UnstickStartTime = -1;
Get(player).UnstickEndTime = -1;
Get(player).StartLoc = null;
if (Math.random() < .5)
{
player.teleport(Spawn.getEastSpawn());
}
else
{
player.teleport(Spawn.getWestSpawn());
}
}
}

View File

@ -1,48 +0,0 @@
package mineplex.game.clans.clans.stuck.commands;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.stuck.StuckManager;
public class StuckCommand extends CommandBase<StuckManager>
{
public StuckCommand(StuckManager plugin)
{
super(plugin, Rank.ALL, "spawn", "stuck", "unstick", "unstuck");
}
@Override
public void Execute(Player caller, String[] args)
{
if (Plugin.isUnsticking(caller))
{
UtilPlayer.message(caller, F.main("Clans", "You are already teleporting to Spawn."));
return;
}
if (!Recharge.Instance.usable(caller, "Spawn Teleport", true))
{
return;
}
if(ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()) != null && !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Borderlands") &&
!ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Shops") && !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Spawn"))
{
UtilPlayer.message(caller, F.main("Clans", "You must be in the Wilderness/Borderlands/Shops/Spawn to use this command."));
return;
}
UtilPlayer.message(caller, F.main("Clans", "Teleporting to Spawn... Please do not move for " + F.elem(UtilTime.MakeStr(StuckManager.UNSTICK_WAIT_TIME))) + ".");
Plugin.unstick(caller);
}
}

View File

@ -14,7 +14,6 @@ import org.bukkit.Sound;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
@ -57,6 +56,7 @@ import mineplex.core.common.util.UtilGear;
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.common.weight.Weight;
import mineplex.core.common.weight.WeightSet;
@ -66,6 +66,7 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.ClansWaterPlaceEvent;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
@ -157,9 +158,15 @@ public class Gameplay extends MiniPlugin
@EventHandler
public void onBowShoot(EntityShootBowEvent event)
{
if (event.isCancelled())
{
return;
}
if (event.getEntity() instanceof Player)
{
Player player = (Player) event.getEntity();
ClientClass playerClass = _clansManager.getClassManager().Get(player);
if (!playerClass.IsGameClass(ClassType.Assassin, ClassType.Ranger))
@ -230,7 +237,7 @@ public class Gameplay extends MiniPlugin
HashSet<Block> remove = new HashSet<Block>();
for (Block cur : _bucketWater.keySet())
if (UtilTime.elapsed(_bucketWater.get(cur), 2000)) remove.add(cur);
if (UtilTime.elapsed(_bucketWater.get(cur).longValue(), 2000)) remove.add(cur);
for (Block cur : remove)
_bucketWater.remove(cur);
@ -239,6 +246,11 @@ public class Gameplay extends MiniPlugin
@EventHandler(priority = EventPriority.LOWEST)
public void ObsidianCancel(BlockPlaceEvent event)
{
if (_clansManager.masterBypass(event.getPlayer()))
{
return;
}
if (event.getBlock().getType() == Material.OBSIDIAN)
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot place " + F.item("Obsidian") + "."));
@ -328,12 +340,27 @@ public class Gameplay extends MiniPlugin
@EventHandler
public void LapisPlace(BlockPlaceEvent event)
{
if (event.isCancelled()) return;
if (event.isCancelled())
{
return;
}
if (event.getBlock().getType() != Material.LAPIS_BLOCK) return;
if (event.getBlock().getType() != Material.LAPIS_BLOCK)
{
return;
}
event.setCancelled(true);
ClansWaterPlaceEvent placeEvent = new ClansWaterPlaceEvent(event.getPlayer(), event.getBlock());
UtilServer.callEvent(placeEvent);
if (placeEvent.isCancelled())
{
return;
}
UtilInv.remove(event.getPlayer(), Material.LAPIS_BLOCK, (byte) 0, 1);
final Block block = event.getBlock();

Some files were not shown because too many files have changed in this diff Show More