Merge branches 'develop' and 'feature/report-v2' of github.com:Mineplex-LLC/Minecraft-PC into feature/report-v2

# Conflicts:
#	Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java
#	Plugins/Mineplex.Core/src/mineplex/core/preferences/UserPreferences.java
#	Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/ExclusivePreferencesPage.java
#	Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java
#	Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java
This commit is contained in:
Keir Nellyer 2016-09-05 14:26:06 +01:00
commit acd63c90a1
306 changed files with 15287 additions and 4563 deletions

View File

@ -19,7 +19,33 @@
package com.java.sk89q.jnbt;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.util.Vector;
import net.minecraft.server.v1_8_R3.NBTBase;
import net.minecraft.server.v1_8_R3.NBTTagByte;
import net.minecraft.server.v1_8_R3.NBTTagByteArray;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.NBTTagDouble;
import net.minecraft.server.v1_8_R3.NBTTagEnd;
import net.minecraft.server.v1_8_R3.NBTTagFloat;
import net.minecraft.server.v1_8_R3.NBTTagInt;
import net.minecraft.server.v1_8_R3.NBTTagIntArray;
import net.minecraft.server.v1_8_R3.NBTTagList;
import net.minecraft.server.v1_8_R3.NBTTagLong;
import net.minecraft.server.v1_8_R3.NBTTagShort;
import net.minecraft.server.v1_8_R3.NBTTagString;
/**
* A class which contains NBT-related utility methods.
@ -167,4 +193,249 @@ public final class NBTUtils {
return expected.cast(tag);
}
public static byte[] toBytesCompressed(String name, CompoundTag tag)
{
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
try (NBTOutputStream nbtStream = new NBTOutputStream(new GZIPOutputStream(byteStream)))
{
nbtStream.writeNamedTag(name, tag);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
return byteStream.toByteArray();
}
public static NamedTag getFromBytesCompressed(byte[] bytes)
{
try (NBTInputStream stream = new NBTInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes)));)
{
return stream.readNamedTag();
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public static NBTBase toNative(Tag tag) {
if (tag instanceof IntArrayTag) {
return toNative((IntArrayTag) tag);
} else if (tag instanceof ListTag) {
return toNative((ListTag) tag);
} else if (tag instanceof LongTag) {
return toNative((LongTag) tag);
} else if (tag instanceof StringTag) {
return toNative((StringTag) tag);
} else if (tag instanceof IntTag) {
return toNative((IntTag) tag);
} else if (tag instanceof ByteTag) {
return toNative((ByteTag) tag);
} else if (tag instanceof ByteArrayTag) {
return toNative((ByteArrayTag) tag);
} else if (tag instanceof CompoundTag) {
return toNative((CompoundTag) tag);
} else if (tag instanceof FloatTag) {
return toNative((FloatTag) tag);
} else if (tag instanceof ShortTag) {
return toNative((ShortTag) tag);
} else if (tag instanceof DoubleTag) {
return toNative((DoubleTag) tag);
} else {
throw new IllegalArgumentException("Can't convert tag of type " + tag.getClass().getCanonicalName());
}
}
public static NBTTagIntArray toNative(IntArrayTag tag) {
int[] value = tag.getValue();
return new NBTTagIntArray(Arrays.copyOf(value, value.length));
}
public static NBTTagList toNative(ListTag tag) {
NBTTagList list = new NBTTagList();
for (Tag child : tag.getValue()) {
if (child instanceof EndTag) {
continue;
}
list.add(toNative(child));
}
return list;
}
public static NBTTagLong toNative(LongTag tag) {
return new NBTTagLong(tag.getValue());
}
public static NBTTagString toNative(StringTag tag) {
return new NBTTagString(tag.getValue());
}
public static NBTTagInt toNative(IntTag tag) {
return new NBTTagInt(tag.getValue());
}
public static NBTTagByte toNative(ByteTag tag) {
return new NBTTagByte(tag.getValue());
}
public static NBTTagByteArray toNative(ByteArrayTag tag) {
byte[] value = tag.getValue();
return new NBTTagByteArray(Arrays.copyOf(value, value.length));
}
public static NBTTagCompound toNative(CompoundTag tag) {
NBTTagCompound compound = new NBTTagCompound();
for (Entry<String, Tag> child : tag.getValue().entrySet()) {
compound.set(child.getKey(), toNative(child.getValue()));
}
return compound;
}
public static NBTTagFloat toNative(FloatTag tag) {
return new NBTTagFloat(tag.getValue());
}
public static NBTTagShort toNative(ShortTag tag) {
return new NBTTagShort(tag.getValue());
}
public static NBTTagDouble toNative(DoubleTag tag) {
return new NBTTagDouble(tag.getValue());
}
public static Tag fromNative(NBTBase other) {
if (other instanceof NBTTagIntArray) {
return fromNative((NBTTagIntArray) other);
} else if (other instanceof NBTTagList) {
return fromNative((NBTTagList) other);
} else if (other instanceof NBTTagEnd) {
return fromNative((NBTTagEnd) other);
} else if (other instanceof NBTTagLong) {
return fromNative((NBTTagLong) other);
} else if (other instanceof NBTTagString) {
return fromNative((NBTTagString) other);
} else if (other instanceof NBTTagInt) {
return fromNative((NBTTagInt) other);
} else if (other instanceof NBTTagByte) {
return fromNative((NBTTagByte) other);
} else if (other instanceof NBTTagByteArray) {
return fromNative((NBTTagByteArray) other);
} else if (other instanceof NBTTagCompound) {
return fromNative((NBTTagCompound) other);
} else if (other instanceof NBTTagFloat) {
return fromNative((NBTTagFloat) other);
} else if (other instanceof NBTTagShort) {
return fromNative((NBTTagShort) other);
} else if (other instanceof NBTTagDouble) {
return fromNative((NBTTagDouble) other);
} else {
throw new IllegalArgumentException("Can't convert other of type " + other.getClass().getCanonicalName());
}
}
public static IntArrayTag fromNative(NBTTagIntArray other) {
int[] value = other.c();
return new IntArrayTag(Arrays.copyOf(value, value.length));
}
public static ListTag fromNative(NBTTagList other) {
other = (NBTTagList) other.clone();
List<Tag> list = new ArrayList<Tag>();
Class<? extends Tag> listClass = StringTag.class;
int size = other.size();
for (int i = 0; i < size; i++) {
Tag child = fromNative(other.a(0));
list.add(child);
listClass = child.getClass();
}
return new ListTag(listClass, list);
}
public static EndTag fromNative(NBTTagEnd other) {
return new EndTag();
}
public static LongTag fromNative(NBTTagLong other) {
return new LongTag(other.c());
}
public static StringTag fromNative(NBTTagString other) {
return new StringTag(other.a_());
}
public static IntTag fromNative(NBTTagInt other) {
return new IntTag(other.d());
}
public static ByteTag fromNative(NBTTagByte other) {
return new ByteTag(other.f());
}
public static ByteArrayTag fromNative(NBTTagByteArray other) {
byte[] value = other.c();
return new ByteArrayTag(Arrays.copyOf(value, value.length));
}
public static CompoundTag fromNative(NBTTagCompound other) {
@SuppressWarnings("unchecked") Collection<String> tags = other.c();
Map<String, Tag> map = new HashMap<String, Tag>();
for (String tagName : tags) {
map.put(tagName, fromNative(other.get(tagName)));
}
return new CompoundTag(map);
}
public static FloatTag fromNative(NBTTagFloat other) {
return new FloatTag(other.h());
}
public static ShortTag fromNative(NBTTagShort other) {
return new ShortTag(other.e());
}
public static DoubleTag fromNative(NBTTagDouble other) {
return new DoubleTag(other.g());
}
public static NBTTagList doubleArrayToList(double... doubles)
{
NBTTagList nbttaglist = new NBTTagList();
for(double d : doubles)
{
nbttaglist.add(new NBTTagDouble(d));
}
return nbttaglist;
}
public static Vector getVector(CompoundTag tag)
{
return new Vector(tag.asDouble("x"), tag.asDouble("y"), tag.asDouble("z"));
}
}

View File

@ -42,6 +42,7 @@ public class SortedSchematicLoader<T>
if (entry != null && !entry.getKey().equals(_currentValue))
{
_currentValue = entry.getKey();
Schematic schematic = entry.getValue();
entry.getValue().paste(_pasteLocation, false);
}
}

View File

@ -1,23 +1,30 @@
package mineplex.core.common.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* @author Shaun Bennett
*/
public class ApiEndpoint
{
private static final String API_HOST = "10.33.53.12";
// private static final String API_HOST = "localhost";
// private static final int API_PORT = 3000;
private static final int API_PORT = 7979;
private Gson _gson;
private ApiWebCall _webCall;
public ApiEndpoint(String path, Gson gson)
public ApiEndpoint(ApiHost host, String path)
{
String url = "http://" + API_HOST + ":" + API_PORT + path;
this(host, path, new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create());
}
public ApiEndpoint(ApiHost host, String path, Gson gson)
{
this(host.getHost(), host.getPort(), path, gson);
}
public ApiEndpoint(String host, int port, String path, Gson gson)
{
String url = "http://" + host + ":" + port + path;
_webCall = new ApiWebCall(url, gson);
_gson = gson;
}

View File

@ -0,0 +1,31 @@
package mineplex.core.common.api;
/**
* TODO: Store this in a file instead of being hardcoded
*
* @author Shaun Bennett
*/
public enum ApiHost
{
AMPLIFIERS("10.33.53.12", 7979),
ANTISPAM("10.33.53.12", 8181);
private String _host;
private int _port;
ApiHost(String host, int port)
{
_host = host;
_port = port;
}
public String getHost()
{
return _host;
}
public int getPort()
{
return _port;
}
}

View File

@ -9,16 +9,20 @@ import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockVector;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import net.minecraft.server.v1_8_R3.Chunk;
import net.minecraft.server.v1_8_R3.ChunkCoordIntPair;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutMapChunk;
import net.minecraft.server.v1_8_R3.PacketPlayOutMultiBlockChange;
import net.minecraft.server.v1_8_R3.PacketPlayOutMultiBlockChange.MultiBlockChangeInfo;
import net.minecraft.server.v1_8_R3.TileEntity;
import net.minecraft.server.v1_8_R3.WorldServer;
/**
* An agent used to easily record and send multi-block update packets to players. The agent handles if the packet should be a
@ -86,12 +90,12 @@ public class MultiBlockUpdaterAgent
if(chunkDist > Bukkit.getViewDistance()) continue;
sendPacket(c, players);
sendPacket(c, p);
}
}
}
private void sendPacket(Chunk c, Collection<? extends Player> players)
private void sendPacket(Chunk c, Player...players)
{
List<BlockVector> list = _chunks.get(c);
@ -101,7 +105,7 @@ public class MultiBlockUpdaterAgent
{
for(Player p : players)
{
MapUtil.SendChunkForPlayer(c, p);
UtilPlayer.sendPacket(p, new PacketPlayOutMapChunk(c, true, 65535));
}
}
else
@ -121,6 +125,25 @@ public class MultiBlockUpdaterAgent
UtilPlayer.sendPacket(p, packet);
}
}
Packet<?>[] tileEntities = new Packet[c.tileEntities.size()];
int i = 0;
for(TileEntity te : c.tileEntities.values())
{
tileEntities[i++] = te.getUpdatePacket();
}
for(Player p : players)
{
UtilPlayer.sendPacket(p, tileEntities);
((WorldServer)c.world).getTracker().untrackPlayer(((CraftPlayer)p).getHandle());
}
Bukkit.getScheduler().runTaskLater(UtilServer.getPlugin(), () ->
{
for(Player p : players)
{
((WorldServer)c.world).getTracker().a(((CraftPlayer)p).getHandle(), c);
}
}, 5);
}
}

View File

@ -1,14 +1,34 @@
package mineplex.core.common.block.schematic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.util.BlockVector;
import org.bukkit.util.Vector;
import com.mysql.jdbc.Util;
import com.java.sk89q.jnbt.CompoundTag;
import com.java.sk89q.jnbt.DoubleTag;
import com.java.sk89q.jnbt.NBTUtils;
import com.java.sk89q.jnbt.Tag;
import mineplex.core.common.block.DataLocationMap;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilBlock;
import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.EntityTypes;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.NBTTagInt;
import net.minecraft.server.v1_8_R3.TileEntity;
import net.minecraft.server.v1_8_R3.WorldServer;
public class Schematic
{
@ -18,8 +38,11 @@ public class Schematic
private final short[] _blocks;
private final byte[] _blockData;
private final Vector _weOffset;
private final Map<BlockVector, Map<String, Tag>> _tileEntities;
private final List<Tag> _entities;
public Schematic(short width, short height, short length, short[] blocks, byte[] blockData, Vector worldEditOffset)
public Schematic(short width, short height, short length, short[] blocks, byte[] blockData, Vector worldEditOffset, Map<BlockVector, Map<String, Tag>> tileEntities, List<Tag> entities)
{
_width = width;
_height = height;
@ -27,6 +50,18 @@ public class Schematic
_blocks = blocks;
_blockData = blockData;
_weOffset = worldEditOffset;
_tileEntities = tileEntities;
_entities = entities;
}
public Schematic(short width, short height, short length, short[] blocks, byte[] blockData, Vector worldEditOffset, Map<BlockVector, Map<String, Tag>> tileEntities)
{
this(width, height, length, blocks, blockData, worldEditOffset, tileEntities, new ArrayList<>());
}
public Schematic(short width, short height, short length, short[] blocks, byte[] blockData, Vector worldEditOffset)
{
this(width, height, length, blocks, blockData, worldEditOffset, new HashMap<>());
}
public Schematic(short width, short height, short length, short[] blocks, byte[] blockData)
@ -34,17 +69,17 @@ public class Schematic
this(width, height, length, blocks, blockData, null);
}
public DataLocationMap paste(Location originLocation)
public SchematicData paste(Location originLocation)
{
return paste(originLocation, false);
}
public DataLocationMap paste(Location originLocation, boolean ignoreAir)
public SchematicData paste(Location originLocation, boolean ignoreAir)
{
return paste(originLocation, ignoreAir, false);
}
public DataLocationMap paste(Location originLocation, boolean ignoreAir, boolean worldEditOffset)
public SchematicData paste(Location originLocation, boolean ignoreAir, boolean worldEditOffset)
{
if(worldEditOffset && hasWorldEditOffset())
{
@ -52,12 +87,16 @@ public class Schematic
}
DataLocationMap locationMap = new DataLocationMap();
SchematicData output = new SchematicData(locationMap, originLocation.getWorld());
int startX = originLocation.getBlockX();
int startY = originLocation.getBlockY();
int startZ = originLocation.getBlockZ();
UtilBlock.startQuickRecording();
WorldServer nmsWorld = ((CraftWorld)originLocation.getWorld()).getHandle();
for (int x = 0; x < _width; x++)
{
for (int y = 0; y < _height; y++)
@ -107,15 +146,62 @@ public class Schematic
}
}
UtilBlock.setQuick(originLocation.getWorld(), startX + x, startY + y, startZ + z, materialId, _blockData[index]);
BlockVector bv = new BlockVector(x,y,z);
output.getBlocksRaw().add(bv);
Map<String, Tag> map = _tileEntities.get(bv);
if(map != null)
{
TileEntity te = nmsWorld.getTileEntity(MapUtil.getBlockPos(bv.add(originLocation.toVector())));
if(te == null) continue;
CompoundTag weTag = new CompoundTag(map);
NBTTagCompound tag = NBTUtils.toNative(weTag);
tag.set("x", new NBTTagInt(tag.getInt("x") + startX));
tag.set("y", new NBTTagInt(tag.getInt("y") + startY));
tag.set("z", new NBTTagInt(tag.getInt("z") + startZ));
te.a(tag);
output.getTileEntitiesRaw().add(bv);
}
}
}
}
UtilBlock.stopQuickRecording();
return locationMap;
for(Tag tag : _entities)
{
if(tag instanceof CompoundTag)
{
CompoundTag ctag = (CompoundTag) tag;
NBTTagCompound nmsTag = NBTUtils.toNative(ctag);
List<DoubleTag> list = ctag.getList("Pos", DoubleTag.class);
Vector pos = new Vector(list.get(0).getValue(), list.get(1).getValue(), list.get(2).getValue());
pos.add(originLocation.toVector());
UtilSchematic.setPosition(nmsTag, pos);
list = NBTUtils.fromNative(nmsTag).getList("Pos", DoubleTag.class);
Entity nmsEntity = EntityTypes.a(nmsTag, nmsWorld);
nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM);
if(nmsEntity == null) continue;
output.getEntitiesRaw().add(nmsEntity.getBukkitEntity());
}
}
return output;
}
/**
@ -175,6 +261,13 @@ public class Schematic
return _weOffset != null;
}
public Vector getWorldEditOffset()
{
if(!hasWorldEditOffset()) return null;
return _weOffset.clone();
}
public int getSize()
{
return _blocks.length;
@ -187,7 +280,7 @@ public class Schematic
public boolean hasIndex(int index)
{
return index < _blocks.length;
return index < _blocks.length && index >= 0;
}
public Short getBlock(int x, int y, int z)
@ -241,6 +334,16 @@ public class Schematic
return _blockData;
}
public List<Tag> getEntities()
{
return _entities;
}
public Map<BlockVector, Map<String, Tag>> getTileEntities()
{
return _tileEntities;
}
@Override
public String toString()
{

View File

@ -0,0 +1,86 @@
package mineplex.core.common.block.schematic;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.util.BlockVector;
import mineplex.core.common.block.DataLocationMap;
/**
* Wrapper class for holding the output from pasting a schematic
*/
public class SchematicData
{
private final List<BlockVector> _blocks;
private final DataLocationMap _dataMap;
private final List<Entity> _entities;
private final List<BlockVector> _tileEntities;
private final World _world;
public SchematicData(DataLocationMap dataMap, World world)
{
_dataMap = dataMap;
_blocks = new ArrayList<>();
_tileEntities = new ArrayList<>();
_entities = new ArrayList<>();
_world = world;
}
/**
* @return Returns a list of blocks which has been edited by the schematic
*/
public List<BlockVector> getBlocks()
{
return new ArrayList<>(_blocks);
}
/**
* @return Returns the DataLocationMap which was utilized while pasting
*/
public DataLocationMap getDataLocationMap()
{
return _dataMap;
}
/**
* @return Returns a entities which was spawned by the schematic
*/
public List<Entity> getEntities()
{
return new ArrayList<>(_entities);
}
/**
* @return Returns a list of blocks who are tile entities which have been edited by the schematic. All the blocks in this list is also
* inside the {@link #getBlocks()} method
*/
public List<BlockVector> getTileEntities()
{
return new ArrayList<>(_tileEntities);
}
public World getWorld()
{
return _world;
}
List<BlockVector> getBlocksRaw()
{
return _blocks;
}
List<BlockVector> getTileEntitiesRaw()
{
return _tileEntities;
}
List<Entity> getEntitiesRaw()
{
return _entities;
}
}

View File

@ -1,27 +1,65 @@
package mineplex.core.common.block.schematic;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockVector;
import org.bukkit.util.Vector;
import com.java.sk89q.jnbt.ByteArrayTag;
import com.java.sk89q.jnbt.CompoundTag;
import com.java.sk89q.jnbt.IntTag;
import com.java.sk89q.jnbt.ListTag;
import com.java.sk89q.jnbt.NBTInputStream;
import com.java.sk89q.jnbt.NBTOutputStream;
import com.java.sk89q.jnbt.NBTUtils;
import com.java.sk89q.jnbt.NamedTag;
import com.java.sk89q.jnbt.ShortTag;
import com.java.sk89q.jnbt.StringTag;
import com.java.sk89q.jnbt.Tag;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.NBTTagInt;
import net.minecraft.server.v1_8_R3.TileEntity;
import net.minecraft.server.v1_8_R3.WorldServer;
public class UtilSchematic
{
public static Schematic loadSchematic(File file) throws IOException
{
FileInputStream fis = new FileInputStream(file);
NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(fis));
return loadSchematic(fis);
}
public static Schematic loadSchematic(byte[] bytes) throws IOException
{
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
return loadSchematic(bis);
}
public static Schematic loadSchematic(InputStream input) throws IOException
{
NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(input));
NamedTag rootTag = nbtStream.readNamedTag();
nbtStream.close();
@ -35,9 +73,11 @@ public class UtilSchematic
short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
short height = getChildTag(schematic, "Height", ShortTag.class).getValue();
short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
byte[] blockId = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
byte[] addId = new byte[0];
short[] blocks = new short[blockId.length];
short[] blocks = new short[blockId.length]; // Have to later combine IDs
byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
Vector weOffset = null;
@ -49,11 +89,14 @@ public class UtilSchematic
weOffset = new Vector(x, y, z);
}
// We support 4096 block IDs using the same method as vanilla Minecraft, where
// the highest 4 bits are stored in a separate byte array.
if (schematic.containsKey("AddBlocks"))
{
addId = getChildTag(schematic, "AddBlocks", ByteArrayTag.class).getValue();
}
// Combine the AddBlocks data with the first 8-bit block ID
for (int index = 0; index < blockId.length; index++)
{
if ((index >> 1) >= addId.length)
@ -67,8 +110,253 @@ public class UtilSchematic
}
}
// Need to pull out tile entities
List<Tag> tileEntities = getChildTag(schematic, "TileEntities", ListTag.class).getValue();
Map<BlockVector, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
return new Schematic(width, height, length, blocks, blockData, weOffset);
for (Tag tag : tileEntities)
{
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag t = (CompoundTag) tag;
int x = 0;
int y = 0;
int z = 0;
Map<String, Tag> values = new HashMap<>();
for (Map.Entry<String, Tag> entry : t.getValue().entrySet())
{
if (entry.getValue() instanceof IntTag)
{
if (entry.getKey().equals("x"))
{
x = ((IntTag) entry.getValue()).getValue();
} else if (entry.getKey().equals("y"))
{
y = ((IntTag) entry.getValue()).getValue();
} else if (entry.getKey().equals("z"))
{
z = ((IntTag) entry.getValue()).getValue();
}
}
values.put(entry.getKey(), entry.getValue());
}
BlockVector vec = new BlockVector(x, y, z);
tileEntitiesMap.put(vec, values);
}
List<Tag> entityTags = getChildTag(schematic, "Entities", ListTag.class).getValue();
return new Schematic(width, height, length, blocks, blockData, weOffset, tileEntitiesMap, entityTags);
}
/**
* @param schematic The schematic you want to turn into bytes
* @return Returns a byte array of the schematic which may be used for saving the schematic to DB or file
*/
public static byte[] getBytes(Schematic schematic)
{
ByteArrayOutputStream output = new ByteArrayOutputStream();
writeBytes(schematic, output);
return output.toByteArray();
}
/**
* @param schematic The scheamtic you want save somewhere
* @return Writes out this schematic on byte form
*/
public static void writeBytes(Schematic schematic, OutputStream output)
{
Map<String, Tag> map = new HashMap<>();
short width = schematic.getWidth();
short height = schematic.getHeight();
short length = schematic.getLength();
map.put("Width", new ShortTag(width));
map.put("Height", new ShortTag(height));
map.put("Length", new ShortTag(length));
if(schematic.hasWorldEditOffset())
{
Vector weOffset = schematic.getWorldEditOffset();
map.put("WEOffsetX", new IntTag(weOffset.getBlockX()));
map.put("WEOffsetY", new IntTag(weOffset.getBlockX()));
map.put("WEOffsetZ", new IntTag(weOffset.getBlockX()));
}
map.put("Materials", new StringTag("Alpha"));
short[] sBlocks = schematic.getBlocks();
Map<BlockVector, Map<String, Tag>> sTileEntities = schematic.getTileEntities();
byte[] blocks = new byte[sBlocks.length];
byte[] addBlocks = null;
byte[] blockData = schematic.getBlockData();
List<Tag> tileEntities = new ArrayList<Tag>();
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
for(int z = 0; z < length; z++)
{
int index = y * width * length + z * width + x;
BlockVector bv = new BlockVector(x, y, z);
//Save 4096 IDs in an AddBlocks section
if(sBlocks[index] > 255)
{
if (addBlocks == null) { // Lazily create section
addBlocks = new byte[(blocks.length >> 1) + 1];
}
addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
addBlocks[index >> 1] & 0xF0 | (sBlocks[index] >> 8) & 0xF
: addBlocks[index >> 1] & 0xF | ((sBlocks[index] >> 8) & 0xF) << 4);
}
blocks[index] = (byte) sBlocks[index];
if(sTileEntities.get(bv) != null)
{
Map<String, Tag> values = new HashMap<>(sTileEntities.get(bv));
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));
CompoundTag tileEntityTag = new CompoundTag(values);
tileEntities.add(tileEntityTag);
}
}
}
}
map.put("Blocks", new ByteArrayTag(blocks));
map.put("Data", new ByteArrayTag(blockData));
map.put("TileEntities", new ListTag(CompoundTag.class, tileEntities));
if (addBlocks != null) {
map.put("AddBlocks", new ByteArrayTag(addBlocks));
}
// ====================================================================
// Entities
// ====================================================================
List<Tag> entities = schematic.getEntities();
map.put("Entities", new ListTag(CompoundTag.class, entities));
// ====================================================================
// Output
// ====================================================================
CompoundTag schematicTag = new CompoundTag(map);
try (NBTOutputStream outputStream = new NBTOutputStream(new GZIPOutputStream(output)))
{
outputStream.writeNamedTag("Schematic", schematicTag);
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static Schematic createSchematic(Location locA, Location locB)
{
return createSchematic(locA, locB, null);
}
public static Schematic createSchematic(Location locA, Location locB, Vector worldEditOffset)
{
World world = locA.getWorld();
Vector min = Vector.getMinimum(locA.toVector(), locB.toVector());
Vector max = Vector.getMaximum(locB.toVector(), locA.toVector());
short width = (short) (max.getBlockX()-min.getBlockX());
short height = (short) (max.getBlockY()-min.getBlockY());
short length = (short) (max.getBlockZ()-min.getBlockZ());
short[] blocks = new short[width*height*length];
byte[] blocksData = new byte[blocks.length];
WorldServer nmsWorld = ((CraftWorld)world).getHandle();
Map<BlockVector, Map<String, Tag>> tileEntities = new HashMap<>();
for(int x = min.getBlockX(); x < max.getBlockX(); x++)
{
for(int y = min.getBlockY(); y < max.getBlockY(); y++)
{
for(int z = min.getBlockZ(); z < max.getBlockZ(); z++)
{
int localX = x-min.getBlockX();
int localY = y-min.getBlockY();
int localZ = z-min.getBlockZ();
Block b = world.getBlockAt(x, y, z);
int index = localY * width * length + localZ * width + localX;
blocks[index] = (short) b.getTypeId();
blocksData[index] = b.getData();
BlockPosition bp = new BlockPosition(x, y, z);
TileEntity tileEntity = nmsWorld.getTileEntity(bp);
if(tileEntity == null) continue;
NBTTagCompound nmsTag = new NBTTagCompound();
tileEntity.b(nmsTag);
nmsTag.set("x", new NBTTagInt(localX));
nmsTag.set("y", new NBTTagInt(localY));
nmsTag.set("z", new NBTTagInt(localZ));
CompoundTag tag = NBTUtils.fromNative(nmsTag);
tileEntities.put(new BlockVector(localX, localY, localZ), tag.getValue());
}
}
}
List<Tag> entities = new ArrayList<>();
for(Entity e : world.getEntities())
{
if(e instanceof Player) continue;
if(e.getLocation().toVector().isInAABB(min, max))
{
net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity)e).getHandle();
NBTTagCompound nmsTag = new NBTTagCompound();
nmsEntity.c(nmsTag);
Vector diff = e.getLocation().subtract(min).toVector();
setPosition(nmsTag, diff);
nmsTag.remove("UUID");
nmsTag.remove("UUIDMost");
nmsTag.remove("UUIDLeast");
CompoundTag tag = NBTUtils.fromNative(nmsTag);
entities.add(tag);
}
}
return new Schematic(width, height, length, blocks, blocksData, worldEditOffset, tileEntities, entities);
}
@ -78,6 +366,11 @@ public class UtilSchematic
return expected.cast(tag);
}
public static void setPosition(NBTTagCompound nbtTag, Vector pos)
{
nbtTag.set("Pos", NBTUtils.doubleArrayToList(pos.getX(), pos.getY(), pos.getZ()));
}
public static void main(String[] args) throws IOException
{
File file = new File("test.schematic");

View File

@ -1,36 +1,22 @@
package mineplex.core.common.skin;
import java.lang.reflect.Field;
import java.util.Base64;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.authlib.minecraft.InsecureTextureException;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository;
import mineplex.core.common.util.UtilPlayer;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.minecraft.server.v1_8_R3.Item;
import net.minecraft.server.v1_8_R3.MinecraftKey;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.NBTTagList;
import net.minecraft.server.v1_8_R3.NBTTagString;
import org.bukkit.inventory.meta.SkullMeta;
public class SkinData
@ -69,6 +55,8 @@ public class SkinData
public final static SkinData SNOWMAN = new SkinData("eyJ0aW1lc3RhbXAiOjE0NTAwMTk4Nzk5NDIsInByb2ZpbGVJZCI6ImE5ZDBjMDcyYmYxOTQwYTFhMTkzNjhkMDlkNTAwMjZlIiwicHJvZmlsZU5hbWUiOiJTcGlyaXR1c1NhbmN0dXMiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzEzMTgxYWViODQzODk3NzM1ZDQwMmIyNDk2OTQxNmZkYjBjZTM0YTZiOTM3ODE2MjQzNzU2ZTlkYWU1OGUzIn19fQ==", "NZvsNu+HQ5uvGWq6O8VNDGq9A145bmk2IkHiz916uRVPMRqqCI/zwhKWNLlFACE/feuLkhYAois29ec6sVVOtHIoNA+S5q1Mb/Vjc3TJQxzqmx2FZOhJiIttFwYuo9WomQKBqrPMSJ9tpQig4wzoqldeeTjWC3dLz7JeX+gkzinryVjG7NNN9L5hXK5/BBxRcrtwmXJfUlSANyrd8RZW7mEUgU8yxlzdqTu0w7bZLjQNd4vciwoF3NelXDorMIIqiHTkuQesG91Njtu25VCUDK3nXbqEnZw2ZtxB5fT5G2Omm/vkNSRXc0P7iqchVowdYQcMlQUsp65xpkBbFS4LwjzDkYIfLmF++hePb8z72Gz77FxhO5sRLGreSH227McyL/0CtWNKm9ZZIfQtZZjEZTj9+eiJMCloCMg3yWa1VBOiLHzz0wY6gGklccIImPyXEg7E0dIK8qYseJMhmmBNZ8pDOkbUDp3mRlrQ2iyClgQkbuR63j79IBUaCxmsa3NnrAtaJklzd9mzkHXfMBh2XT7Gl8AhJS6JK5kCvip1rBBI8yjrsjE/E+lyJFIbC4rXxyMDGZWkcdrd7U4ZFYKiLHbzdFRqX+11qs9xO2BvomGXkATCzYmOf2kQ86R6rNN0+JfE4QpKzj2WWt3C8ky2qpuXZz29p0816E3/qseYtgg=");
public final static SkinData TEDDY_BEAR = new SkinData("eyJ0aW1lc3RhbXAiOjE0NTUxMDkzOTE4MjYsInByb2ZpbGVJZCI6ImE5ZDBjMDcyYmYxOTQwYTFhMTkzNjhkMDlkNTAwMjZlIiwicHJvZmlsZU5hbWUiOiJTcGlyaXR1c1NhbmN0dXMiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzQ0OTU4ZDdjNjlhZTQ4NGM2NWYzMTM0N2NkY2M5MmM2OWY1NDA2ODA1YjUzNjUyYTc1YThlZDc5OWRmNyJ9fX0=", "sNTRV9jTjLszUmyaqyEG7N8d5RM1jbwMSXi34S2EkVmIjWsowfSMnHRQqqgZfxcyqBM5I7MljtB84IeQWu4rqhyFrM9blWvtowjijFIOgKCs97q2sswv9iauU6ohvgTpgN5B0Q16MJmMIgZU8d8TATtEaIzq2eg6Ve1AJlNnW4huGNsoNfm8WdVU1tZmsYAwtVP/ryvhyj7mHyVF27m0Sm4fZRf/lHH5gEJYB4JHSAoEhjPIQOdkgRMJRrWGOfhhiGs3kEWmsRGfIPFo2ZJfcu+TFV2rd4Q+A1LmY8kimnzdKX3InXeKbk8qzcgqGNro4XFnSiHo1d6/B+N0JeYOTITYRQ6u24rNSUh5ezbG01iikVFCfrgb7UR6utoLK15F4/fmhpex+BJpmyZoXAqk08tZws/5wsIWQ1okrGcbBKWEHhw2ekUc82US21/W53vd657UBg7FuqM4FhkAqmsYPvYLMpNYxxmDJaI8uJyU7cnGFYyBaFlqUxfJUfcFTwWo10JO3yp5FjqeCQa7rFvfpsqw3w2mBpJmlZ5HRjfS5pmhk0QiY0TRfwZfFemkuZYnNbO82qLUm+6zTm0fbC90Swt8nNr/42ajzEoUjnL6VsERIXS5/fPwjftbQAC60ujy8yo66Sp3sSAALNg5zjM+Uizkq2f9Axc+kind22hp10M=");
public final static SkinData UNCLE_SAM = new SkinData("eyJ0aW1lc3RhbXAiOjE0NjYxODA0NjY4NTcsInByb2ZpbGVJZCI6IjlmY2FlZDhiMTRiNTRmN2ZhNjRjYjYwNDBlNzA1MjcyIiwicHJvZmlsZU5hbWUiOiJMQ2FzdHIxIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9jYzM1YWRmZTQ3ODBjNmU2NTk4YTJlYzk2ZjdhZGQ5ZDc4NjljMjBlZjRmYjEyNjk2NmJhOGFlMDRlOWRhIn19fQ==", "NmJ+hXmvwQlYFYY7YVQWRr11yBbAfJP+jk11SQ91gUUtJJjb4v8RFbNu5UXNCKxYj3BPtldqshG1maNB0NWJRud7ZyAdHc0JMmR1vtHEge9Hhet4fLyyaZ9rZn4BvD9Guqgv9H/mZzUzrft9TIho0Qbu/U++lVsbZXC2GrJDDMyLnYr9C7f+FUnr0z4WvkNcg23SHBOYkOYT95NSdykIka3c3v+/HvSvuwOnMsfVxqLyCZLpo20vamBJ1uK1dmx2+TVGnUPlofFHRdOXOpJc+YmicJvrsQR6a9zlvnTbU4MYClMOKvjLe6aX5Af+n8Gw3oKcm0PuR8CPLyf9kjcmUF6XMiEXAWWJtCgvhCiFV5/mQQH3cQ1kqk4BDLUxMVhG5tzjKLoQQy39cFM32ee+QFjXlzy59meC8jgvPmOVU3GpJ32XWOtaXMCyeJrhz2QVKRLEr2KZgz8Pd8VrHARXVZsNYEasj8z0cHjgSJqTU9kD90CC+4YpvdyRBRqbNQig5KuGCqUHKgflsEsM7YrFRKP5As1LgqYQfqRAMmLSo47eW0onOwchC9wCqqisPlYSuDRt4Mun/KFGqYh1Sghn8/gzu49La8BpwlekjVEoPEcDaIIgnFzOvgmmgMANkoJ3PzhHoHMoXtObe3eSTi+eYp4qAQVzkTxfF3WXY2fui1M=");
public final static SkinData METAL_MAN = new SkinData("eyJ0aW1lc3RhbXAiOjE0Njg3ODAyMzk2ODYsInByb2ZpbGVJZCI6IjlmY2FlZDhiMTRiNTRmN2ZhNjRjYjYwNDBlNzA1MjcyIiwicHJvZmlsZU5hbWUiOiJMQ2FzdHIxIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9hNzc5YWEzYzk3OTc0Mzk1YTY3MTZkZmQ5MTI4YWM0N2E1MzdlMzljMzdmMGM0ZjZkZjQ1YjJmMGI4ZjVkMiJ9fX0=", "acwmrIdtzzkuntsvQqD+o9UYaI09xzQoPgRXFtvS1hvGgGRbApdG7YbQ3Itjg/8WUl0trAMMJa1IL8TlXaOwTeClOj6if3HW2lJ8yO7E+MXEJoDZcjkxVOK3322NRCBiPG+VbNCwHE7IvT8P4awExvV2nHLbCk7upawxK3oKfR5U+YEq/eLG/UCC1TAnHNLXE0mr+6ZtNut5qgz1u0Y+VNQKI/vdjVit1ttYeBjIWpSszhlP4bH8Iw3u3ZRuDqU4xSAWzj6Qhw9UYm2T3s2N9s2yW3wiagijUEq9stbaw97n3UCqBas58lTBy46w524lBvwbYC1U9jwxPxSUo6L6omhPKZSwgK/u2w4mELvfNI09A4C7RNThnz9wgrT0FPajjXYkt31Ba5qaP7HwcThQu02Bb3gmYfHfMvuDBt8xUk4lFyUuL+lwqUHXlKRkUPGVkDLDpmsnk+y4LvaymNHBBWpOyqpm8y1BTpux02GqCIgK7nHtsRNH3q3yHR1YyM0tc6PKXOst5ex1cGP654/Q0KEUSAvAV5ozj/q5izRlPJNiwu9zPqhfs8oWSBSo/Sfej6p7Fu9u0h0j/k0m86bfZObe2RsCEgBe8GSF35cyYRou0qTvk+00hEr+jpxeat0e9JHe163jI/Ew9XPeGd6eT8GTy4iyJM0O/y1MlsRjUec=");
public final static SkinData OMEGA_CHEST = new SkinData("eyJ0aW1lc3RhbXAiOjE0NzI1MTAzNzAwOTksInByb2ZpbGVJZCI6IjlmY2FlZDhiMTRiNTRmN2ZhNjRjYjYwNDBlNzA1MjcyIiwicHJvZmlsZU5hbWUiOiJMQ2FzdHIxIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS85MDM2MjNjMmRkMjdhNWM0Y2NlYzY5MWY3NjM0YTNkMzVkNTRiNDg0YjIzNTdhNWQ1ZWFmYmYwNTRkY2NlIn19fQ==", "cQty4zNF2QgzNuVOHTGGX5YVofApKr01KkQ70bO1n+I9nlkc9qqhcigA+uBYdw4THANFsTRwIrskgTS3TTmuaXYmMUoNnj7gr2Gp7D2t7L53QyJJhIw0hHNDvQucf19SOxhtR9FvW+xnh1JcgOTF3VZxIeRaN4bCtqkeFitCJwts4Z7SlDxB4EFZVsifM+gK4iel9YWYGNnZiQm48lxU+dMFd0cCa4L00ngBExQoWC8zbJc3K9LGdqI1YOMh3bCt81F4jcrPnDycxWwOTj/tBri4yeXK1htq5dAixHwq1EF86gQMnfeIIk6D/BREtVKoXK9K4lstYPHLFiBqkwpijArbC0sZp8s/j88NYUz9PgSJ2z/b5jhPChH2OkoGQOL0/QrxqUZUet+WHaIQtvFoqmcFRCKJQembgJGZV0X86XQxEEtevkNgXPigJVyQ5GVuDCeowRkMGfSadQCBsnmdOVZNshS60tBSDcbd2oWeQUJn1+OJkmz+OktbMbP4ttN6x3+MPMSZoGT1bc1BSRNFRYOBZuNz1zLWsHFRyNLaVS3ep/ktE+Rt5sbapo+r4GjrKGV7Unx6pbfoxcnMVxWZ9X/sMgztQdwYEQlnvAxGvCY/1ZIm3/izqB2zAgG7ZfWzKjU2P5VseKokMjHXrzZX9Uqtn0zpITEaG5HjUpRSaJg=");
// Comments this out for now, so it doesn't load the player profile
// A better way to do this would check for the properties when getting the skull or the skin
@ -78,11 +66,15 @@ public class SkinData
//public final static SkinData CHISS = new SkinData("eyJ0aW1lc3RhbXAiOjE0NTk1NDI5NjgyNDEsInByb2ZpbGVJZCI6IjFkMmJmZTYxN2ViZDQ0NWRiYTdkODM1NGEwZmZkMWVhIiwicHJvZmlsZU5hbWUiOiJDaGlzcyIsInNpZ25hdHVyZVJlcXVpcmVkIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTg3MmNkMzRjY2IzMTIxYjRjNmEzOGFjM2JmOGVkM2UwMzk3YmQ2YTg4NDI4YjdhZmM2ZTUyNTI4NTVhMzQzIiwibWV0YWRhdGEiOnsibW9kZWwiOiJzbGltIn19fX0=", "hNTLRA2acZYx2dM90lnJN8FMK/ceD3+AxKNdD5FrXzxGtYL4C1Jr/vbTE0UosmwFP3wScNEW/fuDOjeZRjZHMJdvgDZMlMK/5KDhOY6sj/RS9RckztsgummSyjH/hdDn7TWWfhZLMbiia/K0VReI9eq2yD6zGQpvMlz5hB/5SX5YHWXvCah3TL4UzYSlSVDlwY/Q3sVuIZUr8m/LIXJwniJKLGo6tUgtiJd9eseOsbBpVjzCUtLD8A9WBe2/eODgmLfqEvXESIoDRG8vL2nPSXWma/YolYHIl32/i+ZxVD7dRRaXQFYSiLI24EtzX1pPhMjyaTLazP9abH43J6J31w02pKM7N/xTa62020L/YfRRKGT5lygEDb1NMoSpAjszPxah+Ra2/L+yUWEI8cMES6I4mIJ00tclPjWK01xhIn3tqg+y2gqsGHwPhu/7vmF5NirNfKFw0qciKNBfbCAF7ae+mkUKjmAPuvBUBqQb7BOcpNVWsCo/XvzmiZZYsf5P4Uwz8LqUK4uH6V/5dg7lY2Xg3+IUylsrDqLGFDI8iy/NdjIQMbuRadh4IDO6DcmxBri2Ax4JNBPBTnRezge8uq37MZcft/IXQgFWKB9RtidVEACaTOkRj27k+Ojnkki+j44k0wZB47hiXFUHMCHl3a0SVdQe15ZbVsQj/HAvAS0=");
//public final static SkinData DEFEK7 = new SkinData("eyJ0aW1lc3RhbXAiOjE0NTk1NDI3ODkwNTksInByb2ZpbGVJZCI6Ijg5ZDQ2M2Y3MjNlYzQ3MGE4MjQ0NDU3ZjBjOGQ4NjFjIiwicHJvZmlsZU5hbWUiOiJkZWZlazciLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2JmYWNjOWM4ZjhlY2E1OWU0NTE4MTUxZmE4OGFiMDZjOTFmNjM3OTE2NzJmMTRlNGYzODY3YTI2OTVlN2NmYmYifSwiQ0FQRSI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzIyYjljNWVhNzYzYzg2ZmM1Y2FlYTMzZDgyYjBmYTY1YTdjMjI4ZmQzMjFiYTU0NzY2ZWE5NWEzZDBiOTc5MyJ9fX0=", "jBoRvkhQXz+nap8yJJIZ+4HClMItWODumeSOYjXytP3WWKHK0UMq0xC/keXsnmvo89lMRdRbknPt2ZX5Flgyjgr4Rt0KtDvpL/hG4BUsTWryUZZMKxdd6DkZXYRtTogLUfHeDYIz+cZQ0aXGMtvX/ZYTXJfMi6FYbIHY/qEEDnWhDX5y+SPpaJaZByPsvzi+qbfcFGnJ6nqi9ccyZYnYpnI2IVBM/yO/VRXWHxfqvJ0VVvv5KsGmVbko2Jxo0SDCxUL2UTH2+eol53FxhkkC+m2geC14k1zsZQLHDF3BgAG9+kFJ4UEoYRKF2Gy1FxeDCJtjYNdrYR8fdaUKRMcpBgEs+ZGe2U9EVVS/ZcBCjB7S+1Ne2bPzPFzTQPuBoMgggo1xbxBmQ5NyhYo4gwgj/xjSLIhb+5h7ioN1URfSRcfYdVv6RRO9l/u9l09jEom8y/jGRviefpEr+/e9iAl5Dd/6nzQgosBQja3NSfqYZmyuet2eI9zu61CObDTpR6yaCbNgBe/lWofRfULdpJpgjb4UNTBom3q82FcCiOe02OekGPw4+YlilhICBhajF5JzN8FKAdqI1osDcX3KuJgikYIW3voNaOP5YN3GXgilJNdou20KFC8ICq68HglgX7/0rLrWKIEoswnINIM6HcJbQuXncVPwQhV6K34Hlt/Na60=");
private Property _skinProperty;
private String _skinValue;
private String _skinSignature;
private Property _skinProperty = null;
public SkinData(String value, String signature)
{
_skinProperty = new Property("textures", value, signature);
_skinValue = value;
_skinSignature = signature;
//_skinProperty = new Property("textures", value, signature);
}
private SkinData(GameProfile profile)
@ -90,6 +82,11 @@ public class SkinData
_skinProperty = profile.getProperties().get("textures").iterator().next();
}
private void getSkinProperty()
{
_skinProperty = new Property("textures", _skinValue, _skinSignature);
}
public ItemStack getSkull()
{
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
@ -124,6 +121,10 @@ public class SkinData
public Property getProperty()
{
if (_skinProperty == null)
{
getSkinProperty();
}
return new Property(_skinProperty.getName(), _skinProperty.getValue(), _skinProperty.getSignature());
}

View File

@ -1,8 +1,9 @@
package mineplex.core.common.util;
import org.bukkit.ChatColor;
import mineplex.core.common.Rank;
import mineplex.core.common.currency.Currency;
import org.bukkit.ChatColor;
public class F
{
@ -27,6 +28,11 @@ public class F
return C.mGame + elem + C.mBody;
}
public static String color(String msg, String color)
{
return color + msg + C.mBody;
}
public static String ta(String message)
{
return C.cGreen + message + C.cWhite;
@ -223,4 +229,9 @@ public class F
return C.cClansNether + word + C.mBody;
}
public static String greenElem(String text)
{
return C.cGreen + text + ChatColor.RESET + C.mBody;
}
}

View File

@ -19,6 +19,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockPosition;
@ -288,6 +289,16 @@ public class MapUtil
}
}
public static BlockPosition getBlockPos(Location loc)
{
return getBlockPos(loc.toVector());
}
public static BlockPosition getBlockPos(Vector v)
{
return getBlockPos(v.getBlockX(), v.getBlockY(), v.getBlockZ());
}
public static BlockPosition getBlockPos(int x, int y, int z)
{
return new BlockPosition(x, y, z);

View File

@ -606,10 +606,10 @@ public class UtilBlock
}
public static ArrayList<Block> getInBoundingBox(Location a, Location b, boolean ignoreAir) {
return getInBoundingBox(a, b, ignoreAir, false, true, true);
return getInBoundingBox(a, b, ignoreAir, false, false, false);
}
public static ArrayList<Block> getInBoundingBox(Location a, Location b, boolean ignoreAir, boolean hollow, boolean walls, boolean ceilfloor)
public static ArrayList<Block> getInBoundingBox(Location a, Location b, boolean ignoreAir, boolean hollow, boolean wallsOnly, boolean ceilfloorOnly)
{
ArrayList<Block> blocks = new ArrayList<Block>();
@ -626,26 +626,25 @@ public class UtilBlock
for (int y = ymin; y <= ymax; y++)
for (int z = zmin; z <= zmax; z++)
{
if(hollow)
{
if(!(x == xmin || x == xmax || y == ymin || y == ymax || z == zmin || z == zmax)) continue;
}
if(!walls)
if(wallsOnly)
{
if(
(x == xmin || x == xmax) ||
(z == zmin || z == zmax)
(x != xmin && x != xmax) &&
(z != zmin && z != zmax)
)
{
continue;
}
}
if(!ceilfloor)
if(ceilfloorOnly)
{
if(y == ymin || y == ymax)
if(y != ymin && y != ymax)
{
continue;
}

View File

@ -1,8 +1,16 @@
package mineplex.core.common.util;
import java.util.*;
import net.minecraft.server.v1_8_R3.*;
import mineplex.core.common.MinecraftVersion;
import mineplex.core.common.events.PlayerMessageEvent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ClickEvent.Action;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldBorder;
import net.minecraft.server.v1_8_R3.PlayerConnection;
import net.minecraft.server.v1_8_R3.WorldBorder;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -20,8 +28,17 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.Vector;
import mineplex.core.common.MinecraftVersion;
import mineplex.core.common.events.PlayerMessageEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
public class UtilPlayer
{
@ -179,7 +196,7 @@ public class UtilPlayer
for (Entity entity : p.getNearbyEntities(range, range, range))
{
if (entity == p || UtilPlayer.isSpectator(entity))
if (entity == p || UtilPlayer.isSpectator(entity) || !(entity instanceof Player))
continue;
double theirDist = p.getEyeLocation().distance(entity.getLocation());
@ -945,6 +962,67 @@ public class UtilPlayer
ALLOWED_COMMANDS.remove(player.getUniqueId());
}
/**
* Sends a formatted clickable accept or deny (or view) message to a player
* Both ACCEPT and DENY will always be sent, but VIEW will only be sent when <code>viewCommand</code> is not null
*
* @param player The player to send the message to
* @param header The message header, such as Party or Game
* @param acceptCommand The command to be run if ACCEPT is clicked
* @param acceptDisplayText The text displayed when hovering over ACCEPT
* @param declineCommand The command to be run when DENY is clicked
* @param declineDisplayText The text displayed when hovering over DENY
* @param viewCommand <code>Optional</code> The command to be run when VIEW is clicked
* @param viewDisplayText <code>Optional</code> The text displayed when hovering over VIEW
*/
public static void sendAcceptOrDeny(Player player, String header,
String acceptCommand, String acceptDisplayText,
String declineCommand, String declineDisplayText,
String viewCommand, String viewDisplayText)
{
TextComponent textComponent = new TextComponent(F.main(header, "Reply: "));
TextComponent accept = new TextComponent("ACCEPT");
accept.setColor(net.md_5.bungee.api.ChatColor.GREEN);
accept.setBold(true);
accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, acceptCommand));
accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
new TextComponent(acceptDisplayText)
}));
textComponent.addExtra(accept);
textComponent.addExtra(" ");
TextComponent deny = new TextComponent("DENY");
deny.setColor(net.md_5.bungee.api.ChatColor.RED);
deny.setBold(true);
deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, declineCommand));
deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
new TextComponent(declineDisplayText)
}));
textComponent.addExtra(deny);
if(viewCommand != null)
{
textComponent.addExtra(" ");
TextComponent view = new TextComponent("VIEW");
view.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
view.setBold(true);
view.setClickEvent(new ClickEvent(Action.RUN_COMMAND, viewCommand));
if(viewDisplayText != null)
{
view.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
new TextComponent(viewDisplayText)
}));
}
textComponent.addExtra(view);
}
player.spigot().sendMessage(textComponent);
}
/*
* Returns whether the UUID belongs to a slim skin
*/

View File

@ -47,7 +47,7 @@
<dependency>
<groupId>com.mineplex</groupId>
<artifactId>anticheat</artifactId>
<version>1.0</version>
<version>1.1</version>
</dependency>
</dependencies>

View File

@ -2,14 +2,15 @@ package mineplex.core.antihack;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.AtomicDouble;
import com.mineplex.anticheat.api.GameEndEvent;
import com.mineplex.anticheat.api.GameStartEvent;
import com.mineplex.anticheat.api.MineplexLink;
import com.mineplex.anticheat.api.PlayerViolationEvent;
import mineplex.core.PlayerSelector;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin;
import mineplex.core.PlayerSelector;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
@ -21,18 +22,11 @@ import mineplex.core.antihack.types.Reach;
import mineplex.core.antihack.types.Speed;
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.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.*;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseBase;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.punish.Category;
import mineplex.core.punish.Punish;
@ -41,44 +35,23 @@ import mineplex.core.punish.Punishment;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.commands.ServerCommandManager;
import net.minecraft.server.v1_8_R3.ChatClickable;
import net.minecraft.server.v1_8_R3.ChatComponentText;
import net.minecraft.server.v1_8_R3.ChatHoverable;
import net.minecraft.server.v1_8_R3.ChatModifier;
import net.minecraft.server.v1_8_R3.EnumChatFormat;
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
import net.minecraft.server.v1_8_R3.MathHelper;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.*;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@ -89,7 +62,14 @@ import java.util.function.Predicate;
@ReflectivelyCreateMiniPlugin
public class AntiHack extends MiniPlugin
{
public static final boolean IS_PHASE_TWO = false;
public static final Map<String, CheckThresholds> CHECKS = ImmutableMap.of(
"Killaura (Type A)", new CheckThresholds("Kill Aura", 25, 50),
"Killaura (Type B)", new CheckThresholds("High CPS", 0, Integer.MAX_VALUE),
"Killaura (Type C)", new CheckThresholds("Reach", Integer.MAX_VALUE, Integer.MAX_VALUE),
"Killaura (Type D)", new CheckThresholds("Kill Aura", 1000, 1500),
"BadPackets", new CheckThresholds("Regen", 1000, 2000)
);
public static final String NAME = "Chiss";
public static final String USER_HAS_BEEN_BANNED = F.main("GWEN", "%s has been banned. I am always watching");
public static final String USER_HAS_BEEN_BANNED_BANWAVE = USER_HAS_BEEN_BANNED;
@ -190,78 +170,27 @@ public class AntiHack extends MiniPlugin
DisguiseBase disguise = disguiseManager.getActiveDisguise(player);
return disguise != null ? disguise.getDisguiseType() : null;
}
@Override
public boolean isSpectator(Player player)
{
return UtilPlayer.isSpectator(player);
}
}, this._plugin, ServicePriority.Normal);
ServerCommandManager.getInstance().registerCommandType(MajorViolationCommand.class, violation ->
{
if (!violation.getOriginatingServer().equals(this._thisServer))
{
IChatBaseComponent component = new ChatComponentText("")
.addSibling(
new ChatComponentText("A")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.AQUA)
.setRandom(true)
)
)
.addSibling(
new ChatComponentText(" GWEN > ")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.RED)
.setBold(true)
)
)
.addSibling(
new ChatComponentText(violation.getPlayerName())
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.GOLD)
)
)
.addSibling(
new ChatComponentText(" failed " + violation.getHackType() + " VL" + violation.getViolations() + " in server ")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.YELLOW)
)
)
.addSibling(
new ChatComponentText(
violation.getOriginatingServer()
)
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.YELLOW)
.setChatClickable(
new ChatClickable(
ChatClickable.EnumClickAction.RUN_COMMAND,
"/server " + violation.getOriginatingServer()
)
)
.setChatHoverable(
new ChatHoverable(
ChatHoverable.EnumHoverAction.SHOW_TEXT,
new ChatComponentText("Teleport to " + violation.getOriginatingServer())
)
)
)
)
.addSibling(
new ChatComponentText(": " + violation.getMessage() + ". Please investigate")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.YELLOW)
)
);
IChatBaseComponent component = getMinimalMessage(violation);
for (Player player : Bukkit.getOnlinePlayers())
for (Player player : Bukkit.getOnlinePlayers())
{
if (player.getName().equals("Spoobncoobr"))
{
if (Managers.get(PreferencesManager.class).Get(player).ShowMacReports && _clientManager.Get(player).GetRank().has(Rank.HELPER))
{
((CraftPlayer) player).getHandle().sendMessage(component);
}
((CraftPlayer) player).getHandle().sendMessage(getDetailedMessage(violation));
} else if (_clientManager.Get(player).GetRank().has(Rank.HELPER) && (violation.getOriginatingServer().equals(_thisServer) || Managers.get(PreferencesManager.class).get(player).isActive(Preference.GLOBAL_GWEN_REPORTS)))
{
((CraftPlayer) player).getHandle().sendMessage(component);
}
}
});
@ -349,6 +278,144 @@ public class AntiHack extends MiniPlugin
require(BanWaveManager.class);
}
private IChatBaseComponent getDetailedMessage(MajorViolationCommand violation)
{
return new ChatComponentText("")
.addSibling(
new ChatComponentText("A")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.AQUA)
.setRandom(true)
)
)
.addSibling(
new ChatComponentText(" GWEN > ")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.RED)
.setBold(true)
)
)
.addSibling(
new ChatComponentText(violation.getPlayerName())
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.GOLD)
)
)
.addSibling(
new ChatComponentText(" failed " + violation.getHackType() + " VL" + violation.getViolations() + " in server ")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.YELLOW)
)
)
.addSibling(
new ChatComponentText(
violation.getOriginatingServer()
)
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.YELLOW)
.setChatClickable(
new ChatClickable(
ChatClickable.EnumClickAction.RUN_COMMAND,
"/server " + violation.getOriginatingServer()
)
)
.setChatHoverable(
new ChatHoverable(
ChatHoverable.EnumHoverAction.SHOW_TEXT,
new ChatComponentText("Teleport to " + violation.getOriginatingServer())
)
)
)
)
.addSibling(
new ChatComponentText(": " + violation.getMessage() + ". Please investigate!")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.YELLOW)
)
);
}
private IChatBaseComponent getMinimalMessage(MajorViolationCommand violation)
{
IChatBaseComponent component = new ChatComponentText("")
.addSibling(
new ChatComponentText("A")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.AQUA)
.setRandom(true)
)
)
.addSibling(
new ChatComponentText(" GWEN > ")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.RED)
.setBold(true)
)
)
.addSibling(
new ChatComponentText(violation.getPlayerName())
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.GOLD)
)
)
.addSibling(
new ChatComponentText(" suspected of ")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.YELLOW)
)
)
.addSibling(CHECKS.get(violation.getHackType()).format(violation.getViolations()));
if (!violation.getOriginatingServer().equals(this._thisServer))
{
component
.addSibling(
new ChatComponentText(" in ")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.YELLOW)
)
)
.addSibling(
new ChatComponentText(violation.getOriginatingServer())
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.AQUA)
.setChatClickable(
new ChatClickable(
ChatClickable.EnumClickAction.RUN_COMMAND,
"/server " + violation.getOriginatingServer()
)
)
.setChatHoverable(
new ChatHoverable(
ChatHoverable.EnumHoverAction.SHOW_TEXT,
new ChatComponentText("Teleport to " + violation.getOriginatingServer())
)
)
)
);
}
return component.addSibling(
new ChatComponentText(". Please investigate!")
.setChatModifier(
new ChatModifier()
.setColor(EnumChatFormat.YELLOW)
)
);
}
public void registerFilter(Predicate<Player> filter)
{
if (filter == null)
@ -376,9 +443,6 @@ public class AntiHack extends MiniPlugin
public void runBanAnimation(Player player, Runnable after)
{
if (!IS_PHASE_TWO)
return;
if (_pendingBan.add(player))
{
float oldWalkSpeed = player.getWalkSpeed();
@ -489,19 +553,17 @@ public class AntiHack extends MiniPlugin
{
runSync(() ->
{
int totalPunishments = getPunishments(player);
int daysBanned = getDaysBanned(player);
CoreClient coreClient = _clientManager.Get(player);
if (coreClient.GetRank().has(Rank.TWITCH))
{
require(Punish.class).AddPunishment(coreClient.getName(), Category.Hacking, message, AntiHack.NAME, totalPunishments + 1, true, daysBanned == -1 ? -1 : TimeUnit.DAYS.toHours(daysBanned), true);
require(Punish.class).AddPunishment(coreClient.getName(), Category.Hacking, message, AntiHack.NAME, 3, true, -1, true);
}
else
{
runBanAnimation(player, () ->
{
require(Punish.class).AddPunishment(coreClient.getName(), Category.Hacking, message, AntiHack.NAME, totalPunishments + 1, true, daysBanned == -1 ? -1 : TimeUnit.DAYS.toHours(daysBanned), true);
require(Punish.class).AddPunishment(coreClient.getName(), Category.Hacking, message, AntiHack.NAME, 3, true, -1, true);
announceBan(player);
});
}
@ -570,10 +632,7 @@ public class AntiHack extends MiniPlugin
@EventHandler
public void on(PlayerViolationEvent event)
{
if (IS_PHASE_TWO)
{
AntiHackAction.getAction(event.getCheckClass()).handle(event);
}
AntiHackAction.getAction(event.getCheckClass()).handle(event);
}
public void announceBan(Player player)
@ -912,21 +971,9 @@ public class AntiHack extends MiniPlugin
@EventHandler
public void onHack(PlayerViolationEvent event)
{
for (Player player : Bukkit.getOnlinePlayers())
{
CoreClient client = _clientManager.Get(player);
if (event.shouldTellStaff())
{
if (client.GetRank().has(Rank.HELPER))
{
UtilPlayer.message(player, C.cAqua + C.Scramble + "A" + ChatColor.RESET + C.cRed + C.Bold + " GWEN > " + ChatColor.RESET + C.cGold + event.getPlayer().getName() + C.cYellow + " failed " + event.getHackType() + " VL" + event.getViolations() + ": " + event.getMessage() + ". Please investigate");
}
}
}
if (event.shouldTellStaff())
{
String key = event.getPlayer().getName() + "." + event.getHackType();
String key = event.getPlayer().getName() + "." + event.getHackType() + "." + CHECKS.get(event.getHackType()).getSeverity(event.getViolations()).toString();
Integer pastVl = this._cooldown.getIfPresent(key);
if (pastVl != null)
{

View File

@ -0,0 +1,61 @@
package mineplex.core.antihack;
import net.minecraft.server.v1_8_R3.ChatComponentText;
import net.minecraft.server.v1_8_R3.ChatModifier;
import net.minecraft.server.v1_8_R3.EnumChatFormat;
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
public class CheckThresholds
{
private final String _friendlyName;
private final int _med;
private final int _high;
public CheckThresholds(String friendlyName, int med, int high)
{
_friendlyName = friendlyName;
_med = med;
_high = high;
}
public String getFriendlyName()
{
return _friendlyName;
}
public IChatBaseComponent format(int violationLevel)
{
EnumChatFormat color = getSeverity(violationLevel)._color;
return new ChatComponentText(_friendlyName).setChatModifier(new ChatModifier().setColor(color));
}
public Severity getSeverity(int violationLevel)
{
if (violationLevel >= _high)
{
return Severity.HIGH;
} else if (violationLevel >= _med)
{
return Severity.MEDIUM;
} else
{
return Severity.LOW;
}
}
public enum Severity
{
LOW(EnumChatFormat.GREEN),
MEDIUM(EnumChatFormat.GOLD),
HIGH(EnumChatFormat.RED),
;
private final EnumChatFormat _color;
Severity(EnumChatFormat color)
{
_color = color;
}
}
}

View File

@ -2,9 +2,6 @@ package mineplex.core.antihack.actions;
import com.mineplex.anticheat.api.PlayerViolationEvent;
import com.mineplex.anticheat.checks.combat.KillauraTypeA;
import com.mineplex.anticheat.checks.combat.KillauraTypeB;
import com.mineplex.anticheat.checks.combat.KillauraTypeD;
import com.mineplex.anticheat.checks.player.BadPackets;
import mineplex.core.common.util.UtilServer;
import org.bukkit.event.Listener;
@ -22,10 +19,7 @@ public abstract class AntiHackAction implements Listener
static
{
ACTIONS.put(KillauraTypeA.class, new ImmediateBanAction(60));
ACTIONS.put(KillauraTypeB.class, new BanwaveAction(NEXT_BAN_WAVE, 50));
ACTIONS.put(KillauraTypeD.class, new BanwaveAction(NEXT_BAN_WAVE, 550));
ACTIONS.put(BadPackets.class, new MixedAction(new BanwaveAction(NEXT_BAN_WAVE, 80), new ImmediateBanAction(120)));
ACTIONS.put(KillauraTypeA.class, new ImmediateBanAction(200));
}
private int _vl;

View File

@ -3,10 +3,7 @@ package mineplex.core.antihack.actions;
import com.mineplex.anticheat.api.PlayerViolationEvent;
import mineplex.core.Managers;
import mineplex.core.antihack.AntiHack;
import mineplex.core.punish.Category;
import mineplex.core.punish.Punish;
import java.util.concurrent.TimeUnit;
import mineplex.core.common.util.UtilServer;
class ImmediateBanAction extends AntiHackAction
{
@ -20,7 +17,12 @@ class ImmediateBanAction extends AntiHackAction
{
if (event.getViolations() >= this.getMinVl())
{
Managers.get(AntiHack.class).doBan(event.getPlayer(), event.getMessage());
String server = UtilServer.getServerName();
if (server.contains("-"))
{
server = server.substring(0, server.indexOf('-'));
}
Managers.get(AntiHack.class).doBan(event.getPlayer(), "[GWEN] Hacking - " + AntiHack.CHECKS.get(event.getHackType()).getFriendlyName() + " [" + server + "]");
}
}
}

View File

@ -24,11 +24,6 @@ public class BanWaveManager extends MiniPlugin
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
if (!AntiHack.IS_PHASE_TWO)
{
return;
}
runAsync(() ->
{
CoreClient client = require(CoreClientManager.class).Get(event.getPlayer());

View File

@ -0,0 +1,21 @@
package mineplex.core.antispam;
import mineplex.core.common.api.ApiResponse;
/**
* @author Shaun Bennett
*/
public class AntiSpamApiResponse extends ApiResponse
{
private boolean isShadowMuted;
public AntiSpamApiResponse()
{
}
public boolean isShadowMuted()
{
return isShadowMuted;
}
}

View File

@ -0,0 +1,74 @@
package mineplex.core.antispam;
import mineplex.core.MiniPlugin;
import mineplex.core.antispam.repository.AntiSpamRepository;
import mineplex.core.chat.IChatMessageFormatter;
import mineplex.core.status.ServerStatusManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
/**
* @author Shaun Bennett
*/
public class AntiSpamManager extends MiniPlugin
{
private final String _pluginName;
private final String _serverName;
private final String _region;
private final AntiSpamRepository _repository;
private IChatMessageFormatter _messageFormatter;
public AntiSpamManager()
{
super("AntiSpam");
_pluginName = getPlugin().getClass().getSimpleName();
_repository = new AntiSpamRepository();
ServerStatusManager serverStatusManager = require(ServerStatusManager.class);
if (serverStatusManager != null)
{
_serverName = serverStatusManager.getCurrentServerName();
_region = serverStatusManager.getRegion().name();
}
else
{
_serverName = "Unknown";
_region = "Unknown";
}
}
public void setMessageFormatter(IChatMessageFormatter messageFormatter)
{
_messageFormatter = messageFormatter;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onChat(AsyncPlayerChatEvent event)
{
// Only listen to async events, as non async events are fake messages
if (event.isAsynchronous())
{
Player player = event.getPlayer();
String message = event.getMessage();
ChatPayload payload = new ChatPayload(player.getName(), player.getUniqueId().toString(), _region, _serverName, message, System.currentTimeMillis());
// Run our API call async to the chat message (prevents blocking chat message)
AntiSpamApiResponse response = _repository.sendMessage(_pluginName, payload);
if (response != null) // can be null if the request times out
{
if (response.isShadowMuted())
{
event.setCancelled(true);
if (_messageFormatter != null)
{
String formattedMessage = String.format(_messageFormatter.getChatFormat(player, message).getFormat(), player.getName(), message);
event.getPlayer().sendMessage(formattedMessage);
}
}
}
}
}
}

View File

@ -0,0 +1,126 @@
package mineplex.core.antispam;
/**
* @author Shaun Bennett
*/
public class ChatPayload
{
private String _playerName;
private String _uuid;
private String _region;
private String _server;
private String _message;
private long _time;
public ChatPayload(String playerName, String uuid, String region, String server, String message, long time)
{
_playerName = playerName;
_uuid = uuid;
_region = region;
_server = server;
_message = message;
_time = time;
}
public String getPlayerName()
{
return _playerName;
}
public void setPlayerName(String playerName)
{
_playerName = playerName;
}
public String getUuid()
{
return _uuid;
}
public void setUuid(String uuid)
{
_uuid = uuid;
}
public String getMessage()
{
return _message;
}
public void setMessage(String message)
{
_message = message;
}
public String getServer()
{
return _server;
}
public void setServer(String server)
{
_server = server;
}
public long getTime()
{
return _time;
}
public void setTime(long time)
{
_time = time;
}
public String getRegion()
{
return _region;
}
public void setRegion(String region)
{
_region = region;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ChatPayload payload = (ChatPayload) o;
if (_time != payload._time) return false;
if (!_playerName.equals(payload._playerName)) return false;
if (!_uuid.equals(payload._uuid)) return false;
if (!_region.equals(payload._region)) return false;
if (!_server.equals(payload._server)) return false;
return _message.equals(payload._message);
}
@Override
public int hashCode()
{
int result = _playerName.hashCode();
result = 31 * result + _uuid.hashCode();
result = 31 * result + _region.hashCode();
result = 31 * result + _server.hashCode();
result = 31 * result + _message.hashCode();
result = 31 * result + (int) (_time ^ (_time >>> 32));
return result;
}
@Override
public String toString()
{
return "ChatPayload{" +
"_playerName='" + _playerName + '\'' +
", _uuid='" + _uuid + '\'' +
", _region='" + _region + '\'' +
", _server='" + _server + '\'' +
", _message='" + _message + '\'' +
", _time=" + _time +
'}';
}
}

View File

@ -0,0 +1,27 @@
package mineplex.core.antispam.repository;
import com.google.gson.Gson;
import mineplex.core.antispam.AntiSpamApiResponse;
import mineplex.core.antispam.ChatPayload;
import mineplex.core.common.api.ApiEndpoint;
import mineplex.core.common.api.ApiHost;
import mineplex.core.common.api.ApiResponse;
import mineplex.core.thread.ThreadPool;
import java.util.Random;
/**
* @author Shaun Bennett
*/
public class AntiSpamRepository extends ApiEndpoint
{
public AntiSpamRepository()
{
super(ApiHost.ANTISPAM, "/chat");
}
public AntiSpamApiResponse sendMessage(String source, ChatPayload payload)
{
return getWebCall().post("/" + source, AntiSpamApiResponse.class, payload);
}
}

View File

@ -8,10 +8,12 @@ import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.bonuses.animations.AnimationCarl;
import mineplex.core.bonuses.commands.AnimationCommand;
import mineplex.core.bonuses.commands.GuiCommand;
import mineplex.core.bonuses.commands.PowerPlayCommand;
import mineplex.core.bonuses.commands.TicketCommand;
import mineplex.core.bonuses.event.CarlSpinnerEvent;
import mineplex.core.bonuses.gui.BonusGui;
import mineplex.core.bonuses.gui.SpinGui;
import mineplex.core.bonuses.gui.buttons.PowerPlayClubButton;
import mineplex.core.bonuses.redis.VoteHandler;
import mineplex.core.bonuses.redis.VotifierCommand;
import mineplex.core.common.Rank;
@ -30,6 +32,7 @@ import mineplex.core.npc.Npc;
import mineplex.core.npc.NpcManager;
import mineplex.core.pet.PetManager;
import mineplex.core.poll.PollManager;
import mineplex.core.powerplayclub.PowerPlayClubRepository;
import mineplex.core.recharge.Recharge;
import mineplex.core.reward.RewardManager;
import mineplex.core.stats.StatsManager;
@ -123,6 +126,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
private StatsManager _statsManager;
private FacebookManager _facebookManager;
private YoutubeManager _youtubeManager;
private PowerPlayClubRepository _powerPlayClubRepository;
private ThankManager _thankManager;
public boolean _enabled;
private Npc _carlNpc;
@ -150,6 +154,10 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_repository = new BonusRepository(plugin, this, donationManager);
_clientManager = clientManager;
_donationManager = donationManager;
_powerPlayClubRepository = new PowerPlayClubRepository(plugin, clientManager);
System.out.print("VOTIFIER: ");
System.out.print("DONATION MANAGER - > " + _donationManager.toString());
_voteList = new ArrayList<String>();
_voteList.add("http://vote1.mineplex.com");
@ -173,6 +181,11 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_inventoryManager = inventoryManager;
_thankManager = thankManager;
if (gadgetManager == null)
{
System.out.print("GM NULL");
}
_rewardManager = new RewardManager(_clientManager, _donationManager, _inventoryManager, petManager, statsManager, gadgetManager);
_pollManager = pollManager;
@ -180,6 +193,8 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_facebookManager = facebookManager;
_youtubeManager = youtubeManager;
_powerPlayClubRepository = new PowerPlayClubRepository(plugin, _clientManager);
_voteList = new ArrayList<String>();
_voteList.add("http://vote1.mineplex.com");
_voteList.add("http://vote2.mineplex.com");
@ -226,6 +241,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
addCommand(new GuiCommand(this));
addCommand(new AnimationCommand(this));
addCommand(new TicketCommand(this));
addCommand(new PowerPlayCommand(this));
}
// Just keeping things up-to-date
@ -508,7 +524,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
}
else
{
UtilPlayer.message(player, F.main("Carl", "There waa an error processing your request. Try again later"));
UtilPlayer.message(player, F.main("Carl", "There was an error processing your request. Try again later"));
}
}
});
@ -909,6 +925,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (getPollManager().getNextPoll(_pollManager.Get(player), _clientManager.Get(player).GetRank()) != null) availableRewards++;
if (!_facebookManager.hasRedeemed(player)) availableRewards++;
if (_thankManager.Get(player).getThankToClaim() > 0) availableRewards++;
if (PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository)) availableRewards++;
Hologram hologram;
@ -1091,7 +1108,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{
if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false))
{
if(_pollManager.hasPoll(player) || canVote(player) || (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) || canDaily(player))
if(_pollManager.hasPoll(player) || canVote(player) || (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) || canDaily(player) || PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository))
{
if(_showCarl.containsKey(player.getName()))
{
@ -1199,4 +1216,19 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
return _thankManager;
}
public DonationManager getDonationManager()
{
return _donationManager;
}
public PowerPlayClubRepository getPowerPlayClubRepository()
{
return _powerPlayClubRepository;
}
public InventoryManager getInventoryManager()
{
return _inventoryManager;
}
}

View File

@ -2,33 +2,25 @@ package mineplex.core.bonuses.animations;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilServer;
import mineplex.core.bonuses.powerplay.PowerPlayAnimation;
import mineplex.core.common.skin.SkinData;
import mineplex.core.common.util.*;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.reward.Reward;
import mineplex.core.reward.RewardData;
import mineplex.core.reward.RewardRarity;
import mineplex.core.treasure.animation.Animation;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Color;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
@ -78,7 +70,7 @@ public class AnimationCarl extends Animation
}
}
if(!((String) _type).contentEquals("DAILY")&& !((String) _type).contentEquals("RANK")&& !((String) _type).contentEquals("POLL"))
if(!((String) _type).contentEquals("DAILY") && !((String) _type).contentEquals("RANK") && !((String) _type).contentEquals("POLL"))
{
Item paper = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.PAPER, (byte) 0, 1, " " + 64));
@ -130,6 +122,37 @@ public class AnimationCarl extends Animation
finish();
}
}
if (_type instanceof PowerPlayAnimation)
{
for (int i = 50; i < 65; i++)
{
// Gem amplifier
Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i));
_items.add(gem);
Vector vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d));
UtilAction.velocity(gem, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false);
// Omega chest
Item omega = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), SkinData.OMEGA_CHEST.getSkull());
_items.add(omega);
vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d));
UtilAction.velocity(omega, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false);
// Monthly items
PowerPlayAnimation powerPlayAnimation = (PowerPlayAnimation) _type;
for (ItemStack itemStack : powerPlayAnimation.getAnimationItems())
{
Item monthly = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), itemStack);
_items.add(monthly);
vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d));
UtilAction.velocity(monthly, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false);
}
}
finish();
}
}
@Override

View File

@ -0,0 +1,45 @@
package mineplex.core.bonuses.commands;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.time.LocalDate;
public class PowerPlayCommand extends CommandBase<BonusManager>
{
private BonusManager _bonusManager;
public PowerPlayCommand(BonusManager manager)
{
super(manager, Rank.JNR_DEV, "powerplay");
_bonusManager = manager;
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length < 1)
{
UtilPlayer.message(caller, F.main("Power Play Club", "Missing Args: " + F.elem("/powerplay <player>")));
return;
}
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
caller.sendMessage(ChatColor.RED + "Couldn't find player");
return;
}
_bonusManager.getPowerPlayClubRepository().Get(player).setSubscribed(true);
_bonusManager.getPowerPlayClubRepository().addSubscription(_bonusManager.getClientManager().Get(player).getAccountId(), LocalDate.now(), "month");
caller.sendMessage(ChatColor.GREEN + "Gave a month's subscription to " + player.getName());
}
}

View File

@ -37,7 +37,9 @@ public class BonusGui extends SimpleGui
setItem(25, new ClaimTipsButton(getPlugin(), player, this, manager, thankManager));
setItem(31, new CarlSpinButton(getPlugin(), player, manager, rewardManager));
setItem(29, new PowerPlayClubButton(player, manager));
setItem(33, new CarlSpinButton(getPlugin(), player, manager, rewardManager));
}
@Override

View File

@ -0,0 +1,134 @@
package mineplex.core.bonuses.gui.buttons;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.gui.GuiItem;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.powerplayclub.PowerPlayClubRepository;
import mineplex.core.powerplayclub.PowerPlayClubRewards;
import mineplex.core.shop.item.ShopItem;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
public class PowerPlayClubButton implements GuiItem
{
private ItemStack _item;
private Player _player;
private PowerPlayClubRepository _powerPlayClubRepository;
private InventoryManager _inventoryManager;
private BonusManager _bonusManager;
public PowerPlayClubButton(Player player, BonusManager manager)
{
_player = player;
_bonusManager = manager;
_powerPlayClubRepository = manager.getPowerPlayClubRepository();
_inventoryManager = manager.getInventoryManager();
}
@Override
public void setup()
{
setItem();
}
@Override
public void close()
{
}
@Override
public void click(ClickType clickType)
{
if (isAvailable() && !_bonusManager.getPowerPlayClubRepository().alreadyClaimed(_player))
{
_player.closeInventory();
_player.playSound(_player.getLocation(), Sound.NOTE_PLING, 1, 1.6f);
PowerPlayClubRewards.giveAllItems(_player, _inventoryManager, _powerPlayClubRepository);
}
else
{
_player.playSound(_player.getLocation(), Sound.ITEM_BREAK, 1, 10);
if (_powerPlayClubRepository.alreadyClaimed(_player))
{
UtilPlayer.message(_player, F.main("Power Play Club", "Already claimed!"));
}
else
{
UtilPlayer.message(_player, F.main("Power Play Club", "You have no months left! Buy more months at " + C.cAqua + "www.mineplex.com/shop" + C.Reset + "!"));
}
}
}
@Override
public ItemStack getObject()
{
return _item;
}
private void setItem()
{
ArrayList<String> lore = new ArrayList<>();
Material material;
byte data = 0;
String itemName;
if (isAvailable())
{
material = Material.GOLD_INGOT;
itemName = C.cGreenB + "Power Play Club";
lore.add("");
lore.add(C.Reset + "Click to claim!");
}
else
{
material = Material.REDSTONE_BLOCK;
itemName = C.cRedB + "Power Play Club";
}
lore.add(C.cYellow + "Rewards");
lore.add(" " + C.cWhite + "2 Game Amplifiers");
lore.add(" " + C.cWhite + "1 Omega Chest");
for (PowerPlayClubRewards.PowerPlayClubItem prize : PowerPlayClubRewards.septemberItems())
{
lore.add(" " + C.cWhite + prize.getAmount() + " " + prize.getPrize());
}
//lore.add(" ");
//lore.add(C.cYellow + "Months left: " + C.cWhite + getMonthsLeft(true)); //TODO: figure this out
if (!isAvailable())
{
lore.add(" ");
if (_powerPlayClubRepository.alreadyClaimed(_player))
{
lore.add(C.cRed + "Already claimed!");
}
else
{
lore.add(C.cRed + "Get Power Play Club months at");
lore.add(C.cAqua + "mineplex.com/shop");
}
}
_item = new ShopItem(material, data, itemName, lore.toArray(new String[0]), 1, false, false);
}
private boolean isAvailable()
{
return _powerPlayClubRepository.canClaim(_player);
}
public static boolean isAvailable(Player player, PowerPlayClubRepository repo)
{
return repo.canClaim(player);
}
}

View File

@ -0,0 +1,29 @@
package mineplex.core.bonuses.powerplay;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class PowerPlayAnimation
{
private List<ItemStack> _animationItems;
private Player _player;
public PowerPlayAnimation(Player player, List<ItemStack> animationItems)
{
_animationItems = animationItems;
_player = player;
}
public List<ItemStack> getAnimationItems()
{
return _animationItems;
}
public Player getPlayer()
{
return _player;
}
}

View File

@ -7,6 +7,7 @@ import com.google.gson.JsonObject;
import com.mojang.authlib.properties.PropertyMap;
import mineplex.core.common.api.ApiEndpoint;
import mineplex.core.common.api.ApiFieldNamingStrategy;
import mineplex.core.common.api.ApiHost;
import mineplex.core.common.api.ApiResponse;
import java.util.Arrays;
@ -23,7 +24,7 @@ public class BoosterRepository extends ApiEndpoint
{
public BoosterRepository()
{
super("/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
super(ApiHost.AMPLIFIERS, "/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
// .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create());
}

View File

@ -12,19 +12,13 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramManager;
import mineplex.core.stats.StatsManager;
import mineplex.core.thread.ThreadPool;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.Region;
import mineplex.serverdata.redis.counter.GoalCounter;
import mineplex.serverdata.redis.counter.GoalCounterListener;
import mineplex.serverdata.servers.ConnectionData;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import java.io.File;
import java.io.IOException;
@ -63,7 +57,7 @@ public class Fountain implements GoalCounterListener
_name = name;
_dataKey = dataKey;
_location = location;
_hologram = new Hologram(hologramManager, location.clone().add(4, 3, -3), name).start();
_hologram = new Hologram(hologramManager, new Location(location.getWorld(), -23, 75, 3), name).start();
_counter = new GoalCounter(writeConnection, readConnection, region, dataKey, goal);
_counter.addListener(this);
_brawlActive = false;
@ -128,7 +122,7 @@ public class Fountain implements GoalCounterListener
}
_hologram.setText(text.toArray(new String[text.size()]));
_schematicLoader.update(fillPercent);
//_schematicLoader.update(fillPercent);
}
else
{

View File

@ -3,31 +3,24 @@ package mineplex.core.brawl.fountain;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.brawl.fountain.command.FountainCommand;
import mineplex.core.brawl.fountain.gui.FountainShop;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.donation.DonationManager;
import mineplex.core.hologram.HologramManager;
import mineplex.core.locations.LocationConstants;
import mineplex.core.stats.StatsManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.Region;
import mineplex.serverdata.redis.counter.Counter;
import mineplex.serverdata.servers.ConnectionData;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
/**
* @author Shaun Bennett
*/
@ -55,7 +48,7 @@ public class FountainManager extends MiniPlugin
int goal = 70000000;//!new File("eu.dat").exists() ? 200000000 : 20000000;
_gemFountain = new Fountain(new ConnectionData("10.3.203.80", 6379, ConnectionData.ConnectionType.MASTER, "USRedis"),
new ConnectionData("10.3.203.80", 6377, ConnectionData.ConnectionType.SLAVE, "USRedis"), Region.ALL,
new Location(world, -32.5, 72, -23.5), new Location(world, -43.5, 67, -38.5),
LocationConstants.FOUNTAIN_LOCATION, LocationConstants.FOUNTAIN_SCHEMATIC,
C.cGreen + "Gem Fountain", "GemFountain_01", goal, this, clientManager, donationManager, _hologramManager, _statsManager);
}

View File

@ -3,6 +3,7 @@ package mineplex.core.chat;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.antispam.AntiSpamManager;
import mineplex.core.chat.command.BroadcastCommand;
import mineplex.core.chat.command.ChatSlowCommand;
import mineplex.core.chat.command.SilenceCommand;
@ -14,6 +15,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTime;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
@ -210,7 +212,7 @@ public class Chat extends MiniPlugin
{
for (Iterator<Player> playerIterator = event.getRecipients().iterator(); playerIterator.hasNext();)
{
if (!_preferences.Get(playerIterator.next()).ShowChat)
if (!_preferences.get(playerIterator.next()).isActive(Preference.SHOW_CHAT))
playerIterator.remove();
}
}

View File

@ -0,0 +1,39 @@
package mineplex.core.chat;
/**
* The format for a chat message being sent by a player
*
* @author Shaun Bennett
*/
public class ChatFormat
{
private String _format;
private boolean _json;
public ChatFormat(String format, boolean json)
{
_format = format;
_json = json;
}
/**
* Get the string representing the chat format. This will be represented as a JSON string if {@link #isJson()},
* or should be in the standard Spigot chat format otherwise.
*
* @return A string representing how to format the chat message
*/
public String getFormat()
{
return _format;
}
/**
* Is this chat format a JSON string (should be sent to player as a json message)
*
* @return boolean representing if this chat format is in the json format
*/
public boolean isJson()
{
return _json;
}
}

View File

@ -0,0 +1,21 @@
package mineplex.core.chat;
import org.bukkit.entity.Player;
/**
* This is an interface that provides a method to format chat message.
* Needed for AntiSpam's shadow mute feature.
*
* @author Shaun Bennett
*/
public interface IChatMessageFormatter
{
/**
* Returns the proper format for the chat message to be sent
*
* @param player Player sending the message
* @param message The message the player is trying to send
* @return the format of the chat message,
*/
public ChatFormat getChatFormat(Player player, String message);
}

View File

@ -1,56 +1,25 @@
package mineplex.core.disguise.disguises;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import mineplex.core.common.skin.SkinData;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.disguise.playerdisguise.PlayerDisguiseManager;
import mineplex.core.thread.ThreadPool;
import mineplex.core.utils.UtilGameProfile;
import net.minecraft.server.v1_8_R3.AttributeInstance;
import net.minecraft.server.v1_8_R3.AttributeMapServer;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.IInventory;
import net.minecraft.server.v1_8_R3.ITileEntityContainer;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.MobEffect;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutAbilities;
import net.minecraft.server.v1_8_R3.PacketPlayOutAnimation;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEffect;
import net.minecraft.server.v1_8_R3.PacketPlayOutExperience;
import net.minecraft.server.v1_8_R3.PacketPlayOutHeldItemSlot;
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn;
import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_8_R3.*;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
import net.minecraft.server.v1_8_R3.PacketPlayOutPosition;
import net.minecraft.server.v1_8_R3.PacketPlayOutRespawn;
import net.minecraft.server.v1_8_R3.PacketPlayOutUpdateAttributes;
import net.minecraft.server.v1_8_R3.PacketPlayOutUpdateHealth;
import net.minecraft.server.v1_8_R3.WorldSettings;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.function.Supplier;
public class DisguisePlayer extends DisguiseHuman
{

View File

@ -34,6 +34,7 @@ public class DonationManager extends MiniClientPlugin<Donor>
private NautHashMap<Player, NautHashMap<String, Integer>> _coinQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
private Queue<GiveDonorData> _coinAttemptQueue;
private final CoreClientManager _clientManager;
public DonationManager(JavaPlugin plugin, CoreClientManager clientManager, String webAddress)

View File

@ -1,13 +1,5 @@
package mineplex.core.friend;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
@ -25,10 +17,10 @@ import mineplex.core.friend.data.FriendData;
import mineplex.core.friend.data.FriendRepository;
import mineplex.core.friend.data.FriendStatus;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.data.PlayerStatus;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -36,6 +28,14 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
public class FriendManager extends MiniDbClientPlugin<FriendData>
{
private static FriendSorter _friendSorter = new FriendSorter();
@ -271,7 +271,7 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
if (friend.Status == FriendStatusType.Blocked || friend.Status == FriendStatusType.Denied)
continue;
if (!_preferenceManager.Get(caller).PendingFriendRequests && friend.Status == FriendStatusType.Pending)
if (!_preferenceManager.get(caller).isActive(Preference.PENDING_FRIEND_REQUESTS) && friend.Status == FriendStatusType.Pending)
continue;
gotAFriend = true;

View File

@ -1,12 +1,11 @@
package mineplex.core.friend.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.friend.FriendManager;
import mineplex.core.friend.ui.FriendsGUI;
import mineplex.core.preferences.Preference;
import org.bukkit.entity.Player;
public class AddFriend extends CommandBase<FriendManager>
{
@ -20,7 +19,7 @@ public class AddFriend extends CommandBase<FriendManager>
{
if (args == null || args.length < 1)
{
if (Plugin.getPreferenceManager().Get(caller).friendDisplayInventoryUI)
if (Plugin.getPreferenceManager().get(caller).isActive(Preference.FRIENDS_DISPLAY_INVENTORY_UI))
{
new FriendsGUI(Plugin, caller);
}
@ -31,14 +30,11 @@ public class AddFriend extends CommandBase<FriendManager>
}
else
{
_commandCenter.GetClientManager().checkPlayerName(caller, args[0], new Callback<String>()
_commandCenter.GetClientManager().checkPlayerName(caller, args[0], result ->
{
public void run(String result)
if (result != null)
{
if (result != null)
{
Plugin.addFriend(caller, result);
}
Plugin.addFriend(caller, result);
}
});
}

View File

@ -1,5 +1,6 @@
package mineplex.core.friend.command;
import mineplex.core.preferences.Preference;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
@ -19,15 +20,15 @@ public class FriendsDisplay extends CommandBase<FriendManager>
@Override
public void Execute(Player caller, final String[] args)
{
UserPreferences preferences = Plugin.getPreferenceManager().Get(caller);
UserPreferences preferences = Plugin.getPreferenceManager().get(caller);
preferences.friendDisplayInventoryUI = !preferences.friendDisplayInventoryUI;
preferences.toggle(Preference.FRIENDS_DISPLAY_INVENTORY_UI);
Plugin.getPreferenceManager().savePreferences(caller);
Plugin.getPreferenceManager().save(preferences);
caller.playSound(caller.getLocation(), Sound.NOTE_PLING, 1, 1.6f);
if (preferences.friendDisplayInventoryUI)
if (preferences.isActive(Preference.FRIENDS_DISPLAY_INVENTORY_UI))
{
Plugin.runAsync(() -> new FriendsGUI(Plugin, caller));
}

View File

@ -3,28 +3,16 @@ package mineplex.core.gadget;
import java.util.*;
import java.util.function.Predicate;
import mineplex.core.gadget.commands.LockCosmeticsCommand;
import mineplex.core.gadget.event.GadgetChangeEvent;
import mineplex.core.gadget.event.GadgetEnableEvent;
import mineplex.core.gadget.gadgets.arrowtrail.freedom.ArrowTrailFreedom;
import mineplex.core.gadget.gadgets.death.freedom.DeathFreedom;
import mineplex.core.gadget.gadgets.doublejump.freedom.DoubleJumpFreedom;
import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitModifier;
import mineplex.core.gadget.gadgets.hat.*;
import mineplex.core.gadget.gadgets.morph.*;
import mineplex.core.gadget.gadgets.outfit.windupsuit.*;
import mineplex.core.gadget.gadgets.particle.*;
import mineplex.core.gadget.gadgets.particle.candycane.ParticleCandyCane;
import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedom;
import mineplex.core.gadget.gadgets.wineffect.*;
import mineplex.core.gadget.persistence.UserGadgetPersistence;
import mineplex.core.gadget.set.*;
import mineplex.core.gadget.types.*;
import mineplex.core.incognito.events.IncognitoHidePlayerEvent;
import mineplex.core.incognito.events.IncognitoStatusChangeEvent;
import org.bukkit.*;
import mineplex.core.gadget.event.PlayerToggleSwimEvent;
import mineplex.core.gadget.gadgets.morph.swim.SwimManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
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.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
@ -36,54 +24,60 @@ import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.*;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.commands.AmmoCommand;
import mineplex.core.gadget.commands.LockCosmeticsCommand;
import mineplex.core.gadget.commands.UnlockCosmeticsCommand;
import mineplex.core.gadget.event.GadgetChangeEvent;
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
import mineplex.core.gadget.gadgets.arrowtrail.vampire.ArrowTrailBlood;
import mineplex.core.gadget.event.GadgetEnableEvent;
import mineplex.core.gadget.gadgets.arrowtrail.candycane.ArrowTrailCandyCane;
import mineplex.core.gadget.gadgets.arrowtrail.party.ArrowTrailConfetti;
import mineplex.core.gadget.gadgets.arrowtrail.cupidslove.ArrowTrailCupid;
import mineplex.core.gadget.gadgets.arrowtrail.emerald.ArrowTrailEmerald;
import mineplex.core.gadget.gadgets.arrowtrail.wisdom.ArrowTrailEnchant;
import mineplex.core.gadget.gadgets.arrowtrail.freedom.ArrowTrailFreedom;
import mineplex.core.gadget.gadgets.arrowtrail.frostlord.ArrowTrailFrostLord;
import mineplex.core.gadget.gadgets.arrowtrail.music.ArrowTrailMusic;
import mineplex.core.gadget.gadgets.arrowtrail.shadow.ArrowTrailShadow;
import mineplex.core.gadget.gadgets.arrowtrail.howlingwinds.ArrowTrailStorm;
import mineplex.core.gadget.gadgets.arrowtrail.music.ArrowTrailMusic;
import mineplex.core.gadget.gadgets.arrowtrail.party.ArrowTrailConfetti;
import mineplex.core.gadget.gadgets.arrowtrail.shadow.ArrowTrailShadow;
import mineplex.core.gadget.gadgets.arrowtrail.titan.ArrowTrailTitan;
import mineplex.core.gadget.gadgets.death.vampire.DeathBlood;
import mineplex.core.gadget.gadgets.arrowtrail.vampire.ArrowTrailBlood;
import mineplex.core.gadget.gadgets.arrowtrail.wisdom.ArrowTrailEnchant;
import mineplex.core.gadget.gadgets.death.candycane.DeathCandyCane;
import mineplex.core.gadget.gadgets.death.cupidslove.DeathCupidsBrokenHeart;
import mineplex.core.gadget.gadgets.death.emerald.DeathEmerald;
import mineplex.core.gadget.gadgets.death.wisdom.DeathEnchant;
import mineplex.core.gadget.gadgets.death.freedom.DeathFreedom;
import mineplex.core.gadget.gadgets.death.frostlord.DeathFrostLord;
import mineplex.core.gadget.gadgets.death.howlingwinds.DeathStorm;
import mineplex.core.gadget.gadgets.death.music.DeathMusic;
import mineplex.core.gadget.gadgets.death.party.DeathPinataBurst;
import mineplex.core.gadget.gadgets.death.shadow.DeathShadow;
import mineplex.core.gadget.gadgets.death.howlingwinds.DeathStorm;
import mineplex.core.gadget.gadgets.death.titan.DeathTitan;
import mineplex.core.gadget.gadgets.doublejump.vampire.DoubleJumpBlood;
import mineplex.core.gadget.gadgets.death.vampire.DeathBlood;
import mineplex.core.gadget.gadgets.death.wisdom.DeathEnchant;
import mineplex.core.gadget.gadgets.doublejump.candycane.DoubleJumpCandyCane;
import mineplex.core.gadget.gadgets.doublejump.cupidslove.DoubleJumpCupidsWings;
import mineplex.core.gadget.gadgets.doublejump.emerald.DoubleJumpEmerald;
import mineplex.core.gadget.gadgets.doublejump.wisdom.DoubleJumpEnchant;
import mineplex.core.gadget.gadgets.doublejump.party.DoubleJumpFirecracker;
import mineplex.core.gadget.gadgets.doublejump.freedom.DoubleJumpFreedom;
import mineplex.core.gadget.gadgets.doublejump.frostlord.DoubleJumpFrostLord;
import mineplex.core.gadget.gadgets.doublejump.music.DoubleJumpMusic;
import mineplex.core.gadget.gadgets.doublejump.shadow.DoubleJumpShadow;
import mineplex.core.gadget.gadgets.doublejump.howlingwinds.DoubleJumpStorm;
import mineplex.core.gadget.gadgets.doublejump.music.DoubleJumpMusic;
import mineplex.core.gadget.gadgets.doublejump.party.DoubleJumpFirecracker;
import mineplex.core.gadget.gadgets.doublejump.shadow.DoubleJumpShadow;
import mineplex.core.gadget.gadgets.doublejump.titan.DoubleJumpTitan;
import mineplex.core.gadget.gadgets.doublejump.vampire.DoubleJumpBlood;
import mineplex.core.gadget.gadgets.doublejump.wisdom.DoubleJumpEnchant;
import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType;
import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitGameModifier;
import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitModifier;
import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitModifierType;
import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.GameModifierMineStrikeSkin;
import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.MineStrikeSkin;
import mineplex.core.gadget.gadgets.hat.HatItem;
import mineplex.core.gadget.gadgets.hat.HatType;
import mineplex.core.gadget.gadgets.morph.*;
import mineplex.core.gadget.gadgets.item.ItemBatGun;
import mineplex.core.gadget.gadgets.item.ItemBow;
import mineplex.core.gadget.gadgets.item.ItemCoal;
@ -101,6 +95,22 @@ import mineplex.core.gadget.gadgets.item.ItemPaintbrush;
import mineplex.core.gadget.gadgets.item.ItemPartyPopper;
import mineplex.core.gadget.gadgets.item.ItemSnowball;
import mineplex.core.gadget.gadgets.item.ItemTNT;
import mineplex.core.gadget.gadgets.morph.MorphBat;
import mineplex.core.gadget.gadgets.morph.MorphBlaze;
import mineplex.core.gadget.gadgets.morph.MorphBlock;
import mineplex.core.gadget.gadgets.morph.MorphBunny;
import mineplex.core.gadget.gadgets.morph.MorphChicken;
import mineplex.core.gadget.gadgets.morph.MorphCow;
import mineplex.core.gadget.gadgets.morph.MorphCreeper;
import mineplex.core.gadget.gadgets.morph.MorphEnderman;
import mineplex.core.gadget.gadgets.morph.MorphPig;
import mineplex.core.gadget.gadgets.morph.MorphPumpkinKing;
import mineplex.core.gadget.gadgets.morph.MorphSlime;
import mineplex.core.gadget.gadgets.morph.MorphSnowman;
import mineplex.core.gadget.gadgets.morph.MorphTitan;
import mineplex.core.gadget.gadgets.morph.MorphUncleSam;
import mineplex.core.gadget.gadgets.morph.MorphVillager;
import mineplex.core.gadget.gadgets.morph.MorphWither;
import mineplex.core.gadget.gadgets.outfit.OutfitTeam;
import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitBoots;
import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuitChestplate;
@ -110,20 +120,68 @@ import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitBoots;
import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitChestplate;
import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitHelmet;
import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuitLeggings;
import mineplex.core.gadget.gadgets.particle.vampire.ParticleBlood;
import mineplex.core.gadget.gadgets.particle.emerald.ParticleEmerald;
import mineplex.core.gadget.gadgets.particle.wisdom.ParticleEnchant;
import mineplex.core.gadget.gadgets.particle.shadow.ParticleFoot;
import mineplex.core.gadget.gadgets.particle.frostlord.ParticleFrostLord;
import mineplex.core.gadget.gadgets.outfit.windupsuit.OutfitWindUpSuitBoosterManager;
import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes;
import mineplex.core.gadget.gadgets.particle.ParticleFairy;
import mineplex.core.gadget.gadgets.particle.ParticleFireRings;
import mineplex.core.gadget.gadgets.particle.ParticleLegend;
import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel;
import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons;
import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal;
import mineplex.core.gadget.gadgets.particle.ParticleWingsPixie;
import mineplex.core.gadget.gadgets.particle.ParticleYinYang;
import mineplex.core.gadget.gadgets.particle.candycane.ParticleCandyCane;
import mineplex.core.gadget.gadgets.particle.cupidslove.ParticleHeart;
import mineplex.core.gadget.gadgets.particle.emerald.ParticleEmerald;
import mineplex.core.gadget.gadgets.particle.freedom.ParticleFreedom;
import mineplex.core.gadget.gadgets.particle.frostlord.ParticleFrostLord;
import mineplex.core.gadget.gadgets.particle.howlingwinds.ParticleRain;
import mineplex.core.gadget.gadgets.particle.music.ParticleMusic;
import mineplex.core.gadget.gadgets.particle.party.ParticlePartyTime;
import mineplex.core.gadget.gadgets.particle.howlingwinds.ParticleRain;
import mineplex.core.gadget.gadgets.particle.shadow.ParticleFoot;
import mineplex.core.gadget.gadgets.particle.titan.ParticleTitan;
import mineplex.core.gadget.gadgets.particle.vampire.ParticleBlood;
import mineplex.core.gadget.gadgets.particle.wisdom.ParticleEnchant;
import mineplex.core.gadget.persistence.UserGadgetPersistence;
import mineplex.core.gadget.set.suits.SetRaveSuit;
import mineplex.core.gadget.set.suits.SetSpaceSuit;
import mineplex.core.gadget.gadgets.wineffect.WinEffectBabyChicken;
import mineplex.core.gadget.gadgets.wineffect.WinEffectFlames;
import mineplex.core.gadget.gadgets.wineffect.WinEffectLavaTrap;
import mineplex.core.gadget.gadgets.wineffect.WinEffectLightningStrike;
import mineplex.core.gadget.gadgets.wineffect.WinEffectMrPunchMan;
import mineplex.core.gadget.gadgets.wineffect.WinEffectPodium;
import mineplex.core.gadget.gadgets.wineffect.WinEffectRiseOfTheElderGuardian;
import mineplex.core.gadget.gadgets.wineffect.WinEffectSnowTrails;
import mineplex.core.gadget.set.SetCandyCane;
import mineplex.core.gadget.set.SetCupidsLove;
import mineplex.core.gadget.set.SetEmerald;
import mineplex.core.gadget.set.SetFreedom;
import mineplex.core.gadget.set.SetFrostLord;
import mineplex.core.gadget.set.SetHowlingWinds;
import mineplex.core.gadget.set.SetMusic;
import mineplex.core.gadget.set.SetParty;
import mineplex.core.gadget.set.SetShadow;
import mineplex.core.gadget.set.SetTitan;
import mineplex.core.gadget.set.SetVampire;
import mineplex.core.gadget.set.SetWisdom;
import mineplex.core.gadget.types.ArrowEffectGadget;
import mineplex.core.gadget.types.DeathEffectGadget;
import mineplex.core.gadget.types.DoubleJumpEffectGadget;
import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetSet;
import mineplex.core.gadget.types.GadgetType;
import mineplex.core.gadget.types.GameModifierGadget;
import mineplex.core.gadget.types.HatGadget;
import mineplex.core.gadget.types.ItemGadget;
import mineplex.core.gadget.types.MusicGadget;
import mineplex.core.gadget.types.OutfitGadget;
import mineplex.core.gadget.types.OutfitGadget.ArmorSlot;
import mineplex.core.gadget.types.ParticleGadget;
import mineplex.core.gadget.types.WinEffectGadget;
import mineplex.core.hologram.HologramManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.incognito.events.IncognitoStatusChangeEvent;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.mount.MountManager;
import mineplex.core.mount.event.MountActivateEvent;
@ -147,6 +205,7 @@ public class GadgetManager extends MiniPlugin
private final PacketHandler _packetManager;
private final HologramManager _hologramManager;
private final OutfitWindUpSuitBoosterManager _boosterManager;
private final IncognitoManager _incognitoManager;
private NautHashMap<GadgetType, List<Gadget>> _gadgets;
@ -161,10 +220,12 @@ public class GadgetManager extends MiniPlugin
private int _activeItemSlot = 3;
private boolean _gadgetsEnabled = true;
private Set<Entity> _gadgetCollideWhitelist = new HashSet<>();
public GadgetManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager,
MountManager mountManager, PetManager petManager, PreferencesManager preferencesManager,
DisguiseManager disguiseManager, BlockRestore blockRestore, ProjectileManager projectileManager, AchievementManager achievementManager,
PacketHandler packetHandler, HologramManager hologramManager)
MountManager mountManager, PetManager petManager, PreferencesManager preferencesManager,
DisguiseManager disguiseManager, BlockRestore blockRestore, ProjectileManager projectileManager, AchievementManager achievementManager,
PacketHandler packetHandler, HologramManager hologramManager, IncognitoManager incognitoManager)
{
super("Gadget Manager", plugin);
@ -182,6 +243,7 @@ public class GadgetManager extends MiniPlugin
_hologramManager = hologramManager;
_userGadgetPersistence = new UserGadgetPersistence(this);
_boosterManager = new OutfitWindUpSuitBoosterManager(this);
_incognitoManager = incognitoManager;
createGadgets();
createSets();
@ -278,6 +340,9 @@ public class GadgetManager extends MiniPlugin
addGadget(new MorphTitan(this));
addGadget(new MorphSnowman(this));
addGadget(new MorphUncleSam(this));
addGadget(new MorphSquid(this));
// Not being added in this update!
//addGadget(new MorphMetalMan(this));
// Particles
addGadget(new ParticleFoot(this));
@ -740,7 +805,7 @@ public class GadgetManager extends MiniPlugin
return _mountManager;
}
public boolean collideEvent(Player shooter, Gadget gadget, Player other)
public boolean collideEvent(Player shooter, Gadget gadget, Entity other)
{
GadgetCollideEntityEvent collideEvent = new GadgetCollideEntityEvent(shooter, gadget, other);
@ -797,6 +862,46 @@ public class GadgetManager extends MiniPlugin
_lastMove.remove(event.getEntity());
}
@EventHandler(priority = EventPriority.LOW)
public void onGadgetCollide(GadgetCollideEntityEvent event)
{
if(event.getOther() instanceof Player)
{
event.setCancelled(false);
return;
}
if(isAffectedByGadgets(event.getOther()))
{
event.setCancelled(false);
}
}
/**
* @param e The entity to check
* @return Returns true if the entity is affected by gadgets like snowballs, flesh hooks etc
*/
public boolean isAffectedByGadgets(Entity e)
{
return _gadgetCollideWhitelist.contains(e);
}
/**
* Set whether or not the given entity should be affected by gadgets by snowball, flesh hooks etc
* By default only players and naturally spawned entities are affected.
*/
public void setAffectedByGadgets(Entity e, boolean affected)
{
if(affected)
{
_gadgetCollideWhitelist.add(e);
}
else
{
_gadgetCollideWhitelist.remove(e);
}
}
public void setActive(Player player, Gadget gadget)
{
if (!_playerActiveGadgetMap.containsKey(player))
@ -919,6 +1024,12 @@ public class GadgetManager extends MiniPlugin
{
if (!_gadgetsEnabled)
event.setCancelled(true);
Player player = event.getPlayer();
if (_incognitoManager.Get(player).Hidden && event.getGadget().getGadgetType() == GadgetType.PARTICLE)
{
event.setCancelled(true);
player.sendMessage(F.main("Cosmetics", "You cannot enable particles while vanished!"));
}
}
@EventHandler
@ -1018,4 +1129,27 @@ public class GadgetManager extends MiniPlugin
{
return _userGadgetPersistence;
}
@EventHandler
public void checkPlayerSwim(PlayerMoveEvent event)
{
Material material = event.getPlayer().getLocation().getBlock().getType();
UUID uuid = event.getPlayer().getUniqueId();
if (material == Material.WATER || material == Material.STATIONARY_WATER)
{
if (!SwimManager.isSwimming(uuid))
{
SwimManager.addPlayer(uuid);
Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), true));
}
}
else
{
if (SwimManager.isSwimming(uuid))
{
SwimManager.removePlayer(uuid);
Bukkit.getPluginManager().callEvent(new PlayerToggleSwimEvent(event.getPlayer(), false));
}
}
}
}

View File

@ -9,11 +9,10 @@ import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType;
import mineplex.core.inventory.ClientInventory;
import mineplex.core.inventory.ClientItem;
import mineplex.core.inventory.data.Item;
import mineplex.core.mount.Mount;
import mineplex.core.pet.Pet;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
public class LockCosmeticsCommand extends CommandBase<GadgetManager>
@ -23,100 +22,107 @@ public class LockCosmeticsCommand extends CommandBase<GadgetManager>
public LockCosmeticsCommand(GadgetManager plugin)
{
super(plugin, Rank.JNR_DEV, new Rank[]{Rank.SNR_MODERATOR}, "lockCosmetics");
super(plugin, Rank.JNR_DEV, "lockCosmetics");
_plugin = plugin;
}
@Override
public void Execute(Player caller, String[] args)
{
// Removes all cosmetic types
if (args.length == 0)
{
lockCosmetics(null, caller);
}
// Removes specific type
else
{
String type = args[0];
if (type.equalsIgnoreCase("all"))
{
lockCosmetics(null, caller);
}
@Override
public void Execute(Player caller, String[] args)
{
// Adds all cosmetic types
if (args.length == 0)
{
removeCosmetics(null, caller);
}
// Adds specific type
else
{
String type = args[0];
if (type.equalsIgnoreCase("all"))
{
removeCosmetics(null, caller);
}
else if (type.equalsIgnoreCase("pet"))
{
lockPets(caller);
removePets(caller);
}
else if (type.equalsIgnoreCase("mount"))
{
lockMounts(caller);
removeMounts(caller);
}
else
{
GadgetType gadgetType = GadgetType.valueOf(type);
if (gadgetType == null)
{
UtilPlayer.message(caller, F.main("Cosmetics", "Invalid cosmetic type!"));
}
else
{
lockCosmetics(gadgetType, caller);
}
}
}
else
{
GadgetType gadgetType = GadgetType.valueOf(type);
if (gadgetType == null)
{
UtilPlayer.message(caller, F.main("Cosmetics", "Invalid cosmetic type!"));
}
else
{
removeCosmetics(gadgetType, caller);
}
}
}
}
}
private void lockCosmetics(GadgetType gadgetType, Player caller)
{
if (gadgetType == null)
{
for (GadgetType type : GadgetType.values())
{
lockCosmetics(type, caller);
}
lockMounts(caller);
lockPets(caller);
return;
}
private void removeCosmetics(GadgetType gadgetType, Player caller)
{
if (gadgetType == null)
{
for (GadgetType type : GadgetType.values())
{
if (type == GadgetType.ITEM)
continue;
removeCosmetics(type, caller);
}
removeMounts(caller);
removePets(caller);
return;
}
ClientInventory clientInventory = _plugin.getInventoryManager().Get(caller);
int removed = 0;
for (Gadget gadget : _plugin.getGadgets(gadgetType))
{
if (gadget.getGadgetType() == GadgetType.ITEM)
int amount = -1;
for (Gadget gadget : _plugin.getGadgets(gadgetType))
{
if (gadgetType == GadgetType.ITEM)
continue;
if (gadget.ownsGadget(caller))
{
Item clientItem = _plugin.getInventoryManager().getItem(gadget.getName());
if (clientItem == null)
continue;
_plugin.getInventoryManager().Get(caller).removeItem(new ClientItem(clientItem, 1));
removed++;
ClientItem clientItem = clientInventory.getClientItem(gadget.getName());
if (clientItem != null)
{
clientInventory.removeItem(clientItem);
removed++;
}
}
}
UtilPlayer.message(caller, F.main("Cosmetics", "Removed all the " + gadgetType.name().toLowerCase()
.replace("_", " ") + "! (Removed " + C.cRed + removed + C.cGray + " " +
UtilText.plural("item", removed) + ")"));
}
}
UtilPlayer.message(caller, F.main("Cosmetics", "Removed all the " + gadgetType.name().toLowerCase()
.replace("_", " ") + " gadgets! (Removed " + C.cRed + removed + C.cGray + " " +
UtilText.plural("item", removed) + ")"));
}
private void lockMounts(Player caller)
private void removeMounts(Player caller)
{
int removed = 0;
ClientInventory clientInventory = _plugin.getInventoryManager().Get(caller);
for (Mount<?> mount : _plugin.getMountManager().getMounts())
{
if (mount.hasMount(caller))
{
Item clientItem = _plugin.getInventoryManager().getItem(mount.getName());
if (clientItem == null)
continue;
_plugin.getInventoryManager().Get(caller).removeItem(new ClientItem(clientItem, 1));
removed++;
ClientItem clientItem = clientInventory.getClientItem(mount.getName());
if (clientItem != null)
{
clientInventory.removeItem(clientInventory.getClientItem(mount.getName()));
removed++;
}
}
}
UtilPlayer.message(caller, F.main("Cosmetics", "Removed " + C.cRed + removed + C.cGray + " " +
UtilText.plural("mount", removed) + "!"));
}
private void lockPets(Player caller)
private void removePets(Player caller)
{
int removed = 0;
for (Pet pet : _plugin.getPetManager().getFactory().GetPets())
@ -130,4 +136,5 @@ public class LockCosmeticsCommand extends CommandBase<GadgetManager>
UtilPlayer.message(caller, F.main("Cosmetics", "Removed " + C.cRed + removed + C.cGray + " " +
UtilText.plural("pet", removed) + "!"));
}
}

View File

@ -2,12 +2,16 @@ package mineplex.core.gadget.event;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.core.gadget.types.Gadget;
public class GadgetCollideEntityEvent extends Event
/**
* An event called when a gadget used by a player collides with an entity. By default, only players are effected (event is cancelled).
*/
public class GadgetCollideEntityEvent extends Event implements Cancellable
{
private static final HandlerList handlers = new HandlerList();
@ -15,7 +19,7 @@ public class GadgetCollideEntityEvent extends Event
private Gadget _gadget;
private Entity _other;
private boolean _cancelled = false;
private boolean _cancelled = true;
public GadgetCollideEntityEvent(Player player, Gadget gadget, Entity other)
{

View File

@ -0,0 +1,41 @@
package mineplex.core.gadget.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class PlayerToggleSwimEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _player;
private boolean _swimming;
public PlayerToggleSwimEvent(Player player, boolean swimming)
{
_player = player;
_swimming = swimming;
}
public Player getPlayer()
{
return _player;
}
public boolean isSwimming()
{
return _swimming;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -1,16 +1,5 @@
package mineplex.core.gadget.gadgets.item;
import java.util.ArrayList;
import java.util.HashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Bat;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LineFormat;
@ -18,18 +7,29 @@ import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
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.UtilText;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.Ammo;
import mineplex.core.gadget.types.ItemGadget;
import mineplex.core.preferences.Preference;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Bat;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashMap;
public class ItemBatGun extends ItemGadget
{
@ -102,7 +102,7 @@ public class ItemBatGun extends ItemGadget
if (other.equals(cur))
continue;
if (!Manager.getPreferencesManager().Get(other).HubGames || !Manager.getPreferencesManager().Get(other).ShowPlayers)
if (!Manager.getPreferencesManager().get(other).isActive(Preference.HUB_GAMES) || !Manager.getPreferencesManager().get(other).isActive(Preference.SHOW_PLAYERS))
continue;
if (!Recharge.Instance.usable(other, "Hit by Bat"))

View File

@ -13,9 +13,9 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.Ammo;
import mineplex.core.gadget.types.ItemGadget;
@ -66,9 +66,8 @@ public class ItemFleshHook extends ItemGadget implements IThrown
if (target == null)
return;
if (target instanceof Player)
if (Manager.collideEvent(player, this, (Player) target))
return;
if (Manager.collideEvent(player, this, target))
return;
//Pull
UtilAction.velocity(target,

View File

@ -14,7 +14,6 @@ import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
import mineplex.core.gadget.gadgets.Ammo;
import mineplex.core.gadget.types.ItemGadget;
@ -53,9 +52,8 @@ public class ItemSnowball extends ItemGadget
if(!_snowballs.containsKey(ball)) return;
GadgetCollideEntityEvent gevent = new GadgetCollideEntityEvent(_snowballs.remove(ball), this, event.getEntity());
if(Manager.collideEvent(_snowballs.remove(ball), this, event.getEntity())) return;
if(gevent.isCancelled()) return;
UtilAction.velocity(event.getEntity(), event.getDamager().getVelocity().normalize().add(new Vector(0,0.5,0)).multiply(0.5));
event.getDamager().getWorld().playSound(event.getDamager().getLocation(), Sound.STEP_SNOW, 1, 0.5f);

View File

@ -56,7 +56,7 @@ public class MorphBat extends MorphGadget implements IThrown
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseBat disguise = new DisguiseBat(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -67,7 +67,7 @@ public class MorphBat extends MorphGadget implements IThrown
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
player.setAllowFlight(false);

View File

@ -39,7 +39,7 @@ public class MorphBlaze extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseBlaze disguise = new DisguiseBlaze(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -50,7 +50,7 @@ public class MorphBlaze extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
}

View File

@ -48,7 +48,7 @@ public class MorphBlock extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
_active.put(player, new BlockForm(this, player, Material.EMERALD_BLOCK));
}
@ -56,7 +56,7 @@ public class MorphBlock extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
BlockForm form = _active.remove(player);

View File

@ -52,7 +52,7 @@ public class MorphBunny extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseRabbit disguise = new DisguiseRabbit(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -67,7 +67,7 @@ public class MorphBunny extends MorphGadget
public void disableCustom(Player player, boolean message)
{
_jumpCharge.remove(player);
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
player.removePotionEffect(PotionEffectType.SPEED);

View File

@ -45,7 +45,7 @@ public class MorphChicken extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseChicken disguise = new DisguiseChicken(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -56,7 +56,7 @@ public class MorphChicken extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
player.setAllowFlight(false);

View File

@ -33,7 +33,7 @@ public class MorphCow extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseCow disguise = new DisguiseCow(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -44,7 +44,7 @@ public class MorphCow extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
}

View File

@ -47,7 +47,7 @@ public class MorphCreeper extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseCreeper disguise = new DisguiseCreeper(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -58,7 +58,7 @@ public class MorphCreeper extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
}

View File

@ -44,7 +44,7 @@ public class MorphEnderman extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseEnderman disguise = new DisguiseEnderman(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -55,7 +55,7 @@ public class MorphEnderman extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
player.setAllowFlight(false);

View File

@ -0,0 +1,135 @@
package mineplex.core.gadget.gadgets.morph;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import mineplex.core.common.skin.SkinData;
import mineplex.core.common.util.*;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.GadgetSelectLocationEvent;
import mineplex.core.gadget.gadgets.particle.unrelated.MetalManEffect;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.recharge.Recharge;
import mineplex.core.utils.UtilGameProfile;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
public class MorphMetalMan extends MorphGadget
{
private Map<UUID, Integer> _playerColors = new HashMap<>();
public MorphMetalMan(GadgetManager manager)
{
super(manager, "Metal Man Morph", UtilText.splitLinesToArray(new String[]{"Placeholder"}, LineFormat.LORE),
0, Material.IRON_INGOT, (byte) 0);
}
@Override
public void enableCustom(Player player, boolean message)
{
applyArmor(player, message);
GameProfile gameProfile = UtilGameProfile.getGameProfile(player);
gameProfile.getProperties().clear();
gameProfile.getProperties().put("textures", SkinData.METAL_MAN.getProperty());
DisguisePlayer disguisePlayer = new DisguisePlayer(player, gameProfile);
disguisePlayer.showInTabList(true, 0);
Manager.getDisguiseManager().disguise(disguisePlayer);
}
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
}
@EventHandler
public void onPlayerClick(PlayerInteractEvent event)
{
Player player = event.getPlayer();
if (!isActive(player))
return;
if (!UtilEvent.isAction(event, UtilEvent.ActionType.L))
return;
if (!Recharge.Instance.use(player, getName(), 1000, false, false, "Cosmetics"))
return;
// Creates colored laser
HashSet<Material> ignore = new HashSet<Material>();
ignore.add(Material.AIR);
Location loc = player.getTargetBlock(ignore, 64).getLocation().add(0.5, 0.5, 0.5);
GadgetSelectLocationEvent gadgetSelectLocationEvent = new GadgetSelectLocationEvent(player, this, loc);
Bukkit.getServer().getPluginManager().callEvent(gadgetSelectLocationEvent);
// Checks to see if it's a valid location
if (gadgetSelectLocationEvent.isCancelled())
{
if (gadgetSelectLocationEvent.canShowMessage())
{
UtilPlayer.message(player, F.main("Gadget", "You cannot use the laser on this area!"));
}
return;
}
// Creates the particle beam
int color = 0;
if (_playerColors.containsKey(player.getUniqueId()))
{
color = _playerColors.get(player.getUniqueId());
}
MetalManEffect metalManEffect = new MetalManEffect(player.getEyeLocation(), loc, color, Manager.getPlugin());
increaseColor(player.getUniqueId());
metalManEffect.start();
// Creates the explosion and knockback players
loc.getWorld().createExplosion(loc, 0f);
UtilParticle.PlayParticle(UtilParticle.ParticleType.HUGE_EXPLOSION, loc, 3f, 3f, 3f, 0, 32, UtilParticle.ViewDist.MAX, UtilServer.getPlayers());
HashMap<Player, Double> players = UtilPlayer.getInRadius(loc, 12d);
for (Player ent : players.keySet())
{
if (Manager.collideEvent(player, this, ent))
continue;
double mult = players.get(ent);
//Knockback
UtilAction.velocity(ent, UtilAlg.getTrajectory(loc, ent.getLocation()), 2 * mult, false, 0, 1 + 1 * mult, 10, true);
}
}
public void increaseColor(UUID uuid)
{
if (_playerColors.containsKey(uuid))
{
int color = _playerColors.get(uuid);
if (color == 0)
color = 1;
else
color = 0;
_playerColors.put(uuid, color);
}
else
{
_playerColors.put(uuid, 0);
}
}
}

View File

@ -46,7 +46,7 @@ public class MorphPig extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguisePig disguise = new DisguisePig(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -57,7 +57,7 @@ public class MorphPig extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
}

View File

@ -30,7 +30,7 @@ public class MorphPumpkinKing extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseSkeleton disguise = new DisguiseSkeleton(player);
disguise.showArmor();
@ -48,7 +48,7 @@ public class MorphPumpkinKing extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
player.getInventory().setHelmet(null);
}

View File

@ -45,7 +45,7 @@ public class MorphSlime extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseSlime disguise = new DisguiseSlime(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -67,7 +67,7 @@ public class MorphSlime extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
}

View File

@ -19,15 +19,14 @@ import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilEvent.ActionType;
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.UtilText;
import mineplex.core.disguise.disguises.DisguiseSnowman;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.recharge.Recharge;
import mineplex.core.recharge.RechargeData;
@ -57,7 +56,7 @@ public class MorphSnowman extends MorphGadget
@Override
public void enableCustom(Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseSnowman disguise = new DisguiseSnowman(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -68,7 +67,7 @@ public class MorphSnowman extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
}
@ -143,9 +142,7 @@ public class MorphSnowman extends MorphGadget
if (!_snowball.containsKey(proj))
return;
GadgetCollideEntityEvent gevent = new GadgetCollideEntityEvent(_snowball.remove(proj), this, event.getEntity());
if(gevent.isCancelled()) return;
if(Manager.collideEvent(_snowball.remove(proj), this, event.getEntity())) return;
UtilAction.velocity(event.getEntity(), proj.getVelocity().multiply(0.15).add(new Vector(0, 0.15, 0)));
}

View File

@ -0,0 +1,142 @@
package mineplex.core.gadget.gadgets.morph;
import mineplex.core.common.util.*;
import mineplex.core.disguise.disguises.DisguiseSquid;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.PlayerToggleSwimEvent;
import mineplex.core.gadget.gadgets.morph.swim.SwimManager;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.gadget.types.OutfitGadget;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.projectile.IThrown;
import mineplex.core.projectile.ProjectileUser;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class MorphSquid extends MorphGadget implements IThrown
{
public MorphSquid(GadgetManager manager)
{
super(manager, "Squid Morph", UtilText.splitLinesToArray(new String[]{
C.cGray + "It's more fun to be a squid than to eat one. They're really rubbery.",
C.blankLine,
C.cWhite + "Swim to enable Fast Swimming",
C.cWhite + "Sneak to shoot a fish above you"
}, LineFormat.LORE),
0, Material.INK_SACK, (byte) 0);
}
@Override
public void enableCustom(Player player, boolean message)
{
applyArmor(player, message);
DisguiseSquid disguiseSquid = new DisguiseSquid(player);
disguiseSquid.setName(player.getName(), Manager.getClientManager().Get(player).GetRank());
Manager.getDisguiseManager().disguise(disguiseSquid);
onToggleSwim(new PlayerToggleSwimEvent(player, SwimManager.isSwimming(player.getUniqueId())));
}
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Player player : UtilServer.getPlayers())
{
if (!isActive(player))
continue;
UtilParticle.PlayParticle(UtilParticle.ParticleType.WATER_WAKE, player.getLocation().clone().add(0, .5, 0), 0.01f, 0.01f, 0.01f,
0.001f, 1, UtilParticle.ViewDist.NORMAL);
}
}
@EventHandler
public void onToggleSwim(PlayerToggleSwimEvent event)
{
if (!isActive(event.getPlayer()))
return;
if (event.isSwimming())
{
// Removes any costume player could be wearing
Manager.removeOutfit(event.getPlayer(), OutfitGadget.ArmorSlot.Boots);
// Adds enchanted boot
ItemStack enchantedBoot = new ItemStack(Material.DIAMOND_BOOTS, 1);
enchantedBoot.addEnchantment(Enchantment.DEPTH_STRIDER, 3);
event.getPlayer().getInventory().setBoots(enchantedBoot);
// Adds swiftness potion
event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 3, true, true));
}
else
{
event.getPlayer().getInventory().setBoots(new ItemStack(Material.AIR));
event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
}
}
@EventHandler
public void onSneak(PlayerToggleSneakEvent event)
{
Player player = event.getPlayer();
if (!player.isSneaking())
return;
if (!isActive(player))
return;
if (!Recharge.Instance.use(player, getName(), 1000, false, false, "Cosmetics"))
return;
Item item = player.getWorld().dropItem(player.getEyeLocation().add(player.getLocation().getDirection()),
ItemStackFactory.Instance.CreateStack(Material.RAW_FISH));
UtilAction.velocity(item, player.getLocation().getDirection(),
0.01, true, -0.3, 1.5, 10, false);
Manager.getProjectileManager().AddThrow(item, player, this, -1, true, true, true, true,
null, 1f, 1f, null, null, 0, UpdateType.TICK, 0.5f);
}
@Override
public void Collide(LivingEntity target, Block block, ProjectileUser data)
{
data.getThrown().remove();
}
@Override
public void Idle(ProjectileUser data)
{
data.getThrown().remove();
}
@Override
public void Expire(ProjectileUser data)
{
data.getThrown().remove();
}
}

View File

@ -60,7 +60,7 @@ public class MorphTitan extends MorphGadget
@Override
public void enableCustom(Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseGuardian disguise = new DisguiseGuardian(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -72,7 +72,7 @@ public class MorphTitan extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
player.setAllowFlight(false);

View File

@ -45,7 +45,7 @@ public class MorphUncleSam extends MorphGadget
@Override
public void enableCustom(Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
GameProfile profile = UtilGameProfile.getGameProfile(player);
profile.getProperties().clear();
@ -61,7 +61,7 @@ public class MorphUncleSam extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(this._disguises.remove(player.getUniqueId()));
}

View File

@ -48,7 +48,7 @@ public class MorphVillager extends MorphGadget implements IThrown
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
DisguiseVillager disguise = new DisguiseVillager(player);
disguise.setName(player.getName(), Manager.getClientManager().Get(player).getRealOrDisguisedRank());
@ -59,7 +59,7 @@ public class MorphVillager extends MorphGadget implements IThrown
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
}

View File

@ -58,7 +58,7 @@ public class MorphWither extends MorphGadget
@Override
public void enableCustom(final Player player, boolean message)
{
this.ApplyArmor(player, message);
this.applyArmor(player, message);
player.setMaxHealth(300);
player.setHealth(300);
@ -75,7 +75,7 @@ public class MorphWither extends MorphGadget
@Override
public void disableCustom(Player player, boolean message)
{
this.RemoveArmor(player);
this.removeArmor(player);
Manager.getDisguiseManager().undisguise(player);
player.setAllowFlight(false);

View File

@ -0,0 +1,30 @@
package mineplex.core.gadget.gadgets.morph.swim;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class SwimManager
{
private static List<UUID> _swimming = new ArrayList<>();
public static void addPlayer(UUID uuid)
{
_swimming.add(uuid);
}
public static void removePlayer(UUID uuid)
{
if (_swimming.contains(uuid))
{
_swimming.remove(uuid);
}
}
public static boolean isSwimming(UUID uuid)
{
return _swimming.contains(uuid);
}
}

View File

@ -9,6 +9,7 @@ public abstract class Effect
public int _ticksToRun = 20, _ticks = 0, _task;
public long _delay = 1;
public EffectLocation _effectLocation;
public EffectLocation _targetLocation;
protected JavaPlugin _javaPlugin;
public Effect(int ticks, EffectLocation effectLocation, JavaPlugin javaPlugin)
@ -53,4 +54,14 @@ public abstract class Effect
public abstract void runEffect();
public void setTargetLocation(EffectLocation effectLocation)
{
_targetLocation = effectLocation;
}
public EffectLocation getTargetLocation()
{
return _targetLocation;
}
}

View File

@ -0,0 +1,50 @@
package mineplex.core.gadget.gadgets.particle.unrelated;
import java.awt.*;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class MetalManEffect extends Effect
{
private int _particles = 100;
private int _color;
private Vector _vector;
public MetalManEffect(Location location, Location target, int color, JavaPlugin javaPlugin)
{
super(20, new EffectLocation(location), javaPlugin);
_color = color;
setTargetLocation(new EffectLocation(target));
}
@Override
public void runEffect()
{
Location location = _effectLocation.getFixedLocation().clone();
if (_vector == null)
{
Location targetLoc = getTargetLocation().getFixedLocation().clone();
Vector link = targetLoc.toVector().subtract(location.toVector());
float length = (float) link.length();
link.normalize();
Vector vector = link.multiply(length / _particles);
_vector = vector;
}
ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST,
new DustSpellColor((_color == 0) ? Color.YELLOW : Color.RED), _effectLocation.getLocation().clone());
Location loc = location.clone().subtract(_vector);
for (int i = 0; i < _particles; i++)
{
loc.add(_vector);
coloredParticle.setLocation(loc);
coloredParticle.display(UtilParticle.ViewDist.LONG);
}
}
}

View File

@ -16,7 +16,7 @@ public abstract class MorphGadget extends Gadget
super(manager, GadgetType.MORPH, name, desc, cost, mat, data);
}
public void ApplyArmor(Player player, boolean message)
public void applyArmor(Player player, boolean message)
{
Manager.removeGadgetType(player, GadgetType.MORPH, this);
@ -26,7 +26,7 @@ public abstract class MorphGadget extends Gadget
UtilPlayer.message(player, F.main("Gadget", "You morphed into " + F.elem(getName()) + "."));
}
public void RemoveArmor(Player player)
public void removeArmor(Player player)
{
if (_active.remove(player))
UtilPlayer.message(player, F.main("Gadget", "You unmorphed from " + F.elem(getName()) + "."));

View File

@ -61,6 +61,7 @@ public enum GameDisplay
ZombieSurvival("Zombie Survival", Material.SKULL_ITEM, (byte)2, GameCategory.SURVIVAL, 49),
Build("Master Builders", Material.WOOD, (byte)0, GameCategory.CLASSICS, 50),
BuildMavericks("Mavericks Master Builders", Material.WOOD, (byte)3, GameCategory.CLASSICS, 63),
Cards("Craft Against Humanity", Material.MAP, (byte)0, GameCategory.CLASSICS, 51),
Skywars("Skywars", Material.FEATHER, (byte) 0, GameCategory.SURVIVAL, 52),
SkywarsTeams("Skywars Teams", "Skywars", Material.FEATHER, (byte)0, GameCategory.TEAM_VARIANT, 53),
@ -81,6 +82,8 @@ public enum GameDisplay
Valentines("Valentines Vendetta", Material.LEATHER, (byte)0, GameCategory.EXTRA, 61),
Basketball("Hoops", Material.SLIME_BALL, (byte)0, GameCategory.EXTRA, 63),
Event("Mineplex Event", Material.CAKE, (byte)0, GameCategory.EVENT, 999),
Brawl("Brawl", Material.DIAMOND, (byte) 0, GameCategory.EVENT, 998);

View File

@ -5,6 +5,7 @@ import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.preferences.Preference;
import org.bukkit.entity.Player;
public class IncognitoToggleCommand extends CommandBase<IncognitoManager>
@ -18,7 +19,7 @@ public class IncognitoToggleCommand extends CommandBase<IncognitoManager>
@Override
public void Execute(Player caller, String[] args)
{
if (Plugin.getPreferences().Get(caller).Invisibility && !Plugin.Get(caller).Status)
if (Plugin.getPreferences().get(caller).isActive(Preference.INVISIBILITY) && !Plugin.Get(caller).Status)
{
UtilPlayer.message(caller, F.main("Incognito", "You are not allowed to toggle incognito on while Hub Invisibility is enabled."));
return;

View File

@ -0,0 +1,84 @@
package mineplex.core.interactions;
import mineplex.core.MiniPlugin;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
/**
* Manages interactions with Armor stands, paintings, and in the main hub, taking items out of chests.
*/
public class NewInteractionsManager extends MiniPlugin
{
public NewInteractionsManager()
{
super("Interactions Manager");
registerEvents(this);
}
@EventHandler
public void onInteract(PlayerArmorStandManipulateEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void onClickBrewingStand(PlayerInteractEvent event)
{
if(event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.BREWING_STAND)
{
event.setCancelled(true);
event.setUseInteractedBlock(Result.DENY);
}
}
@EventHandler
public void onPainting(HangingBreakEvent event)
{
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onChestInteract(InventoryClickEvent event)
{
Player player = (Player) event.getWhoClicked();
Inventory inventory = event.getClickedInventory();
if(inventory == null)
{
return;
}
if(event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR)
{
return;
}
if(inventory.getType() != InventoryType.CHEST)
{
return;
}
if(inventory.getSize() != 27 && inventory.getSize() != 54)
{
return;
}
if(inventory.getTitle() != null)
{
return;
}
event.setCancelled(true);
event.setResult(Result.DENY);
}
}

View File

@ -25,6 +25,10 @@ public class ClientInventory
Items.remove(item.Item.Name);
}
public ClientItem getClientItem(String name) {
return Items.containsKey(name) ? Items.get(name) : null;
}
public int getItemCount(String name)
{
return Items.containsKey(name) ? Items.get(name).Count : 0;

View File

@ -1,27 +1,5 @@
package mineplex.core.inventory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
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.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.EnchantingInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.cache.player.PlayerCache;
import mineplex.cache.player.PlayerInfo;
import mineplex.core.MiniDbClientPlugin;
@ -33,6 +11,26 @@ import mineplex.core.inventory.data.InventoryRepository;
import mineplex.core.inventory.data.Item;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.EnchantingInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
{
@ -266,7 +264,7 @@ public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
@EventHandler
public void onInventoryClick(final InventoryClickEvent event)
{
if (event.getView().getTopInventory().getType() != InventoryType.ENCHANTING)
if (event.getClickedInventory() == null || event.getClickedInventory().getType() != InventoryType.ENCHANTING)
{
return;
}

View File

@ -0,0 +1,58 @@
package mineplex.core.locations;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
/**
* This class controls all "hard coded" locations that will be the same throughout the entire server
* regardless of whether or not it is on hub
*/
public class LocationConstants
{
private static final int CHEST_X = 31;
private static final int CHEST_Z = 23;
/**
* The number to be added to either the X or the Z for chest reset locations
*/
private static final int CHEST_ADD = 5;
public static final World WORLD = Bukkit.getWorld("world");
public static final Location HUB_SPAWN = new Location(WORLD, 0, 77, -32);
public static final Location[] CHEST_LOCATIONS = {
new Location(WORLD, 34, 72, -15),
new Location(WORLD, 23, 72, -31),
new Location(WORLD, -23, 72, -31),
new Location(WORLD, -34, 72, -15)
};
//new Location(world, -25.5, 73, 19.5), new Location(world, -35.5, 69, 1.5)
public static final Location FOUNTAIN_SCHEMATIC = new Location(WORLD, -35.5, 68, 1.5);
public static final Location FOUNTAIN_LOCATION = new Location(WORLD, -24.5, 72, 24.5);
public static Location getResetLocation(Location chestLocation)
{
int x = chestLocation.getBlockX();
int z = chestLocation.getBlockZ();
int absX = Math.abs(x);
int absZ = Math.abs(z);
if (absX == CHEST_X)
{
return chestLocation.clone().add(CHEST_ADD, 0, 0);
}
if (absZ == CHEST_Z)
{
return chestLocation.clone().add(0, 0, CHEST_ADD);
}
return chestLocation.clone().add(CHEST_ADD, 0, CHEST_ADD);
}
}

View File

@ -0,0 +1,188 @@
package mineplex.core.mavericks;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.util.Vector;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.SchematicData;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
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.hologram.Hologram;
import mineplex.core.hologram.HologramManager;
/**
* Represents a display slot to display Mavericks Master Builders builds.
*/
public class DisplaySlot
{
private MavericksApprovedWrapper _data;
private Location _loc;
private ArrayList<Entity> _pastedEntities = new ArrayList<>();
private Map<Vector, ParticleType> _particles = null;
private List<Hologram> _holograms = new ArrayList<>();
/**
* @param loc The minimum corner of where the build will be pasted in.
*/
public DisplaySlot(Location loc, HologramManager hologramManager)
{
_loc = loc.clone();
for(int i = 0; i < 4; i++)
{
_holograms.add(new Hologram(hologramManager, _loc.clone(), "Built by ???", "Theme: ???"));
}
}
public MavericksApprovedWrapper getData()
{
return _data;
}
public void setData(MavericksApprovedWrapper data)
{
clearEntities();
for(Hologram h : _holograms)
h.stop();
Schematic schematic = data.getBuild().getSchematic();
Location a = _loc;
Location b = _loc.clone().add(schematic.getWidth(), schematic.getHeight(), schematic.getLength());
UtilBlock.startQuickRecording();
for(int x = a.getBlockX(); x < b.getX(); x++)
{
// Ignore the floor to keep the outer ring
for(int y = a.getBlockY() + 1; y < b.getY(); y++)
{
for(int z = a.getBlockZ(); z < b.getZ(); z++)
{
UtilBlock.setQuick(a.getWorld(), x, y, z, 0, (byte) 0);
}
}
}
SchematicData pasteData = schematic.paste(_loc, true, false);
for(Entity e : pasteData.getEntities())
{
if(e instanceof Item)
{
//Don't despawn
e.setTicksLived(32768);
//Prevent Pickup
((Item)e).setPickupDelay(32767);
}
else
{
UtilEnt.Vegetate(e, true);
UtilEnt.ghost(e, true, false);
}
_pastedEntities.add(e);
}
_particles = data.getBuild().getParticles();
boolean wasNull = _data == null;
_data = data;
//Only need to set locations first time after we get the data
if(wasNull)
{
setHologramLocations();
}
for(Hologram h : _holograms)
{
h.setText(
C.cGray + "Built by " + C.cYellow + C.Bold + _data.getBuild().getName(),
C.cGray + "Theme: " + C.cYellow + C.Bold + data.getBuild().getTheme());
h.start();
}
}
/**
* Send all the entities to nearby players. Should be called every 10 ticks.
*/
public void updateParticles()
{
if(_particles == null) return;
for(Entry<Vector, ParticleType> e : _particles.entrySet())
{
Location loc = _loc.clone().add(e.getKey());
ParticleType type = e.getValue();
int amount = 8;
if (type == ParticleType.HUGE_EXPLOSION ||
type == ParticleType.LARGE_EXPLODE ||
type == ParticleType.NOTE)
amount = 1;
UtilParticle.PlayParticleToAll(type, loc, 0.4f, 0.4f, 0.4f, 0, amount, ViewDist.LONG);
}
}
private void clearEntities()
{
for(Entity e : _pastedEntities)
{
e.remove();
}
_pastedEntities.clear();
}
/**
* @param e The entity you want to check.
* @return Returns true if this entity is spawned in by this display slot.
*/
public boolean isDisplaySlotEntity(Entity e)
{
return _pastedEntities.contains(e);
}
public boolean isInside(Location loc)
{
if(!_loc.getWorld().equals(loc.getWorld())) return false;
if(_data == null) return false;
Schematic s = _data.getBuild().getSchematic();
Location min = _loc.clone();
Location max = _loc.clone().add(s.getWidth(), s.getHeight(), s.getLength());
return UtilAlg.inBoundingBox(loc, min, max);
}
public void setHologramLocations()
{
if(_data == null) return;
Schematic s = _data.getBuild().getSchematic();
Location min = _loc.clone();
double height = 4;
_holograms.get(0).setLocation(min.clone().add(s.getWidth()/2.0, height, -1.5));
_holograms.get(1).setLocation(min.clone().add(s.getWidth()/2.0, height, s.getLength() + 1.5));
_holograms.get(2).setLocation(min.clone().add(-1.5, height, s.getLength()/2.0));
_holograms.get(3).setLocation(min.clone().add(s.getWidth() + 1.5, height, s.getLength()/2.0));
}
}

View File

@ -0,0 +1,176 @@
package mineplex.core.mavericks;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import mineplex.serverdata.database.DBPool;
/**
* Repository for Mavericks-MasterBuilders SQL game data
* -
* Table to back this repository may be created with:
*
*
CREATE TABLE mavericksMasterBuildersApproved (
buildId INT NOT NULL AUTO_INCREMENT,
ApproveDate INT NOT NULL,
ApprovedBy VARCHAR(36) NOT NULL DEFAULT '',
Display TINYINT(1) NOT NULL DEFAULT '1',
PRIMARY KEY (buildId),
CONSTRAINT account_id FOREIGN KEY (ApprovedBy) REFERENCES accounts (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT build_id FOREIGN KEY (BuildId) REFERENCES mavericksMasterBuildersBuilds (BuildId) ON DELETE NO ACTION ON UPDATE NO ACTION
)
*/
public class MavericksApprovedRepository
{
private static final String TABLE_APPROVED = "mavericksMasterBuildersApproved";
private static final String TABLE_BUILD = "mavericksMasterBuildersBuilds";
public CompletableFuture<Boolean> add(MavericksBuildWrapper data, UUID approvedBy)
{
return add(data, approvedBy, true);
}
public CompletableFuture<Boolean> add(MavericksBuildWrapper data, UUID approvedBy, boolean display)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("REPLACE INTO " + TABLE_APPROVED + " (BuildId, ApprovedBy, Display) SELECT ?, accounts.id, ? FROM accounts WHERE uuid=?");
stmt.setLong(1, data.getBuildId());
stmt.setBoolean(2, display);
stmt.setString(3, approvedBy.toString());
return stmt.executeUpdate() > 0;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
public CompletableFuture<List<MavericksApprovedWrapper>> getToDisplay(boolean onlyDisplay, int limit, int offset)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
String filter = onlyDisplay ? " WHERE Display=1 " : " ";
PreparedStatement stmt = conn.prepareStatement(
"SELECT " +
TABLE_APPROVED + ".BuildId, ApprovedDate," +
"(SELECT uuid FROM accounts WHERE accounts.id=ApprovedBy)," +
"Display, FirstDisplayed," +
"BuildTheme," +
"(SELECT uuid FROM accounts WHERE accounts.id=accountId)," +
"(SELECT name FROM accounts WHERE accounts.id=accountId)," +
"Points, Place, Date, Schematic, Particles, Reviewed " +
"FROM " + TABLE_APPROVED + " " +
"INNER JOIN " + TABLE_BUILD + " " +
"ON " + TABLE_APPROVED + ".BuildId = " + TABLE_BUILD + ".BuildId" +
filter +
"LIMIT " + limit + " OFFSET " + offset);
ResultSet set = stmt.executeQuery();
List<MavericksApprovedWrapper> list = new ArrayList<>();
while (set.next())
{
long buildId = set.getLong(1);
long approvedDate = set.getLong(2);
UUID approvedBy = UUID.fromString(set.getString(3));
boolean display = set.getBoolean(4);
Timestamp stamp = set.getTimestamp(1);
Long firstDisplayed = null;
if(!set.wasNull() && stamp != null) stamp.getTime();
String theme = set.getString(6);
UUID uuid = UUID.fromString(set.getString(7));
String lastName = set.getString(8);
int votes = set.getInt(9);
int place = set.getInt(10);
long dateStamp = set.getLong(11);
byte[] schematic = set.getBytes(12);
byte[] particles = set.getBytes(13);
boolean reviewed = set.getBoolean(14);
MavericksBuildWrapper build = new MavericksBuildWrapper(buildId, uuid, lastName, theme, votes, place, dateStamp, schematic, particles, reviewed);
MavericksApprovedWrapper approved = new MavericksApprovedWrapper(build, approvedDate, approvedBy, display, firstDisplayed);
list.add(approved);
}
return list;
}
catch (SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
public CompletableFuture<Boolean> setDisplay(boolean display, long... buildids)
{
if(buildids.length == 0) return null;
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
String where = "WHERE BuildId=?";
for(int i = 1; i < buildids.length; i++)
{
where += " OR BuildId=?";
}
PreparedStatement stmt = conn.prepareStatement("UPDATE " + TABLE_APPROVED + " SET Display=? " + where);
stmt.setBoolean(1, display);
for(int i = 0; i < buildids.length; i++)
{
stmt.setLong(2+i, buildids[i]);
}
return stmt.executeUpdate() > 0;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
public CompletableFuture<Boolean> setDisplayDate(long buildid)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("UPDATE " + TABLE_APPROVED + " SET FirstDisplayed=? WHERE BuildId=?");
// stmt.setDate(1, new Date(System.currentTimeMillis()));
stmt.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
stmt.setLong(2, buildid);
return stmt.executeUpdate() > 0;
}
catch(Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
}

View File

@ -0,0 +1,57 @@
package mineplex.core.mavericks;
import java.util.UUID;
/**
* A wrapper class to SQL data in the mavericksMasterBuildersApproved SQL table
*/
public class MavericksApprovedWrapper
{
private final MavericksBuildWrapper _build;
private final long _approvedDate;
private final UUID _approvedBy;
private final boolean _display;
private Long _firstDisplayed;
public MavericksApprovedWrapper(MavericksBuildWrapper build, long approvedDate, UUID approvedBy, boolean display, Long firstDisplayed)
{
_build = build;
_approvedDate = approvedDate;
_approvedBy = approvedBy;
_display = display;
_firstDisplayed = firstDisplayed;
}
public MavericksBuildWrapper getBuild()
{
return _build;
}
public long getApprovedDate()
{
return _approvedDate;
}
public UUID getApprovedBy()
{
return _approvedBy;
}
public Long getFirstDisplayed()
{
return _firstDisplayed;
}
public void setFirstDisplayed(Long firstDisplayed)
{
_firstDisplayed = firstDisplayed;
}
public boolean isDisplay()
{
return _display;
}
}

View File

@ -0,0 +1,133 @@
package mineplex.core.mavericks;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import mineplex.serverdata.database.DBPool;
/**
* Repository for Mavericks-MasterBuilders SQL game data
* -
* Table to back this repository may be created with
*
CREATE TABLE IF NOT EXISTS mavericksMasterBuildersBuilds (
accountId INT NOT NULL,
BuildTheme VARCHAR(255) NOT NULL,
Points DOUBLE NOT NULL,
Place INT NOT NULL,
Date BIGINT NOT NULL,
Schematic BLOB,
Reviewed TINYINT,
PRIMARY KEY (accountId,Date),
FOREIGN KEY (accountId) REFERENCES accounts(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
*/
public class MavericksBuildRepository
{
private static final String TABLE = "mavericksMasterBuildersBuilds";
public CompletableFuture<List<MavericksBuildWrapper>> getToReview(boolean onlyUnreviewed, int limit, int offset)
{
return getToReview(onlyUnreviewed, limit, offset, true);
}
public CompletableFuture<List<MavericksBuildWrapper>> getToReview(boolean onlyUnreviewed, int limit, int offset, boolean parseData)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
String filter = onlyUnreviewed ? "WHERE Reviewed=0 " : "";
PreparedStatement stmt = conn.prepareStatement("SELECT BuildId," +
"(SELECT uuid from accounts WHERE accounts.id=" + TABLE + ".accountId)," +
"(SELECT name from accounts WHERE accounts.id=" + TABLE + ".accountId)," +
"BuildTheme,Points,Place,Date,Schematic,Particles,Reviewed FROM " + TABLE + " " + filter +
" ORDER BY Points DESC LIMIT " + limit + " OFFSET " + offset);
ResultSet set = stmt.executeQuery();
List<MavericksBuildWrapper> list = new ArrayList<>();
while (set.next())
{
long buildId = set.getLong(1);
UUID uuid = UUID.fromString(set.getString(2));
String lastName = set.getString(3);
String theme = set.getString(4);
int votes = set.getInt(5);
int place = set.getInt(6);
long dateStamp = set.getLong(7);
byte[] schematic = set.getBytes(8);
byte[] particles = set.getBytes(9);
boolean reviewed = set.getBoolean(10);
MavericksBuildWrapper data = new MavericksBuildWrapper(buildId, uuid, lastName, theme, votes, place, dateStamp, schematic, particles, reviewed);
if(parseData)
{
data.getParticles();
data.getSchematic();
}
list.add(data);
}
return list;
}
catch (SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
public CompletableFuture<Boolean> setReviewed(long buildId, boolean reviewed)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("UPDATE " + TABLE + " SET Reviewed=? WHERE BuildId=?");
stmt.setBoolean(1, reviewed);
stmt.setLong(2, buildId);
return stmt.executeUpdate() > 0;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
public CompletableFuture<Boolean> add(MavericksBuildWrapper data)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement("REPLACE INTO " + TABLE + " (accountId, BuildTheme, Points, Place, Date, Schematic, Particles) SELECT accounts.id, ?, ?, ?, ?, ?, ? FROM accounts WHERE uuid=?");
stmt.setString(1, data.getTheme());
stmt.setDouble(2, data.getPoints());
stmt.setInt(3, data.getPlace());
stmt.setLong(4, data.getDateStamp());
stmt.setBytes(5, data.getSchematicBytes());
stmt.setBytes(6, data.getParticlesRaw());
stmt.setString(7, data.getUUID().toString());
return stmt.executeUpdate() > 0;
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
}

View File

@ -0,0 +1,176 @@
package mineplex.core.mavericks;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.util.Vector;
import com.java.sk89q.jnbt.CompoundTag;
import com.java.sk89q.jnbt.NBTUtils;
import com.java.sk89q.jnbt.Tag;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.UtilParticle.ParticleType;
/**
* A simple wrapper class for Mavericks-MasterBuilders SQL data
*/
public class MavericksBuildWrapper
{
private final long _buildId;
private final UUID _uuid;
private final String _theme;
private final double _points;
private final int _place;
private final long _dateStamp;
private final byte[] _schematic;
private Schematic _schematicCache;
private final byte[] _particles;
private Map<Vector, ParticleType> _particlesCache;
private boolean _reviewed;
private final String _name;
public MavericksBuildWrapper(long buildId, UUID uuid, String name, String theme, double points, int place, long dateStamp,
byte[] schematic, byte[] particles, boolean reviewed)
{
this._buildId = buildId;
this._uuid = uuid;
this._name = name;
this._theme = theme;
this._points = points;
this._place = place;
this._dateStamp = dateStamp;
this._schematic = schematic;
this._particles = particles;
this._reviewed = reviewed;
}
public MavericksBuildWrapper(long buildId, UUID uuid, String theme, double points, int place, long dateStamp,
byte[] schematic, byte[] particles, boolean reviewed)
{
this(buildId, uuid, null, theme, points, place, dateStamp, schematic, particles, reviewed);
}
public long getBuildId()
{
return _buildId;
}
public UUID getUUID()
{
return _uuid;
}
public String getName()
{
return _name;
}
public boolean hasNameSet()
{
return _name != null;
}
public String getTheme()
{
return _theme;
}
public double getPoints()
{
return _points;
}
public int getPlace()
{
return _place;
}
public long getDateStamp()
{
return _dateStamp;
}
public byte[] getSchematicBytes()
{
return _schematic;
}
public boolean isReviewed()
{
return _reviewed;
}
public void setReviewed(boolean reviewed)
{
_reviewed = reviewed;
}
public Schematic getSchematic()
{
if(_schematicCache != null) return _schematicCache;
try
{
return _schematicCache = UtilSchematic.loadSchematic(_schematic);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public boolean hasParticles()
{
return _particles != null && _particles.length > 0;
}
public byte[] getParticlesRaw()
{
return _particles;
}
public Map<Vector, ParticleType> getParticles()
{
if(_particlesCache != null) return _particlesCache;
Map<Vector, ParticleType> map = new HashMap<>();
if(!hasParticles()) return map;
try
{
CompoundTag tag = (CompoundTag) NBTUtils.getFromBytesCompressed(_particles).getTag();
for(Entry<String, Tag> e : tag.getValue().entrySet())
{
CompoundTag parent = (CompoundTag) e.getValue();
Vector v = NBTUtils.getVector(parent);
ParticleType particle = ParticleType.valueOf(parent.getString("particle"));
while(map.containsKey(v)) v.add(new Vector(0.00000001, 0, 0));
map.put(v, particle);
}
}
catch (Exception e)
{
e.printStackTrace();
}
return _particlesCache = map;
}
@Override
public String toString()
{
return "MavericksBuildWrapper[uuid='" + _uuid + "',theme='" + _theme + "',points=" + _points + ",place=" + _place
+ ",date=" + _dateStamp + ",Schematic=ByteArray[" + _schematic.length + "]]";
}
}

View File

@ -0,0 +1,70 @@
package mineplex.core.menu;
import mineplex.core.MiniPlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
/**
* An abstract class for managing buttons inside of menus
*/
public abstract class Button<T extends MiniPlugin>
{
private ItemStack _item;
private T _plugin;
public Button(ItemStack item, T plugin)
{
_item = item;
_plugin = plugin;
}
public Button(ItemStack itemStack)
{
_item = itemStack;
_plugin = null;
}
/**
* The method called when a players clicks the slot
*
* @param player The player who clicked
* @param clickType Tge type of click
*/
public abstract void onClick(Player player, ClickType clickType);
/**
* Called when clicking on a specific item is needed, rather than just the slot
* Empty by default
*
* @param player The player who clicked
* @param clickType Tge type of click
* @param item The ItemStack clicked
*/
public void onClick(Player player, ClickType clickType, ItemStack item)
{
}
public boolean useItemClick()
{
return false;
}
public ItemStack getItemStack()
{
return _item;
}
public void setItemStack(ItemStack item)
{
_item = item;
}
public T getPlugin()
{
return _plugin;
}
}

View File

@ -1,7 +1,5 @@
package mineplex.core.party.ui.button;
package mineplex.core.menu;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.Button;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@ -13,9 +11,9 @@ import org.bukkit.inventory.ItemStack;
public class IconButton extends Button
{
public IconButton(ItemStack item, PartyManager plugin)
public IconButton(ItemStack item)
{
super(item, plugin);
super(item);
}
@Override

View File

@ -1,10 +1,7 @@
package mineplex.core.party.ui;
package mineplex.core.menu;
import mineplex.core.common.util.C;
import mineplex.core.MiniPlugin;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.party.PartyManager;
import mineplex.core.party.ui.button.IconButton;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Material;
@ -20,26 +17,20 @@ import java.util.UUID;
/**
* A class to manage dynamic creation of GUI's
*/
public abstract class Menu
public abstract class Menu<T extends MiniPlugin>
{
protected static final Button PANE = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE)
.setTitle(" ")
.setData(DyeColor.LIGHT_BLUE.getWoolData())
.build(), null);
protected static final Button PURCHASE_MORE_SLOTS = new IconButton(new ItemBuilder(Material.REDSTONE_BLOCK)
.setTitle(C.cRed + C.Bold + "Locked!")
.setLore(" ", C.cGray + "Purchase a rank @ mineplex.com/shop", C.cGray + "Purchasing a rank increases your", C.cGray + "party size to allow 10 people!")
.build(), null);
private final ItemStack PANE = new ItemBuilder(Material.STAINED_GLASS_PANE).setTitle(" ").setData(DyeColor.LIGHT_BLUE.getWoolData()).build();
protected static final Button[] EMPTY = new Button[54];
protected static Map<UUID, Menu> MENUS = new HashMap<>();
private String _name;
protected static final Map<UUID, Menu> MENUS = new HashMap<>();
private final String _name;
private final T _plugin;
private boolean _useClose = false;
private Button[] _buttons;
protected PartyManager _plugin;
private Player _player;
public Menu(String name, PartyManager plugin)
public Menu(String name, T plugin)
{
_name = name;
_buttons = EMPTY;
@ -51,50 +42,14 @@ public abstract class Menu
return MENUS.get(name);
}
/**
* Create an icon (no click action)
*
* @param item The itemstack ti display
* @return The created button
*/
protected Button create(ItemStack item)
public T getPlugin()
{
return new IconButton(item, _plugin);
return _plugin;
}
public String getName()
{
return ChatColor.translateAlternateColorCodes('&', _name);
}
public Button[] addPanes(Button[] buttons)
{
for (int i = 0; i < 9; i++)
{
if (buttons[i] == null)
{
buttons[i] = PANE;
}
if(buttons.length == 9)
{
continue;
}
if (buttons[i + buttons.length - 9] == null)
{
buttons[i + buttons.length - 9] = PANE;
}
if (i == 0 || i == 8)
{
for (int a = 9; a < buttons.length; a += 9)
{
buttons[i + a] = PANE;
}
}
}
return buttons;
return _name;
}
/**
@ -105,6 +60,7 @@ public abstract class Menu
*/
public void open(Player player)
{
_player = player;
setButtons(setUp(player));
if (MENUS.get(player.getUniqueId()) != null)
@ -115,7 +71,7 @@ public abstract class Menu
MENUS.put(player.getUniqueId(), this);
int size = (_buttons.length + 8) / 9 * 9;
Inventory inventory = Bukkit.createInventory(player, size, getName());
Inventory inventory = Bukkit.createInventory(player, size, _name);
for (int i = 0; i < _buttons.length; i++)
{
@ -173,9 +129,8 @@ public abstract class Menu
*
* @param slot The slot to set the new button
* @param button The reference to the button
* @param player The player whose GUI we'll be updating
*/
public void setButton(int slot, Button button, Player player)
public void setButton(int slot, Button button)
{
try
{
@ -184,24 +139,22 @@ public abstract class Menu
{
ignored.printStackTrace();
}
update(player);
update();
}
/**
* Refresh the players view, allows to change what the player sees, without opening and closing the GUI
*
* @param player The player whose view you wish to update
*/
public void update(Player player)
public void update()
{
InventoryView view = player.getOpenInventory();
InventoryView view = _player.getOpenInventory();
if (view == null)
{
return;
}
if (!view.getTitle().equalsIgnoreCase(getName()))
if (!view.getTitle().equalsIgnoreCase(_name))
{
return;
}
@ -222,25 +175,23 @@ public abstract class Menu
/**
* Reset this players current menu's buttons and refresh the page
*
* @param player The player whose view you wish to update
*/
public void resetAndUpdate(Player player)
public void resetAndUpdate()
{
InventoryView view = player.getOpenInventory();
InventoryView view = _player.getOpenInventory();
if (view == null)
{
return;
}
if (!view.getTitle().equalsIgnoreCase(getName()))
if (!view.getTitle().equalsIgnoreCase(_name))
{
return;
}
Inventory inventory = view.getTopInventory();
Button[] buttons = setUp(player);
Button[] buttons = setUp(_player);
for (int i = 0; i < buttons.length; i++)
{
if (buttons[i] == null)
@ -254,19 +205,56 @@ public abstract class Menu
}
}
public void setTitle(String title)
protected Button[] pane(Button[] buttons)
{
_name = title;
for (int i = 0; i < 9; i++)
{
if (buttons[i] == null)
{
buttons[i] = new IconButton(PANE);
}
if (buttons[i + buttons.length - 9] == null)
{
buttons[i + buttons.length - 9] = new IconButton(PANE);
}
if (i == 0 || i == 8)
{
for (int a = 0; a < buttons.length; a += 9)
{
if (buttons[i + a] == null)
{
buttons[i + a] = new IconButton(PANE);
}
}
}
}
return buttons;
}
public void onClose(Player player)
{
MENUS.remove(player.getUniqueId());
}
public static Menu remove(UUID uniqueId)
{
return MENUS.remove(uniqueId);
}
public Player getPlayer()
{
return _player;
}
public boolean isUseClose()
{
return _useClose;
}
public void setUseClose(boolean useClose)
{
_useClose = useClose;
}
}

View File

@ -1,12 +1,11 @@
package mineplex.core.party.ui;
package mineplex.core.menu;
import mineplex.core.party.ui.button.PartyMemberIcon;
import mineplex.core.party.ui.menus.PartyOwnerMenu;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
/**
* Listener for the Menu system
@ -41,17 +40,37 @@ public class MenuListener implements Listener
return;
}
if(button instanceof PartyMemberIcon)
if(button.useItemClick())
{
if(!(gui instanceof PartyOwnerMenu))
{
return;
}
((PartyMemberIcon) button).onClick(player, event.getCurrentItem());
button.onClick(player, event.getClick(), event.getCurrentItem());
return;
}
button.onClick(player, event.getClick());
}
@EventHandler
public void onClose(InventoryCloseEvent event)
{
String name = event.getInventory().getName();
Player player = (Player) event.getPlayer();
Menu gui = Menu.get(player.getUniqueId());
if (gui == null)
{
return;
}
if (!gui.getName().equalsIgnoreCase(name))
{
return;
}
if(gui.isUseClose())
{
gui.onClose(player);
gui.setUseClose(false);
}
}
}

View File

@ -0,0 +1,18 @@
package mineplex.core.menu;
import mineplex.core.MiniPlugin;
import org.bukkit.plugin.java.JavaPlugin;
/**
*
*/
public class MenuManager extends MiniPlugin
{
public MenuManager(JavaPlugin plugin)
{
super("Menu Manager", plugin);
getPluginManager().registerEvents(new MenuListener(), plugin);
}
}

View File

@ -25,6 +25,7 @@ import mineplex.core.message.commands.ResendAdminCommand;
import mineplex.core.message.commands.ResendCommand;
import mineplex.core.message.redis.RedisMessage;
import mineplex.core.message.redis.RedisMessageCallback;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.punish.Punish;
import mineplex.core.punish.PunishClient;
@ -145,7 +146,7 @@ public class MessageManager extends MiniClientPlugin<ClientMessage>
public String canReceiverMessageThem(String sender, Player target)
{
// If the receiver has turned off private messaging and the sender isn't a mod
if (!_preferences.Get(target).PrivateMessaging)
if (!_preferences.get(target).isActive(Preference.PRIVATE_MESSAGING))
{
return C.cPurple + target.getName() + " has private messaging disabled.";

View File

@ -37,8 +37,6 @@ public class LagMeter extends MiniPlugin
private boolean _timingsPasted;
private long _timingsStarted;
private boolean _fakeTps = false;
private HashSet<Player> _monitoring = new HashSet<Player>();
public LagMeter(JavaPlugin plugin, CoreClientManager clientManager)
@ -122,10 +120,6 @@ public class LagMeter extends MiniPlugin
public double getTicksPerSecond()
{
if (_fakeTps)
{
return 20.0;
}
return _ticksPerSecond;
}
@ -170,10 +164,4 @@ public class LagMeter extends MiniPlugin
player.sendMessage(F.main(getName(), ChatColor.GRAY + "Free-------" + ChatColor.YELLOW + (Runtime.getRuntime().freeMemory() / 1048576) + "MB"));
player.sendMessage(F.main(getName(), ChatColor.GRAY + "Max--------" + ChatColor.YELLOW + (Runtime.getRuntime().maxMemory() / 1048576)) + "MB");
}
// I'm so sorry. Blame ServerMonitor for being so strict
public void setFakeTps(boolean fakeTps)
{
this._fakeTps = fakeTps;
}
}

View File

@ -1,11 +1,5 @@
package mineplex.core.notifier;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
@ -14,8 +8,10 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
public class NotificationManager extends MiniPlugin
{
@ -60,7 +56,7 @@ public class NotificationManager extends MiniPlugin
{
for (Player player : UtilServer.getPlayers())
{
if (!_preferencesManager.Get(player).DisableAds)
if (_preferencesManager.getClientManager().Get(player).GetRank() == Rank.ALL)
{
player.sendMessage(C.cWhite + " ");
player.sendMessage(C.cRedB + " MASSIVE WINTER SALE");

View File

@ -27,7 +27,25 @@ public class Npc
_npcManager = npcManager;
_databaseRecord = databaseRecord;
_location = new Location(Bukkit.getWorld(getDatabaseRecord().getWorld()), getDatabaseRecord().getX(), getDatabaseRecord().getY(), getDatabaseRecord().getZ());
Double yaw = getDatabaseRecord().getYaw();
Double pitch = getDatabaseRecord().getPitch();
if(yaw == null)
{
yaw = 0d;
}
if(pitch == null)
{
pitch = 0d;
}
_location = new Location(Bukkit.getWorld(getDatabaseRecord().getWorld()),
getDatabaseRecord().getX(),
getDatabaseRecord().getY(),
getDatabaseRecord().getZ(),
yaw.floatValue(),
pitch.floatValue());
if (getDatabaseRecord().getInfo() == null)
_info = null;

View File

@ -264,6 +264,8 @@ public class NpcManager extends MiniPlugin
npcsRecord.setX(player.getLocation().getX());
npcsRecord.setY(player.getLocation().getY());
npcsRecord.setZ(player.getLocation().getZ());
npcsRecord.setYaw((double)player.getEyeLocation().getYaw());
npcsRecord.setPitch((double)player.getEyeLocation().getPitch());
npcsRecord.setRadius(radius);
npcsRecord.setEntityType(entityType.name());
npcsRecord.setAdult(adult);
@ -422,8 +424,6 @@ public class NpcManager extends MiniPlugin
if (npc.getFailedAttempts() >= 10 || npc.getDatabaseRecord().getRadius() == 0)
{
Location location = npc.getLocation();
location.setPitch(entity.getLocation().getPitch());
location.setYaw(entity.getLocation().getYaw());
entity.teleport(location);
entity.setVelocity(new Vector(0, 0, 0));
npc.setFailedAttempts(0);
@ -461,8 +461,6 @@ public class NpcManager extends MiniPlugin
if (!entity.isDead() && entity.isValid())
{
Location location = npc.getLocation();
location.setPitch(entity.getLocation().getPitch());
location.setYaw(entity.getLocation().getYaw());
entity.teleport(location);
entity.setVelocity(new Vector(0, 0, 0));

View File

@ -1,6 +1,7 @@
package mineplex.core.party;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import org.bukkit.entity.Player;
import java.text.MessageFormat;
@ -44,10 +45,25 @@ public enum Lang
PARTY_FULL("Error: Your party is full!"),
SERVER_CLOSED("Error: Your server is closed and you cannot invite players to join it right now!"),
SERVER_FULL("Error: Your server is full and you cannot invite more players to join it right now!"),
PLAYER_IN_DIFFERENT_PARTY("Error: {0} is in a different party.")
PLAYER_IN_DIFFERENT_PARTY("Error: {0} is in a different party."),
PARTNER_ALREADY_INVITED("Error: You have already invited {0} to be your partner for {1}."),
PARTNER_NO_GAME("Error: {0} is not a valid game name."),
PARTNER_NO_PLAYER("Error: You didn't specify a player to partner with."),
PARTNER_NOT_ONLINE("Error: {0} is not on your server!"),
PARTNER_PLAYER_NOT_REQUESTED("Error: {0} hasn't made a partner request with you yet!"),
PARTNER_USAGE("Usage: /teampref accept/deny <player>."),
PARTNER_HOVER_TEXT_ACCEPT("Click to be {0}''s partner for {1}."),
PARTNER_HOVER_TEXT_DENY("Click to decline being {0}''s partner for {1}."),
PARTNER_REQUEST_SENT("Partner request sent to {0} for {1}."),
PARTNER_REQUEST_RECEIVED("Partner request from {0} for {1}."),
PARTNER_REQUEST_DENIED_SENDER("{0} has declined your partner request for {1}."),
PARTNER_REQUEST_DENIED_PLAYER("You have denied {0}''s partner request for {1}."),
PARTNER_REQUEST_ACCEPT_SENDER("{0} has accepted your partner request for {1}."),
PARTNER_REQUEST_ACCEPT_PLAYER("You have accepted {0}''s partner request for {1}."),
;
private String _message;
Lang(String message)
@ -55,6 +71,16 @@ public enum Lang
_message = message;
}
public String toString(String... args)
{
return getFormatted(args);
}
public void sendHeader(Player player, String header, String... args)
{
player.sendMessage(F.main(header, getFormatted(args)));
}
public void send(Player player, String... args)
{
player.sendMessage(C.mHead + "Party> " + getFormatted(args));
@ -65,16 +91,16 @@ public enum Lang
party.sendMessage(C.mHead + "Party> " + getFormatted(args));
}
private String getFormatted(String[] args)
private String getFormatted(String... args)
{
String color = C.mBody;
if(args.length == 0)
if (args == null || args.length == 0)
{
return color + _message;
}
if(_message.startsWith("Error:"))
if (_message.startsWith("Error:"))
{
color = C.cRed;
}
@ -83,7 +109,7 @@ public enum Lang
String[] coloredArgs = new String[args.length];
for(int i = 0; i < args.length; i++)
for (int i = 0; i < args.length; i++)
{
coloredArgs[i] = C.cYellow + args[i] + color;
}

View File

@ -35,10 +35,20 @@ public class Party
*/
private static final int PARTY_MAX_SIZE = 16;
/**
* Partners that have already been placed
*/
private transient final List<UUID> _teamed;
/**
* The current leader of this party
*/
private UUID _owner;
private String _owner;
/**
* The names of all current party members
*/
private List<String> _members;
/**
* The UUIDS of all current party members
@ -55,12 +65,17 @@ public class Party
*/
private int _size;
/**
* Team preferences
*/
private Map<UUID, Map<String, String>> _preferences;
/**
* Empty constructor for GSON
*/
public Party()
{
_teamed = Lists.newArrayList();
}
/**
@ -68,16 +83,31 @@ public class Party
*
* @param owner The owner / leader of the party.
*/
public Party(UUID owner)
public Party(String owner)
{
_owner = owner;
_members = Lists.newArrayList();
_invites = Maps.newHashMap();
_members.add(owner);
_teamed = Lists.newArrayList();
_membersByUUID = Lists.newArrayList();
_preferences = Maps.newHashMap();
_membersByUUID.add(Bukkit.getPlayerExact(owner).getUniqueId());
}
public String getOwner()
{
return Bukkit.getPlayer(_owner).getName();
return _owner;
}
/**
* Get the current members by their IGN
*
* @return The list of named party members
*/
public List<String> getMembers()
{
return _members;
}
public Map<String, Long> getInvites()
@ -94,12 +124,39 @@ public class Party
*/
public String getName()
{
return getOwner();
return _owner;
}
public List<UUID> getMembers()
/**
* Gets the players preferred teammate for a game
*
* @param player The player's UUID
* @return His team preference
*/
public String getPartner(UUID player, String game)
{
return this._membersByUUID;
Map<String, String> prefs = _preferences.get(player);
if (prefs == null)
{
prefs = Maps.newHashMap();
_preferences.put(player, prefs);
return null;
}
return prefs.get(game);
}
/**
* Set a player's partner preference
*
* @param player The player
* @param game The name of the game
* @param partner The name of his partner
*/
public void setPartner(Player player, String game, String partner)
{
Map<String, String> prefs = _preferences.getOrDefault(player.getUniqueId(), Maps.newHashMap());
prefs.put(game, partner);
_preferences.put(player.getUniqueId(), prefs);
}
/**
@ -109,7 +166,7 @@ public class Party
*/
public void sendMessage(String message)
{
getMembers().stream().map(Bukkit::getPlayer).forEach(player -> player.sendMessage(message));
getMembersByUUID().stream().map(Bukkit::getPlayer).forEach(player -> player.sendMessage(message));
}
public int getSize()
@ -133,14 +190,12 @@ public class Party
*/
public void onPlayerAdd(String player)
{
Player pl = Bukkit.getPlayerExact(player);
UUID uuid = pl.getUniqueId();
_invites.remove(player);
if(_membersByUUID.contains(uuid))
if(_members.contains(player))
{
return;
}
_membersByUUID.add(uuid);
_members.add(player);
Lang.ADD_MEMBER.send(this, player);
getMembers().forEach(s ->
{
@ -152,42 +207,46 @@ public class Party
/**
* Called when a member of the party is removed
*
* @param uuid The uuid of the player
* @param player The name of the player
* @param reason The reason for his removal.
*/
public void onPlayerRemove(UUID uuid, PartyRemoveReason reason)
public void onPlayerRemove(String player, PartyRemoveReason reason)
{
Player bukkitPlayer = Bukkit.getPlayer(uuid);
if(reason == PartyRemoveReason.DISBANDED)
{
Player bukkitPlayer = Bukkit.getPlayerExact(player);
Lang.DISBANDED.send(bukkitPlayer);
bukkitPlayer.closeInventory();
return;
}
if(_membersByUUID.size() <= 0)
if(_members.size() <= 0)
{
return;
}
if(reason == PartyRemoveReason.LEFT)
{
if(uuid.equals(_owner) && _membersByUUID.size() > 1)
if(player.equalsIgnoreCase(_owner) && _members.size() > 1)
{
_owner = _membersByUUID.get(0);
Lang.TRANSFER_OWNER.send(this, bukkitPlayer.getName(), getOwner());
PartyTransferOwnerEvent event = new PartyTransferOwnerEvent(this, getOwner(), bukkitPlayer.getName(), TransferReason.LEFT);
_owner = _members.get(0);
Lang.TRANSFER_OWNER.send(this, player, _owner);
PartyTransferOwnerEvent event = new PartyTransferOwnerEvent(this, _owner, player, TransferReason.LEFT);
UtilServer.getServer().getPluginManager().callEvent(event);
return;
}
Lang.REMOVE_PLAYER.send(this, bukkitPlayer.getName());
Lang.REMOVE_PLAYER.send(this, player);
return;
}
if(reason == PartyRemoveReason.OTHER)
{
return;
}
if(reason == PartyRemoveReason.KICKED)
{
Lang.REMOVE_PLAYER_KICK.send(this, bukkitPlayer.getName());
Lang.REMOVE_PLAYER_KICK.send(this, player);
}
}
@ -218,7 +277,7 @@ public class Party
*/
public void setOwner(String owner)
{
_owner = Bukkit.getPlayerExact(owner).getUniqueId();
_owner = owner;
}
/**
@ -241,11 +300,6 @@ public class Party
_alreadyTeamed = alreadyTeamed;
}
public UUID getOwnerId()
{
return this._owner;
}
/**
* Check to see if this party contains a certain player name
* This is case-insensitive
@ -255,7 +309,7 @@ public class Party
*/
public boolean contains(String name)
{
for(UUID member : _membersByUUID)
for (UUID member : _membersByUUID)
{
if (Bukkit.getPlayer(member).getName().equalsIgnoreCase(name))
{
@ -264,4 +318,17 @@ public class Party
}
return false;
}
public boolean isAlreadyTeamed(UUID uuid)
{
return _teamed.contains(uuid);
}
public void setTeamed(Player... players)
{
for (Player player : players)
{
_teamed.add(player.getUniqueId());
}
}
}

View File

@ -1,11 +1,11 @@
package mineplex.core.party;
import mineplex.core.common.Rank;
import mineplex.core.menu.Menu;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.event.PartyMemberKickGUIEvent;
import mineplex.core.party.event.PartySendToServerEvent;
import mineplex.core.party.event.PartyTransferOwnerEvent;
import mineplex.core.party.ui.Menu;
import mineplex.core.portal.ServerTransferEvent;
import mineplex.serverdata.data.MinecraftServer;
import org.bukkit.Bukkit;
@ -47,11 +47,11 @@ public class PartyEventListener implements Listener
Player bukkitPlayer = Bukkit.getPlayerExact(partyName);
if (party == null && bukkitPlayer != null)
if (party == null)
{
party = new Party(bukkitPlayer.getUniqueId());
party = new Party(partyName);
if (_plugin.getClientManager().Get(bukkitPlayer).GetRank().has(Rank.ULTRA))
if (bukkitPlayer != null && _plugin.getClientManager().Get(bukkitPlayer).GetRank().has(Rank.ULTRA))
{
party.setSize();
} else
@ -109,7 +109,7 @@ public class PartyEventListener implements Listener
Player clicked = Bukkit.getPlayerExact(event.getPlayerClicked());
Lang.REMOVED.send(clicked);
_plugin.getMethodManager().removeFromParty(clicked, PartyRemoveReason.KICKED);
Menu.get(event.getOwner().getUniqueId()).resetAndUpdate(event.getOwner());
Menu.get(event.getOwner().getUniqueId()).resetAndUpdate();
}
@EventHandler

View File

@ -10,17 +10,17 @@ import mineplex.core.party.manager.PartyInviteManager;
import mineplex.core.party.manager.PartyJoinManager;
import mineplex.core.party.manager.PartyMethodManager;
import mineplex.core.party.manager.PartyRedisManager;
import mineplex.core.party.ui.MenuListener;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.servers.ServerManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.Map;
import java.util.UUID;
@ -58,7 +58,9 @@ public class PartyManager extends MiniPlugin
/**
* A map of owner (name) -> party server wide
*/
private final Map<UUID, Party> _parties = Maps.newHashMap();
private final Map<String, Party> _parties = Maps.newHashMap();
private final Region _region;
public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager)
{
@ -78,13 +80,14 @@ public class PartyManager extends MiniPlugin
_methodManager = new PartyMethodManager(this);
addCommand(new PartyCommand(this));
getPluginManager().registerEvents(new MenuListener(), getPlugin());
new PartyEventListener(this);
_region = !new File("eu.dat").exists() ? Region.US : Region.EU;
}
public Party getParty(String party)
{
return _parties.get(Bukkit.getPlayerExact(party).getUniqueId());
return _parties.get(party);
}
public Party getParty(Player player)
@ -94,12 +97,12 @@ public class PartyManager extends MiniPlugin
public void addParty(Party party)
{
_parties.put(party.getOwnerId(), party);
_parties.put(party.getName(), party);
}
public void removeParty(Party party)
{
_parties.remove(party.getOwnerId());
_parties.remove(party.getName());
}
public Portal getPortal()
@ -147,8 +150,14 @@ public class PartyManager extends MiniPlugin
return _players;
}
public Map<UUID, Party> getParties()
public Map<String, Party> getParties()
{
return _parties;
}
public Region getRegion()
{
return _region;
}
}

View File

@ -0,0 +1,167 @@
package mineplex.core.party.command;
import com.google.common.collect.Maps;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.game.GameDisplay;
import mineplex.core.party.Lang;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Map;
import java.util.UUID;
/**
* Unused for now.
*/
public class TeamPreferenceCommand extends CommandBase<PartyManager>
{
private static final String[] ARGS = {
"teampref",
"teamprefs",
"teamp",
"tprefs",
"teampreferences"
};
private final String ACCEPT = "accept";
private final String DENY = "deny";
private final String ACCEPT_COMMAND = "/teamprefs accept ";
private final String DENY_COMMAND = "/teamprefs deny ";
private final String HEADER = "Partners";
//Player, Partner, GameName
private Map<UUID, Map<String, String>> INVITES = Maps.newHashMap();
public TeamPreferenceCommand(PartyManager plugin)
{
super(plugin, Rank.ALL, ARGS);
}
@Override
public void Execute(Player player, String[] args)
{
if (args.length < 2)
{
Lang.PARTNER_USAGE.sendHeader(player, HEADER);
return;
}
String arg = args[0];
if (arg.equalsIgnoreCase(ACCEPT) || arg.equalsIgnoreCase(DENY))
{
Party party = Plugin.getParty(player);
if (party == null)
{
Lang.NO_PARTY.send(player);
return;
}
String inviter = args[1];
boolean accept = arg.equalsIgnoreCase(ACCEPT);
Player inviterPlayer = Bukkit.getPlayerExact(inviter);
if (inviterPlayer == null)
{
Lang.PARTNER_NOT_ONLINE.sendHeader(player, HEADER, inviter);
return;
}
Map<String, String> sent = INVITES.get(inviterPlayer.getUniqueId());
if (sent == null || sent.isEmpty())
{
Lang.PARTNER_PLAYER_NOT_REQUESTED.sendHeader(player, HEADER, inviter);
return;
}
if (sent.get(player.getName()) == null)
{
Lang.PARTNER_PLAYER_NOT_REQUESTED.sendHeader(player, HEADER, inviter);
return;
}
String gameName = sent.remove(player.getName());
if (!accept)
{
Lang.PARTNER_REQUEST_DENIED_PLAYER.send(player, inviterPlayer.getName(), gameName);
Lang.PARTNER_REQUEST_DENIED_SENDER.send(inviterPlayer, player.getName(), gameName);
return;
}
Lang.PARTNER_REQUEST_ACCEPT_PLAYER.send(player, inviterPlayer.getName(), gameName);
Lang.PARTNER_REQUEST_ACCEPT_SENDER.send(inviterPlayer, player.getName(), gameName);
party.setPartner(player, gameName, inviterPlayer.getName());
party.setPartner(inviterPlayer, gameName, player.getName());
return;
}
Player target = Bukkit.getPlayerExact(arg);
String gameName = "";
String[] game = new String[args.length - 2];
System.arraycopy(args, 2, game, 0, game.length);
for (String s : game)
{
gameName += s + " ";
}
gameName = gameName.trim();
GameDisplay gameDisplay = GameDisplay.matchName(gameName);
if (gameDisplay == null)
{
Lang.PARTNER_NO_GAME.sendHeader(player, HEADER, gameName);
return;
}
gameName = gameDisplay.getName();
if (alreadyInvited(player, gameName, target.getName()))
{
Lang.PARTNER_ALREADY_INVITED.sendHeader(player, HEADER, target.getName(), gameName);
return;
}
sendRequest(player, gameName, target);
}
private void sendRequest(Player player, String game, Player partner)
{
invite(player, game, partner);
String gameName = C.cGreen + (game);
String playerName = C.cGreen + (player.getName());
String partnerName = C.cGreen + (partner.getName());
String acceptCommand = ACCEPT_COMMAND + player.getName();
String declineCommand = DENY_COMMAND + player.getName();
String acceptText = Lang.PARTNER_HOVER_TEXT_ACCEPT.toString(playerName, gameName);
String declineText = Lang.PARTNER_HOVER_TEXT_DENY.toString(playerName, gameName);
Lang.PARTNER_REQUEST_SENT.sendHeader(player, HEADER, partnerName, gameName);
Lang.PARTNER_REQUEST_RECEIVED.sendHeader(partner, HEADER, playerName, gameName);
UtilPlayer.sendAcceptOrDeny(partner, HEADER, acceptCommand, acceptText, declineCommand, declineText, null, null);
}
private boolean alreadyInvited(Player player, String game, String partner)
{
Map<String, String> sent = INVITES.get(player.getUniqueId());
return !(sent == null || sent.isEmpty()) && sent.get(partner).equalsIgnoreCase(game);
}
private void invite(Player player, String game, Player partner)
{
Map<String, String> sent = INVITES.getOrDefault(player.getUniqueId(), Maps.newHashMap());
sent.put(partner.getName(), game);
INVITES.put(player.getUniqueId(), sent);
}
}

View File

@ -80,7 +80,7 @@ public class PartyInviteManager
}
if (newParty == null)
{
newParty = new Party(possible.getUniqueId());
newParty = new Party(possible.getName());
if(_plugin.getClientManager().Get(possible).GetRank().has(Rank.ULTRA))
{
newParty.setSize();

View File

@ -8,6 +8,7 @@ import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.constants.JoinResponseReason;
import mineplex.core.party.redis.RedisMessageType;
import mineplex.serverdata.servers.ServerManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -32,6 +33,27 @@ public class PartyJoinManager
_transferring = Lists.newArrayList();
}
/**
* Scans through the party to check if all players are some form of VIP
* If the party contains even 1 non-vip, the party cannot be sent to a full server
*
* @param party The party
* @return <code>true</code> if the party contains all VIP's <code>false</code> if it contains even 1 non-vip
*/
public boolean canJoinFullServer(Party party)
{
List<Player> players = party.getMembersByUUID().stream().map(Bukkit::getPlayer).collect(Collectors.toList());
for (Player player : players)
{
Rank rank = _plugin.getClientManager().Get(player).GetRank();
if (rank == Rank.ALL)
{
return false;
}
}
return true;
}
/**
* Initiates a request to join a server for a specific party
*
@ -40,17 +62,7 @@ public class PartyJoinManager
*/
public void requestServerJoin(String server, Party party)
{
boolean canJoinFull = true;
List<Player> players = party.getMembers().stream().map(Bukkit::getPlayer).collect(Collectors.toList());
for (Player player : players)
{
Rank rank = _plugin.getClientManager().Get(player).GetRank();
if (rank == Rank.ALL)
{
canJoinFull = false;
break;
}
}
boolean canJoinFull = canJoinFullServer(party);
_plugin.getRedisManager().publish(server, RedisMessageType.PREJOIN_SERVER_REQUEST,
_plugin.getServerName(), party.getOwner(), "" + party.getMembers().size(), "" + canJoinFull);
}
@ -75,7 +87,7 @@ public class PartyJoinManager
return;
}
}
ServerManager.getServerRepository(_plugin.getRegion()).getServerStatus(_plugin.getServerName()).incrementPlayerCount(partySize);
_plugin.getRedisManager().publish(serverFrom, RedisMessageType.PREJOIN_SERVER_RESPONSE, initiator, JoinResponseReason.SUCCESS.name(), _plugin.getServerName());
}

View File

@ -2,11 +2,12 @@ package mineplex.core.party.manager;
import com.google.common.collect.Lists;
import mineplex.core.common.util.F;
import mineplex.core.menu.Menu;
import mineplex.core.party.Lang;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.ui.Menu;
import mineplex.core.preferences.Preference;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -75,7 +76,7 @@ public class PartyMethodManager
//Same Server
if (possible != null)
{
if(!_plugin.getPreferencesManager().Get(possible).PartyRequests)
if(!_plugin.getPreferencesManager().get(possible).isActive(Preference.PARTY_REQUESTS))
{
caller.sendMessage(F.main("Party> ", F.name(target) + " is not accepting invites at this time."));
return;
@ -83,7 +84,7 @@ public class PartyMethodManager
if (party == null)
{
if(_plugin.getParty(possible) != null)
if(_plugin.getParty(target) != null)
{
Lang.PLAYER_IN_DIFFERENT_PARTY.send(caller, target);
return;
@ -117,7 +118,7 @@ public class PartyMethodManager
}
//Not on the same server
_plugin.getRedisManager().findAndInvite(target, caller);
_plugin.getRedisManager().findAndInvite(target, caller.getName());
}
/**
@ -265,7 +266,8 @@ public class PartyMethodManager
{
return;
}
party.onPlayerRemove(uuid, PartyRemoveReason.OTHER);
String player = Bukkit.getPlayer(uuid).getName();
party.onPlayerRemove(player, PartyRemoveReason.OTHER);
}
public void removeFromParty(UUID uuid, PartyRemoveReason reason)
@ -293,7 +295,7 @@ public class PartyMethodManager
}
party.getMembers().remove(player.getName());
party.getMembersByUUID().remove(uuid);
party.onPlayerRemove(player.getUniqueId(), reason);
party.onPlayerRemove(player.getName(), reason);
int size = party.getMembers().size();
if(size <= 1)
@ -303,7 +305,7 @@ public class PartyMethodManager
_plugin.removeParty(party);
return;
}
_plugin.getPlayerParties().remove(party.getMembers().get(0));
_plugin.getPlayerParties().remove(Bukkit.getPlayerExact(party.getMembers().get(0)).getUniqueId());
party.onPlayerRemove(party.getMembers().get(0), PartyRemoveReason.DISBANDED);
_plugin.removeParty(party);
}
@ -326,14 +328,19 @@ public class PartyMethodManager
public void transferOwner(String newOwner, String oldOwner)
{
Party party = _plugin.getParties().remove(Bukkit.getPlayerExact(oldOwner).getUniqueId());
Party party = _plugin.getParties().remove(oldOwner);
if(party == null)
{
return;
}
_plugin.getParties().put(Bukkit.getPlayerExact(newOwner).getUniqueId(), party);
_plugin.getParties().put(newOwner, party);
party.setOwner(newOwner);
party.getMembers().remove(Bukkit.getPlayerExact(oldOwner).getUniqueId());
party.getMembers().add(Bukkit.getPlayerExact(oldOwner).getUniqueId());
party.getMembers().remove(oldOwner);
party.getMembers().add(oldOwner);
UUID uuid = Bukkit.getPlayerExact(oldOwner).getUniqueId();
party.getMembersByUUID().remove(uuid);
party.getMembersByUUID().add(uuid);
}
}

View File

@ -12,6 +12,7 @@ import mineplex.core.party.constants.JoinResponseReason;
import mineplex.core.party.event.PartyDataReceivedEvent;
import mineplex.core.party.redis.PartyRedisListener;
import mineplex.core.party.redis.RedisMessageType;
import mineplex.core.preferences.Preference;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@ -120,7 +121,7 @@ public class PartyRedisManager
return;
}
if(!_plugin.getPreferencesManager().Get(player).PartyRequests)
if(!_plugin.getPreferencesManager().get(player).isActive(Preference.PARTY_REQUESTS))
{
publish(first, RedisMessageType.INVITE_PLAYER_NOT_ACCEPTING_INVITES, _serverName, player.getName(), player.getUniqueId().toString(), third);
return;
@ -191,9 +192,9 @@ public class PartyRedisManager
* @param player The player target
* @param sender The sending player
*/
public void findAndInvite(String player, Player sender)
public void findAndInvite(String player, String sender)
{
sender.sendMessage(F.main("Party", "Locating " + F.elem(player) + "..."));
Bukkit.getPlayerExact(sender).sendMessage(F.main("Party", "Locating " + F.elem(player) + "..."));
TASKS.put(player, new BukkitRunnable()
{
@Override
@ -205,19 +206,25 @@ public class PartyRedisManager
return;
}
TASKS.remove(player);
Player senderPlayer = Bukkit.getPlayerExact(sender);
if (senderPlayer == null)
{
cancel();
return;
}
if (Bukkit.getPlayerExact(player) != null)
{
cancel();
return;
}
sender.sendMessage(F.main("Party", "Could not locate " + F.elem(player) + "."));
senderPlayer.sendMessage(F.main("Party", "Could not locate " + F.elem(player) + "."));
}
}.runTaskLater(_plugin.getPlugin(), 20L * 5));
_plugin.runAsync(() -> {
try (Jedis jedis = _writePool.getResource())
{
jedis.publish(FIND_PLAYERS_CHANNEL, RedisMessageType.PLAYER_FIND_REQUEST.format(_serverName, player, sender.getName()));
jedis.publish(FIND_PLAYERS_CHANNEL, RedisMessageType.PLAYER_FIND_REQUEST.format(_serverName, player, sender));
}
});
}
@ -237,7 +244,7 @@ public class PartyRedisManager
{
player1.leaveVehicle();
player1.eject();
_plugin.getPortal().sendPlayerToServer(player1, server, true);
_plugin.getPortal().sendPlayer(player1, server);
});
_plugin.removeParty(party);
}

View File

@ -1,45 +0,0 @@
package mineplex.core.party.ui;
import mineplex.core.party.PartyManager;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
/**
* An abstract class for managing buttons inside of menus
*/
public abstract class Button
{
private ItemStack _item;
private PartyManager _plugin;
public Button(ItemStack item, PartyManager plugin)
{
this._item = item;
_plugin = plugin;
}
/**
* The method called when a players clicks the slot
*
* @param player The player who clicked
*/
public abstract void onClick(Player player, ClickType clickType);
public ItemStack getItemStack()
{
return _item;
}
public void setItemStack(ItemStack item)
{
this._item = item;
}
public PartyManager getPlugin()
{
return _plugin;
}
}

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