Merge branch 'develop' of github.com:Mineplex-LLC/Minecraft-PC into update/skyfall

This commit is contained in:
xXVevzZXx 2016-11-17 19:19:28 +01:00
commit 26d8fe5e6e
205 changed files with 4273 additions and 2218 deletions

View File

@ -0,0 +1,4 @@
name: ClansGenerator
main: mineplex.clansgenerator.ClansGenerator
version: 1.0
author: Alex

View File

@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mineplex</groupId>
<artifactId>mineplex-plugin</artifactId>
<version>dev-SNAPSHOT</version>
<relativePath>../plugin.xml</relativePath>
</parent>
<name>ClansGenerator</name>
<artifactId>mineplex-clansgenerator</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mineplex-core-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,176 @@
package mineplex.clansgenerator;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
import org.bukkit.event.world.ChunkPopulateEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.WatchdogThread;
import net.minecraft.server.v1_8_R3.BiomeBase;
public class ClansGenerator extends JavaPlugin implements Runnable, Listener
{
private static final int MIN_X = -100;
private static final int MIN_Z = -100;
private static final int MAX_X = 100;
private static final int MAX_Z = 100;
private File _root;
private File _outputDir;
private boolean _debug = false;
public void onEnable()
{
_root = new File(".");
if (!_root.exists())
{
getLogger().severe("Root folder does not exist. Aborting");
getServer().shutdown();
return;
}
_outputDir = new File(_root, "output");
if (new File(_root, "DEBUG.dat").exists())
{
_debug = true;
}
if (!_outputDir.exists())
{
if (_debug)
{
getLogger().info("Creating map output directory!");
}
_outputDir.mkdir();
}
BiomeBase.getBiomes()[BiomeBase.OCEAN.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.PLAINS.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.DESERT.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.EXTREME_HILLS.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.FOREST.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.TAIGA.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.SWAMPLAND.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.RIVER.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.HELL.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.SKY.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.FROZEN_OCEAN.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.FROZEN_RIVER.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.ICE_PLAINS.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.ICE_MOUNTAINS.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.MUSHROOM_ISLAND.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.MUSHROOM_SHORE.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.BEACH.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.DESERT_HILLS.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.FOREST_HILLS.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.TAIGA_HILLS.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.SMALL_MOUNTAINS.id] = BiomeBase.PLAINS;
BiomeBase.getBiomes()[BiomeBase.JUNGLE.id] = BiomeBase.EXTREME_HILLS;
BiomeBase.getBiomes()[BiomeBase.JUNGLE_HILLS.id] = BiomeBase.EXTREME_HILLS;
BiomeBase.getBiomes()[BiomeBase.JUNGLE_EDGE.id] = BiomeBase.EXTREME_HILLS;
BiomeBase.getBiomes()[BiomeBase.DEEP_OCEAN.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.STONE_BEACH.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.COLD_BEACH.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.BIRCH_FOREST.id] = BiomeBase.BIRCH_FOREST;
BiomeBase.getBiomes()[BiomeBase.BIRCH_FOREST_HILLS.id] = BiomeBase.BIRCH_FOREST_HILLS;
BiomeBase.getBiomes()[BiomeBase.ROOFED_FOREST.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.COLD_TAIGA.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.COLD_TAIGA_HILLS.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.MEGA_TAIGA.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.MEGA_TAIGA_HILLS.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.EXTREME_HILLS_PLUS.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.SAVANNA.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.SAVANNA_PLATEAU.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.MESA.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.MESA_PLATEAU_F.id] = BiomeBase.FOREST;
BiomeBase.getBiomes()[BiomeBase.MESA_PLATEAU.id] = BiomeBase.FOREST;
WatchdogThread.doStop();
getServer().getScheduler().runTaskTimer(this, this, 20L, 100L);
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onPopulate(ChunkPopulateEvent event)
{
Block block;
for (int x = 0; x < 16; x++)
{
for (int y = 1; y < 128; y++)
{
for (int z = 0; z < 16; z++)
{
block = event.getChunk().getBlock(x, y, z);
if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST || block.getType() == Material.MOB_SPAWNER)
{
block.setType(Material.AIR);
if (_debug)
{
getLogger().info("Removing dungeon pieces");
}
}
}
}
}
}
@EventHandler
public void onJoin(AsyncPlayerPreLoginEvent event)
{
event.setLoginResult(Result.KICK_OTHER);
event.setKickMessage("Shoo, go away");
}
public void run()
{
int nextFileId = 0;
for (int existingFiles = 0; new File(_outputDir, "Clans_Map_" + existingFiles).exists(); existingFiles++)
{
nextFileId++;
}
getLogger().info("Generating world id " + nextFileId);
World world = (new WorldCreator("Clans_Map_" + nextFileId)).environment(Environment.NORMAL).generateStructures(false).seed(ThreadLocalRandom.current().nextLong()).createWorld();
world.setKeepSpawnInMemory(false);
for (int x = MIN_X; x <= MAX_X; x++)
{
getLogger().info("Generating chunks for x coord " + x);
for (int z = MIN_Z; z <= MAX_Z; z++)
{
world.getChunkAt(x, z).load(true);
}
}
for (int x = MIN_X; x <= MAX_X; x++)
{
getLogger().info("Unloading chunks for x coord " + x);
for (int z = MIN_Z; z <= MAX_Z; z++)
{
world.getChunkAt(x, z).unload(true, false);
}
}
getLogger().info("Unloading and saving world");
Bukkit.unloadWorld(world, true);
getLogger().info("Finished unloading and saving world");
try
{
FileUtils.moveDirectoryToDirectory(new File(_root, "Clans_Map_" + nextFileId), _outputDir, false);
}
catch (IOException e)
{
e.printStackTrace();
}
getLogger().info("Finished generating world id " + nextFileId);
getServer().shutdown();
}
}

View File

@ -304,11 +304,11 @@ public class UtilBlock
blockUseSet.add((byte) Material.JUNGLE_FENCE_GATE.getId()); blockUseSet.add((byte) Material.JUNGLE_FENCE_GATE.getId());
blockUseSet.add((byte) Material.DARK_OAK_FENCE_GATE.getId()); blockUseSet.add((byte) Material.DARK_OAK_FENCE_GATE.getId());
blockUseSet.add((byte) Material.ACACIA_FENCE_GATE.getId()); blockUseSet.add((byte) Material.ACACIA_FENCE_GATE.getId());
blockUseSet.add((byte) Material.SPRUCE_FENCE.getId()); blockUseSet.add((byte) Material.SPRUCE_FENCE_GATE.getId());
blockUseSet.add((byte) Material.BIRCH_FENCE.getId()); blockUseSet.add((byte) Material.BIRCH_FENCE_GATE.getId());
blockUseSet.add((byte) Material.JUNGLE_FENCE.getId()); blockUseSet.add((byte) Material.JUNGLE_FENCE_GATE.getId());
blockUseSet.add((byte) Material.DARK_OAK_FENCE.getId()); blockUseSet.add((byte) Material.DARK_OAK_FENCE_GATE.getId());
blockUseSet.add((byte) Material.ACACIA_FENCE.getId()); blockUseSet.add((byte) Material.ACACIA_FENCE_GATE.getId());
blockUseSet.add((byte) Material.SPRUCE_DOOR.getId()); blockUseSet.add((byte) Material.SPRUCE_DOOR.getId());
blockUseSet.add((byte) Material.BIRCH_DOOR.getId()); blockUseSet.add((byte) Material.BIRCH_DOOR.getId());

View File

@ -524,5 +524,33 @@ public class UtilBlockText
{0,1,0,0}, {0,1,0,0},
{1,1,1,1} {1,1,1,1}
}); });
alphabet.put(':', new int[][]
{
{0},
{1},
{0},
{1},
{0}
});
alphabet.put('=', new int[][]
{
{0,0,0},
{1,1,1},
{0,0,0},
{1,1,1},
{0,0,0}
});
// THIS IS A SINGLE SPACE
alphabet.put('|', new int[][]
{
{0},
{0},
{0},
{0},
{0}
});
} }
} }

View File

@ -114,4 +114,22 @@ public class UtilFirework
playFirework(location, FireworkEffect.builder().withColor(Color.RED).withColor(Color.BLUE) playFirework(location, FireworkEffect.builder().withColor(Color.RED).withColor(Color.BLUE)
.withColor(Color.WHITE).withFade(Color.RED).withFade(Color.BLUE).withFade(Color.WHITE).build()); .withColor(Color.WHITE).withFade(Color.RED).withFade(Color.BLUE).withFade(Color.WHITE).build());
} }
public static FireworkEffect getRandomFireworkEffect(boolean fade, int maxColors, int maxFade)
{
FireworkEffect.Builder builder = FireworkEffect.builder().with(Type.values()[UtilMath.r(Type.values().length)])
.withColor(Color.fromRGB(UtilMath.r(256), UtilMath.r(256), UtilMath.r(256))).flicker(UtilMath.random.nextBoolean()).trail(UtilMath.random.nextBoolean());
if (fade)
{
for (int i = 0; i < maxFade; i++)
{
builder.withFade(Color.fromRGB(UtilMath.r(256), UtilMath.r(256), UtilMath.r(256)));
}
}
for (int i = 0; i < maxColors; i++)
{
builder.withColor(Color.fromRGB(UtilMath.r(256), UtilMath.r(256), UtilMath.r(256)));
}
return builder.build();
}
} }

View File

@ -9,6 +9,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.NBTTagLong;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -22,8 +25,6 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.structs.ItemContainer; import mineplex.core.common.structs.ItemContainer;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.NBTTagLong;
public class UtilItem public class UtilItem
{ {
@ -1216,6 +1217,27 @@ public class UtilItem
return ent; return ent;
} }
public static ItemStack getVersionSpecificItem(Player player, UtilPlayer.PlayerVersion requiredVersion, ItemStack base)
{
if (UtilPlayer.getPlayerVersion(player).compare(requiredVersion))
{
return base;
}
else
{
ItemStack barrier = new ItemStack(Material.BARRIER);
ItemMeta meta = barrier.getItemMeta();
meta.setDisplayName(base.getItemMeta().getDisplayName());
List<String> lore = new ArrayList<>();
lore.addAll(base.getItemMeta().getLore());
lore.add(" ");
lore.add(C.cRedB + "REQUIRES VERSION " + requiredVersion.getFriendlyName() + "+!");
meta.setLore(lore);
barrier.setItemMeta(meta);
return barrier;
}
}
public static double getAttackDamage(Material type) public static double getAttackDamage(Material type)
{ {
return ItemDamage.get(type); return ItemDamage.get(type);

View File

@ -3,6 +3,7 @@ package mineplex.core.common.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -10,8 +11,21 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
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.EntityTracker;
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
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.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@ -33,18 +47,6 @@ import org.bukkit.util.Vector;
import mineplex.core.common.MinecraftVersion; import mineplex.core.common.MinecraftVersion;
import mineplex.core.common.events.PlayerMessageEvent; 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.EntityTracker;
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
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 java.util.*;
public class UtilPlayer public class UtilPlayer
{ {
@ -1124,4 +1126,49 @@ public class UtilPlayer
{ {
return (playerUUID.hashCode() & 1) == 1; return (playerUUID.hashCode() & 1) == 1;
} }
public static PlayerVersion getPlayerVersion(Player player)
{
int playerVersion = ((CraftPlayer) player).getHandle().playerConnection.networkManager.getVersion();
if (playerVersion >= 210)
{
return PlayerVersion._1_10;
}
else if (playerVersion >= 107)
{
return PlayerVersion._1_9;
}
return PlayerVersion._1_8;
}
public enum PlayerVersion
{
_1_8(47, "1.8"),
_1_9(107, "1.9"),
_1_10(210, "1.10");
private int _version;
private String _friendlyName;
PlayerVersion(int version, String friendlyName)
{
_version = version;
_friendlyName = friendlyName;
}
public int getVersion()
{
return _version;
}
public String getFriendlyName()
{
return _friendlyName;
}
public boolean compare(PlayerVersion versionToCompare)
{
return versionToCompare.getVersion() >= getVersion();
}
}
} }

View File

@ -1,6 +1,12 @@
package mineplex.core.common.util; package mineplex.core.common.util;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -764,4 +770,35 @@ public class UtilText
} }
return stringBuilder.toString(); return stringBuilder.toString();
} }
/**
* Creates an image based on a string
* Removed from EffectLib
* @param font The font that is used
* @param s The string
* @return A buffered image containing the text
*/
public static BufferedImage stringToBufferedImage(Font font, String s) {
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = img.getGraphics();
g.setFont(font);
FontRenderContext frc = g.getFontMetrics().getFontRenderContext();
Rectangle2D rect = font.getStringBounds(s, frc);
g.dispose();
img = new BufferedImage((int) Math.ceil(rect.getWidth()), (int) Math.ceil(rect.getHeight()), BufferedImage.TYPE_4BYTE_ABGR);
g = img.getGraphics();
g.setColor(Color.black);
g.setFont(font);
FontMetrics fm = g.getFontMetrics();
int x = 0;
int y = fm.getAscent();
g.drawString(s, x, y);
g.dispose();
return img;
}
} }

View File

@ -9,16 +9,6 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mineplex.core.common.DummyEntity;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.event.CustomTagEvent;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketVerifier;
import mineplex.core.packethandler.PacketInfo;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import net.minecraft.server.v1_8_R3.DataWatcher; import net.minecraft.server.v1_8_R3.DataWatcher;
import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject; import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject;
import net.minecraft.server.v1_8_R3.Entity; import net.minecraft.server.v1_8_R3.Entity;
@ -42,10 +32,19 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.DummyEntity;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.event.CustomTagEvent;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.core.packethandler.PacketVerifier;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class CustomTagFix extends MiniPlugin implements IPacketHandler public class CustomTagFix extends MiniPlugin implements IPacketHandler
{ {
private Map<UUID, Map<Integer, Integer[]>> _entityMap = new HashMap<>(); private Map<UUID, Map<Integer, Integer[]>> _entityMap = new HashMap<>();
@ -524,9 +523,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler
} }
else else
{ {
PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(); PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(entityIds[0], watcher, true);
entityMetadata.a = entityIds[0];
entityMetadata.b = watcher.c();
packetList.bypassProcess(entityMetadata); packetList.bypassProcess(entityMetadata);
} }

View File

@ -44,6 +44,13 @@ public enum Achievement
new int[]{10}, new int[]{10},
AchievementCategory.HOLIDAY), AchievementCategory.HOLIDAY),
GLOBAL_CHICKEN_CHASER_2016("2016 Chicken Chaser", 4000,
new String[]{"Global.Thanksgiving Chickens 2016"},
new String[]{"Catch 200 Thanksgiving Chickens,",
"during Thanksgiving 2016!"},
new int[]{200},
AchievementCategory.HOLIDAY),
//Bridges //Bridges
BRIDGES_WINS("Bridge Champion", 600, BRIDGES_WINS("Bridge Champion", 600,
new String[]{"The Bridges.Wins"}, new String[]{"The Bridges.Wins"},

View File

@ -5,12 +5,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map.Entry;
import mineplex.core.MiniPlugin;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Location; import org.bukkit.Location;
@ -22,8 +17,15 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class BlockRestore extends MiniPlugin public class BlockRestore extends MiniPlugin
{ {
private HashMap<Block, BlockRestoreData> _blocks = new HashMap<Block, BlockRestoreData>(); private HashMap<Block, BlockRestoreData> _blocks = new HashMap<Block, BlockRestoreData>();
@ -99,6 +101,21 @@ public class BlockRestore extends MiniPlugin
_blocks.remove(cur); _blocks.remove(cur);
} }
@EventHandler
public void expireUnload(ChunkUnloadEvent event)
{
Iterator<Entry<Block, BlockRestoreData>> iterator = _blocks.entrySet().iterator();
while (iterator.hasNext())
{
Entry<Block, BlockRestoreData> entry = iterator.next();
if (entry.getKey().getChunk().equals(event.getChunk()))
{
entry.getValue().restore();
iterator.remove();
}
}
}
public boolean restore(Block block) public boolean restore(Block block)
{ {
if (!contains(block)) if (!contains(block))

View File

@ -1,5 +1,37 @@
package mineplex.core.bonuses; package mineplex.core.bonuses;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.TimeZone;
import java.util.UUID;
import net.minecraft.server.v1_8_R3.DataWatcher;
import net.minecraft.server.v1_8_R3.EntityCreeper;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
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.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import mineplex.core.MiniClientPlugin; import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
@ -47,36 +79,6 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.youtube.YoutubeManager; import mineplex.core.youtube.YoutubeManager;
import mineplex.database.Tables; import mineplex.database.Tables;
import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DBPool;
import net.minecraft.server.v1_8_R3.DataWatcher;
import net.minecraft.server.v1_8_R3.EntityCreeper;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
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.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.TimeZone;
import java.util.UUID;
public class BonusManager extends MiniClientPlugin<BonusClientData> implements ILoginProcessor public class BonusManager extends MiniClientPlugin<BonusClientData> implements ILoginProcessor
{ {
@ -676,7 +678,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
int availableRewards = 0; int availableRewards = 0;
if (_playWireManager.canRedeem(player)) availableRewards++; if (_playWireManager.Get(player) != null && _playWireManager.Get(player).getAccountId() == -1 && _playWireManager.canRedeemTickets(_playWireManager.Get(player))) availableRewards++;
if (_youtubeManager.canYoutube(player)) availableRewards++; if (_youtubeManager.canYoutube(player)) availableRewards++;
if (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) availableRewards++; if (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) availableRewards++;
if (canDaily(player)) availableRewards++; if (canDaily(player)) availableRewards++;
@ -719,9 +721,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
watcher.a(0, (byte) 0, EntityCreeper.META_ENTITYDATA, (byte) 0); watcher.a(0, (byte) 0, EntityCreeper.META_ENTITYDATA, (byte) 0);
watcher.a(1, (short) 300, EntityCreeper.META_AIR, 0); watcher.a(1, (short) 300, EntityCreeper.META_AIR, 0);
watcher.a(17, (byte) 1, EntityCreeper.META_POWERED, true); watcher.a(17, (byte) 1, EntityCreeper.META_POWERED, true);
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(); PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(_carlNpc.getEntity().getEntityId(), watcher, true);
packet.a = _carlNpc.getEntity().getEntityId();
packet.b = watcher.c();
UtilPlayer.sendPacket(player, packet); UtilPlayer.sendPacket(player, packet);
} }
@ -736,9 +736,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
// Charged // Charged
DataWatcher watcher = new DataWatcher(null); DataWatcher watcher = new DataWatcher(null);
watcher.a(17, (byte) 0, EntityCreeper.META_POWERED, false); watcher.a(17, (byte) 0, EntityCreeper.META_POWERED, false);
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(); PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(_carlNpc.getEntity().getEntityId(), watcher, true);
packet.a = _carlNpc.getEntity().getEntityId();
packet.b = watcher.c();
UtilPlayer.sendPacket(player, packet); UtilPlayer.sendPacket(player, packet);
} }
@ -841,7 +839,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{ {
if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false)) if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false))
{ {
if(_pollManager.hasPoll(player) || _playWireManager.canRedeem(player) || (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) || canDaily(player) || PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository)) if(_pollManager.hasPoll(player) || (_playWireManager.Get(player) != null && _playWireManager.Get(player).getAccountId() == -1 && _playWireManager.canRedeemTickets(_playWireManager.Get(player))) || (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) || canDaily(player) || PowerPlayClubButton.isAvailable(player, _powerPlayClubRepository))
{ {
if(_showCarl.containsKey(player.getName())) if(_showCarl.containsKey(player.getName()))
{ {

View File

@ -1,14 +1,15 @@
package mineplex.core.bonuses.gui.buttons; package mineplex.core.bonuses.gui.buttons;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.gui.GuiItem; import mineplex.core.gui.GuiItem;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.playwire.PlayWireManager; import mineplex.core.playwire.PlayWireManager;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
/** /**
* *
@ -20,11 +21,11 @@ public class PlayWireButton implements GuiItem
.setTitle(C.cGreen + C.Bold + "Watch an Ad!") .setTitle(C.cGreen + C.Bold + "Watch an Ad!")
.addLore( .addLore(
C.cWhite + "You have already redeemed your", C.cWhite + "You have already redeemed your",
C.cWhite + "rewards for watching the Ad!", C.cWhite + "rewards for watching the Ads!",
" ", " ",
C.cWhite + "You can watch it again, but you won't earn any shards!", C.cWhite + "You can watch some more, but you won't earn any rewards!",
" ", " ",
C.cWhite + "You can watch the Ad once every hour.", C.cWhite + "You can watch 5 Ads every 24 hours.",
" ", " ",
C.cWhite + "Ads help us keep Mineplex awesome", C.cWhite + "Ads help us keep Mineplex awesome",
C.cRedB + "Be sure to have your AdBlocker disabled!", C.cRedB + "Be sure to have your AdBlocker disabled!",
@ -36,11 +37,10 @@ public class PlayWireButton implements GuiItem
private static final ItemStack ENABLED_ICON = new ItemBuilder(Material.TRIPWIRE_HOOK) private static final ItemStack ENABLED_ICON = new ItemBuilder(Material.TRIPWIRE_HOOK)
.setTitle(C.cGreen + C.Bold + "Watch an Ad!") .setTitle(C.cGreen + C.Bold + "Watch an Ad!")
.addLore( .addLore(
C.cYellow + "Earn a 100 Shard Reward", C.cYellow + "Earn 1 Carl Spin Ticket",
C.cYellow + "and 1 Carl Spin Ticket",
C.cWhite + "by checking out our partner's Advertisement", C.cWhite + "by checking out our partner's Advertisement",
" ", " ",
C.cWhite + "You can watch the Ad once every hour.", C.cWhite + "You can watch 5 Ads every 24 hours.",
" ", " ",
C.cWhite + "Ads help us keep Mineplex awesome", C.cWhite + "Ads help us keep Mineplex awesome",
C.cRedB + "Be sure to have your AdBlocker disabled!", C.cRedB + "Be sure to have your AdBlocker disabled!",
@ -61,7 +61,11 @@ public class PlayWireButton implements GuiItem
@Override @Override
public ItemStack getObject() public ItemStack getObject()
{ {
return _manager.canRedeem(_player) ? ENABLED_ICON : DISABLED_ICON; if (_manager.Get(_player) == null || _manager.Get(_player).getAccountId() == -1)
{
return DISABLED_ICON;
}
return _manager.canRedeemTickets(_manager.Get(_player)) ? ENABLED_ICON : DISABLED_ICON;
} }
@Override @Override

View File

@ -11,6 +11,12 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
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 mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.BonusManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -22,11 +28,6 @@ import mineplex.core.powerplayclub.PowerPlayClubRepository;
import mineplex.core.powerplayclub.PowerPlayClubRewards; import mineplex.core.powerplayclub.PowerPlayClubRewards;
import mineplex.core.powerplayclub.PowerPlayData; import mineplex.core.powerplayclub.PowerPlayData;
import mineplex.core.shop.item.ShopItem; 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;
public class PowerPlayClubButton implements GuiItem public class PowerPlayClubButton implements GuiItem
{ {
@ -77,7 +78,7 @@ public class PowerPlayClubButton implements GuiItem
} }
else 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 + "!")); UtilPlayer.message(_player, F.main("Power Play Club", "You have no months left! Buy more months at " + F.greenElem("www.mineplex.com/shop") + "!"));
} }
} }
} }

View File

@ -85,8 +85,8 @@ public class YoutubeButton implements GuiItem
UtilPlayer.message(_player, C.cGold + C.Bold + C.Strike + "============================================="); UtilPlayer.message(_player, C.cGold + C.Bold + C.Strike + "=============================================");
UtilPlayer.message(_player, ""); UtilPlayer.message(_player, "");
new JsonMessage(" " + C.Bold + "Click to Open in Web Browser and " + message).click(ClickEvent.OPEN_URL, "https://www.youtube.com/embed/RW3sOmkiEG-A?list=UU1MtBclG_aHPd0nLmUupCKg&controls=0&showinfo=0&autoplay=1").sendToPlayer(_player); new JsonMessage(" " + C.Bold + "Click to Open in Web Browser and " + message).click(ClickEvent.OPEN_URL, "http://file.mineplex.com/ads.php").sendToPlayer(_player);
new JsonMessage( " " + C.cGreen + C.Line + "http://youtube.com/mineplexgamesofficial").click(ClickEvent.OPEN_URL, "https://www.youtube.com/embed/RW3sOmkiEG-A?list=UU1MtBclG_aHPd0nLmUupCKg&controls=0&showinfo=0&autoplay=1").sendToPlayer(_player); new JsonMessage( " " + C.cGreen + C.Line + "http://youtube.com/mineplexgamesofficial").click(ClickEvent.OPEN_URL, "http://file.mineplex.com/ads.php").sendToPlayer(_player);
UtilPlayer.message(_player, ""); UtilPlayer.message(_player, "");
UtilPlayer.message(_player, C.cGold + C.Bold + C.Strike + "============================================="); UtilPlayer.message(_player, C.cGold + C.Bold + C.Strike + "=============================================");
} }

View File

@ -20,6 +20,8 @@ import mineplex.core.report.data.Report;
*/ */
public class SnapshotManager public class SnapshotManager
{ {
public static final int MAX_SNAPSHOTS = 5;
// There aren't any List or Set caching implementations // There aren't any List or Set caching implementations
// For an easy work around, we store values as the Key // For an easy work around, we store values as the Key
// For the value we just use some dummy object // For the value we just use some dummy object
@ -38,7 +40,7 @@ public class SnapshotManager
_snapshotRepository = snapshotRepository; _snapshotRepository = snapshotRepository;
} }
public SnapshotRepository getSnapshotRepository() public SnapshotRepository getRepository()
{ {
return _snapshotRepository; return _snapshotRepository;
} }
@ -74,21 +76,21 @@ public class SnapshotManager
* Does not include PMs unless sender or receiver is in the exclusions collection. * Does not include PMs unless sender or receiver is in the exclusions collection.
* *
* @param accountId the account to search for messages involved in * @param accountId the account to search for messages involved in
* @param pmIdWhitelist a list of account ids of which to include PMs of * @param pmWhitelistIds a list of account ids of which to include PMs of
* @return the messages that the account is involved in * @return the messages that the account is involved in
*/ */
public Set<SnapshotMessage> getMessagesInvolving(int accountId, Collection<Integer> pmIdWhitelist) public Set<SnapshotMessage> getMessagesInvolving(int accountId, Collection<Integer> pmWhitelistIds)
{ {
return getMessagesInvolving(accountId).stream() return getMessagesInvolving(accountId).stream()
.filter(message -> includeMessage(message, pmIdWhitelist)) .filter(message -> includeMessage(message, pmWhitelistIds))
.collect(Collectors.toCollection(TreeSet::new)); .collect(Collectors.toCollection(TreeSet::new));
} }
private boolean includeMessage(SnapshotMessage message, Collection<Integer> pmExclusions) private boolean includeMessage(SnapshotMessage message, Collection<Integer> pmWhitelistIds)
{ {
return message.getType() != MessageType.PM || return message.getType() != MessageType.PM ||
pmExclusions.contains(message.getSenderId()) || pmWhitelistIds.contains(message.getSenderId()) ||
!Collections.disjoint(message.getRecipientIds(), pmExclusions); !Collections.disjoint(message.getRecipientIds(), pmWhitelistIds);
} }
/** /**
@ -134,9 +136,10 @@ public class SnapshotManager
public CompletableFuture<SnapshotMetadata> saveReportSnapshot(Report report, Collection<SnapshotMessage> messages) public CompletableFuture<SnapshotMetadata> saveReportSnapshot(Report report, Collection<SnapshotMessage> messages)
{ {
return _snapshotRepository SnapshotMetadata snapshotMetadata = report.getSnapshotMetadata().orElseThrow(() ->
.saveReportSnapshot(report, messages) new IllegalStateException("Report does not have associated snapshot."));
.whenComplete((snapshotMetadata, throwable) ->
return _snapshotRepository.insertMessages(snapshotMetadata.getId(), messages).whenComplete(((aVoid, throwable) ->
{ {
if (throwable == null) if (throwable == null)
{ {
@ -146,6 +149,6 @@ public class SnapshotManager
{ {
_javaPlugin.getLogger().log(Level.SEVERE, "Error whilst saving snapshot.", throwable); _javaPlugin.getLogger().log(Level.SEVERE, "Error whilst saving snapshot.", throwable);
} }
}); })).thenApply(aVoid -> snapshotMetadata);
} }
} }

View File

@ -11,6 +11,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.chatsnap.command.ChatSnapCommand;
import mineplex.core.message.PrivateMessageEvent; import mineplex.core.message.PrivateMessageEvent;
/** /**
@ -36,7 +37,7 @@ public class SnapshotPlugin extends MiniPlugin
@Override @Override
public void addCommands() public void addCommands()
{ {
addCommand(new ChatSnapCommand(this));
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)

View File

@ -6,15 +6,16 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.report.data.Report;
import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DBPool;
/** /**
@ -65,13 +66,14 @@ public class SnapshotRepository
return token; return token;
} }
private static final String INSERT_SNAPSHOT = "INSERT INTO snapshots (token, creator) VALUES (?, ?);"; private static final String INSERT_SNAPSHOT = "INSERT INTO snapshots (token, creatorId) VALUES (?, ?);";
private static final String INSERT_MESSAGE = "INSERT INTO snapshotMessages (senderId, `server`, `time`, message, snapshotType) VALUES (?, ?, ?, ?, ?);"; private static final String INSERT_MESSAGE = "INSERT INTO snapshotMessages (senderId, `server`, `time`, message, snapshotType) VALUES (?, ?, ?, ?, ?);";
private static final String INSERT_MESSAGE_RECIPIENT = "INSERT INTO snapshotRecipients (messageId, recipientId) VALUES (?, ?);"; private static final String INSERT_MESSAGE_RECIPIENT = "INSERT INTO snapshotRecipients (messageId, recipientId) VALUES (?, ?);";
private static final String INSERT_MESSAGE_MAPPING = "INSERT INTO snapshotMessageMap (snapshotId, messageId) VALUES (?, ?);"; private static final String INSERT_MESSAGE_MAPPING = "INSERT INTO snapshotMessageMap (snapshotId, messageId) VALUES (?, ?);";
private static final String GET_ID_FROM_TOKEN = "SELECT snapshots.id FROM snapshots WHERE snapshots.token = ?;"; private static final String GET_ID_FROM_TOKEN = "SELECT snapshots.id FROM snapshots WHERE snapshots.token = ?;";
private static final String GET_METADATA = "SELECT token, creator FROM snapshots WHERE id = ?;"; private static final String GET_METADATA = "SELECT token, creatorId FROM snapshots WHERE id = ?;";
private static final String SET_TOKEN = "UPDATE snapshots SET token = ? WHERE id = ?;"; private static final String SET_TOKEN = "UPDATE snapshots SET token = ? WHERE id = ?;";
private static final String GET_USER_SNAPSHOTS = "SELECT snapshots.id FROM snapshots WHERE snapshots.creatorId = ?;";
private final String _serverName; private final String _serverName;
private final Logger _logger; private final Logger _logger;
@ -82,42 +84,6 @@ public class SnapshotRepository
_logger = logger; _logger = logger;
} }
public CompletableFuture<SnapshotMetadata> saveReportSnapshot(Report report, Collection<SnapshotMessage> messages)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{
SnapshotMetadata snapshotMetadata = report.getSnapshotMetadata().orElseThrow(() ->
new IllegalStateException("Report does not have associated snapshot."));
insertMessages(snapshotMetadata.getId(), messages, connection);
return snapshotMetadata;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
public CompletableFuture<SnapshotMetadata> saveSnapshot(Collection<SnapshotMessage> messages)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{
SnapshotMetadata snapshotMetadata = createSnapshot(connection, null);
insertMessages(snapshotMetadata.getId(), messages, connection);
return snapshotMetadata;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
public CompletableFuture<SnapshotMetadata> createSnapshot(Integer creatorAccountId) public CompletableFuture<SnapshotMetadata> createSnapshot(Integer creatorAccountId)
{ {
return CompletableFuture.supplyAsync(() -> return CompletableFuture.supplyAsync(() ->
@ -218,7 +184,7 @@ public class SnapshotRepository
setToken(connection, snapshotId, token); setToken(connection, snapshotId, token);
} }
Integer creatorId = resultSet.getInt("creator"); Integer creatorId = resultSet.getInt("creatorId");
if (resultSet.wasNull()) creatorId = null; if (resultSet.wasNull()) creatorId = null;
return new SnapshotMetadata(snapshotId, token, creatorId); return new SnapshotMetadata(snapshotId, token, creatorId);
@ -244,6 +210,40 @@ public class SnapshotRepository
return future; return future;
} }
public CompletableFuture<List<Integer>> getUserSnapshots(int creatorId)
{
CompletableFuture<List<Integer>> future = CompletableFuture.supplyAsync(() ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{
PreparedStatement preparedStatement = connection.prepareStatement(GET_USER_SNAPSHOTS);
preparedStatement.setInt(1, creatorId);
ResultSet resultSet = preparedStatement.executeQuery();
List<Integer> snapshotIds = new ArrayList<>();
while (resultSet.next())
{
snapshotIds.add(resultSet.getInt("id"));
}
return snapshotIds;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
future.exceptionally(throwable ->
{
_logger.log(Level.SEVERE, "Error getting snapshots for user " + creatorId + ".");
return new ArrayList<>();
});
return future;
}
private void setToken(Connection connection, int snapshotId, String token) throws SQLException private void setToken(Connection connection, int snapshotId, String token) throws SQLException
{ {
try (PreparedStatement setTokenStatement = connection.prepareStatement(SET_TOKEN)) try (PreparedStatement setTokenStatement = connection.prepareStatement(SET_TOKEN))
@ -254,7 +254,11 @@ public class SnapshotRepository
} }
} }
private void insertMessages(int snapshotId, Collection<SnapshotMessage> messages, Connection connection) throws SQLException public CompletableFuture<Void> insertMessages(int snapshotId, Collection<SnapshotMessage> messages)
{
CompletableFuture<Void> future = CompletableFuture.supplyAsync(() ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{ {
try (PreparedStatement insertSnapshotStatement = connection.prepareStatement(INSERT_MESSAGE, new String[]{"id"})) try (PreparedStatement insertSnapshotStatement = connection.prepareStatement(INSERT_MESSAGE, new String[]{"id"}))
{ {
@ -276,24 +280,7 @@ public class SnapshotRepository
insertRecipientStatement.executeBatch(); insertRecipientStatement.executeBatch();
insertMappingStatement.executeBatch(); insertMappingStatement.executeBatch();
} return null;
}
}
}
public CompletableFuture<Void> insertMessage(int snapshotId, SnapshotMessage message)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{
try (PreparedStatement insertSnapshotStatement = connection.prepareStatement(INSERT_MESSAGE, new String[]{"id"}))
{
try (PreparedStatement insertRecipientStatement = connection.prepareStatement(INSERT_MESSAGE_RECIPIENT))
{
try (PreparedStatement insertMappingStatement = connection.prepareStatement(INSERT_MESSAGE_MAPPING))
{
insertMessage(insertSnapshotStatement, insertRecipientStatement, insertMappingStatement, snapshotId, message);
} }
} }
} }
@ -302,9 +289,15 @@ public class SnapshotRepository
{ {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
});
future.exceptionally(throwable ->
{
_logger.log(Level.SEVERE, "Error whilst inserting messages into snapshot.", throwable);
return null; return null;
}); });
return future;
} }
private void insertMessage(PreparedStatement insertSnapshotStatement, PreparedStatement insertRecipientStatement, PreparedStatement insertMappingStatement, int snapshotId, SnapshotMessage message) throws SQLException private void insertMessage(PreparedStatement insertSnapshotStatement, PreparedStatement insertRecipientStatement, PreparedStatement insertMappingStatement, int snapshotId, SnapshotMessage message) throws SQLException

View File

@ -0,0 +1,71 @@
package mineplex.core.chatsnap.command;
import java.util.Set;
import org.bukkit.entity.Player;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.SnapshotMessage;
import mineplex.core.chatsnap.SnapshotPlugin;
import mineplex.core.chatsnap.SnapshotRepository;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
/**
* A command which when executed will create a chat log which will be viewable online.
*/
public class ChatSnapCommand extends CommandBase<SnapshotPlugin>
{
public ChatSnapCommand(SnapshotPlugin plugin)
{
super(plugin, Rank.TITAN, "chatsnap");
}
@Override
public void Execute(Player player, String[] args)
{
if (args == null || args.length == 0)
{
SnapshotManager manager = Plugin.getSnapshotManager();
SnapshotRepository repository = manager.getRepository();
int accountId = _commandCenter.GetClientManager().getAccountId(player);
Plugin.getSnapshotManager().getRepository().getUserSnapshots(accountId).thenAccept(snapshotIds ->
{
if (snapshotIds.size() < SnapshotManager.MAX_SNAPSHOTS)
{
Set<SnapshotMessage> messages = manager.getMessagesInvolving(accountId);
repository.createSnapshot(accountId).thenAccept(snapshotMetadata ->
{
String token = snapshotMetadata.getToken().orElseThrow(() ->
new IllegalStateException("Snapshot doesn't have a token."));
repository.insertMessages(snapshotMetadata.getId(), messages).join();
UtilPlayer.message(player, F.main(Plugin.getName(), "Snapshot successfully created."));
new JsonMessage(F.main(Plugin.getName(), "Your snapshot token is: "))
.extra(F.elem(token))
.click(ClickEvent.OPEN_URL, SnapshotRepository.getURL(token))
.sendToPlayer(player);
});
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(),
C.cRed + "Cannot create snapshot, you have reached the limit."));
}
});
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Invalid Usage: " + F.elem("/" + _aliasUsed)));
}
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core.chatsnap.command; package mineplex.core.chatsnap.redis;
import java.util.Set; import java.util.Set;

View File

@ -1,4 +1,4 @@
package mineplex.core.chatsnap.command; package mineplex.core.chatsnap.redis;
import java.util.Set; import java.util.Set;
import mineplex.core.chatsnap.SnapshotMessage; import mineplex.core.chatsnap.SnapshotMessage;
@ -35,7 +35,7 @@ public class PushSnapshotsHandler implements CommandCallback
if (messages.size() > 0) if (messages.size() > 0)
{ {
_reportManager.getReportRepository().getReport(reportId).thenAccept(reportOptional -> _reportManager.getRepository().getReport(reportId).thenAccept(reportOptional ->
{ {
if (reportOptional.isPresent()) if (reportOptional.isPresent())
{ {

View File

@ -2,6 +2,7 @@ package mineplex.core.command;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
@ -21,8 +22,8 @@ public class CommandCenter implements Listener
protected JavaPlugin Plugin; protected JavaPlugin Plugin;
protected CoreClientManager ClientManager; protected CoreClientManager ClientManager;
protected static NautHashMap<String, ICommand> Commands; protected static NautHashMap<String, ICommand> Commands;
private final List<String> BLOCKED_COMMANDS = Lists.newArrayList("pl", "plugins", "ver", "version", "icanhasbukkit"); private final List<String> BLOCKED_COMMANDS = Lists.newArrayList("pl", "plugins", "ver", "version", "icanhasbukkit", "about", "?", "help");
private final String MESSAGE = C.cRed + "I''m sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error."; private final String MESSAGE = C.cRed + "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.";
public static void Initialize(JavaPlugin plugin) public static void Initialize(JavaPlugin plugin)
{ {
@ -59,13 +60,6 @@ public class CommandCenter implements Listener
args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" ");
} }
if(BLOCKED_COMMANDS.contains(commandName.toLowerCase()))
{
event.setCancelled(true);
event.getPlayer().sendMessage(MESSAGE);
return;
}
ICommand command = Commands.get(commandName.toLowerCase()); ICommand command = Commands.get(commandName.toLowerCase());
if (command != null) if (command != null)
@ -84,6 +78,14 @@ public class CommandCenter implements Listener
command.SetAliasUsed(commandName.toLowerCase()); command.SetAliasUsed(commandName.toLowerCase());
command.Execute(event.getPlayer(), args); command.Execute(event.getPlayer(), args);
} }
return;
}
if (BLOCKED_COMMANDS.contains(commandName.toLowerCase()) && !(event.getPlayer().isOp() || ClientManager.Get(event.getPlayer()).GetRank().has(Rank.DEVELOPER)))
{
event.setCancelled(true);
event.getPlayer().sendMessage(MESSAGE);
return;
} }
} }

View File

@ -1,16 +0,0 @@
package mineplex.core.cosmetic.ui;
import java.util.Comparator;
import mineplex.core.pet.Pet;
public class PetSorter implements Comparator<Pet>
{
public int compare(Pet a, Pet b)
{
if (a.getPetType().getTypeId() < b.getPetType().getTypeId())
return -1;
return 1;
}
}

View File

@ -3,23 +3,23 @@ package mineplex.core.cosmetic.ui.button;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import mineplex.core.pet.Pet;
import mineplex.core.cosmetic.ui.page.PetPage; import mineplex.core.cosmetic.ui.page.PetPage;
import mineplex.core.pet.PetType;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
public class PetButton implements IButton public class PetButton implements IButton
{ {
private Pet _pet; private PetType _petType;
private PetPage _page; private PetPage _page;
public PetButton(Pet pet, PetPage page) public PetButton(PetType pet, PetPage page)
{ {
_pet = pet; _petType = pet;
_page = page; _page = page;
} }
public void onClick(Player player, ClickType clickType) public void onClick(Player player, ClickType clickType)
{ {
_page.purchasePet(player, _pet); _page.purchasePet(player, _petType);
} }
} }

View File

@ -1,11 +1,10 @@
package mineplex.core.cosmetic.ui.button; package mineplex.core.cosmetic.ui.button;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import mineplex.core.cosmetic.ui.page.PetPage; import mineplex.core.cosmetic.ui.page.PetPage;
import mineplex.core.pet.Pet; import mineplex.core.pet.PetType;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
public class RenamePetButton implements IButton public class RenamePetButton implements IButton
@ -21,7 +20,7 @@ public class RenamePetButton implements IButton
public void onClick(Player player, ClickType clickType) public void onClick(Player player, ClickType clickType)
{ {
_page.playAcceptSound(player); _page.playAcceptSound(player);
Creature currentPet = _page.getPlugin().getPetManager().getActivePet(player.getName()); PetType currentType = _page.getPlugin().getPetManager().getActivePetType(player.getName());
_page.renamePet(player, new Pet(currentPet.getCustomName(), currentPet.getType(), 1), false); _page.renamePet(player, currentType, false);
} }
} }

View File

@ -5,15 +5,15 @@ import org.bukkit.event.inventory.ClickType;
import mineplex.core.cosmetic.ui.page.Menu; import mineplex.core.cosmetic.ui.page.Menu;
import mineplex.core.cosmetic.ui.page.PetPage; import mineplex.core.cosmetic.ui.page.PetPage;
import mineplex.core.pet.Pet; import mineplex.core.pet.PetType;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
public class ActivatePetButton implements IButton public class ActivatePetButton implements IButton
{ {
private Pet _pet; private PetType _pet;
private PetPage _page; private PetPage _page;
public ActivatePetButton(Pet pet, PetPage page) public ActivatePetButton(PetType pet, PetPage page)
{ {
_pet = pet; _pet = pet;
_page = page; _page = page;
@ -23,7 +23,7 @@ public class ActivatePetButton implements IButton
public void onClick(Player player, ClickType clickType) public void onClick(Player player, ClickType clickType)
{ {
_page.playAcceptSound(player); _page.playAcceptSound(player);
_page.getPlugin().getPetManager().addPetOwner(player, _pet.getPetType(), player.getLocation()); _page.getPlugin().getPetManager().addPetOwner(player, _pet, player.getLocation());
_page.getShop().openPageForPlayer(player, new Menu(_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), player)); _page.getShop().openPageForPlayer(player, new Menu(_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), player));
} }
} }

View File

@ -26,7 +26,7 @@ public class ArrowTrailPage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.ARROW_TRAIL)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.ARROW_TRAIL))
{ {
@ -37,8 +37,8 @@ public class ArrowTrailPage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 17)
slot = 28; slot += 2;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -1,5 +1,9 @@
package mineplex.core.cosmetic.ui.page; package mineplex.core.cosmetic.ui.page;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.CosmeticManager;
@ -9,9 +13,6 @@ import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.ShopItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
public class BalloonsPage extends GadgetPage public class BalloonsPage extends GadgetPage
{ {
@ -24,7 +25,7 @@ public class BalloonsPage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.BALLOON)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.BALLOON))
{ {
@ -35,10 +36,8 @@ public class BalloonsPage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 17 || slot == 26)
slot = 28; slot += 2;
if(slot == 35)
slot = 37;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -26,7 +26,7 @@ public class DeathEffectPage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.DEATH)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.DEATH))
{ {
@ -37,8 +37,8 @@ public class DeathEffectPage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 17)
slot = 28; slot += 2;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -26,7 +26,7 @@ public class DoubleJumpPage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.DOUBLE_JUMP)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.DOUBLE_JUMP))
{ {
@ -37,8 +37,8 @@ public class DoubleJumpPage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 17)
slot = 28; slot += 2;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -53,7 +53,7 @@ public class GadgetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.ITEM)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.ITEM))
{ {
@ -67,7 +67,7 @@ public class GadgetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
slot++; slot++;
if (slot == 26 || slot == 35) if (slot == 17 || slot == 26)
slot += 2; slot += 2;
} }
@ -165,7 +165,7 @@ public class GadgetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
} }
else else
{ {
itemLore.add(C.cBlue + "Found in Power Play Club"); itemLore.add(C.cBlue + "Bonus Item Unlocked with Power Play Club");
} }
} }
@ -355,7 +355,25 @@ public class GadgetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
} }
} }
addButton(slot, new ShopItem(gadgetItemStack, false, false).hideInfo(), new ActivateGadgetButton(gadget, this)); /*if (gadget instanceof MorphStray)
{
gadgetItemStack = UtilItem.getVersionSpecificItem(_player, UtilPlayer.PlayerVersion._1_9, gadgetItemStack);
}*/
IButton iButton = new ActivateGadgetButton(gadget, this);
/*if (gadgetItemStack.getData().getItemType().equals(Material.BARRIER))
{
iButton = null;
}
else
{
// Does not set the item stack yet
//gadgetItemStack.setType(Material.getMaterial(440));
}*/
addButton(slot, new ShopItem(gadgetItemStack, false, false).hideInfo(), iButton);
} }
} }
else else

View File

@ -29,7 +29,7 @@ public class HatPage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
List<Gadget> list = getPlugin().getGadgetManager().getGadgets(GadgetType.HAT); List<Gadget> list = getPlugin().getGadgetManager().getGadgets(GadgetType.HAT);
if(list != null) if(list != null)
@ -42,8 +42,8 @@ public class HatPage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 17)
slot = 28; slot += 2;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -25,13 +25,12 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.mount.Mount; import mineplex.core.mount.Mount;
import mineplex.core.pet.Pet; import mineplex.core.pet.PetType;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Creature; import org.bukkit.entity.Creature;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
@ -122,10 +121,10 @@ public class Menu extends ShopPageBase<CosmeticManager, CosmeticShop>
int petOwned = 0; int petOwned = 0;
int petMax = 0; int petMax = 0;
for (Pet pet : getPlugin().getPetManager().getFactory().GetPets()) for (PetType type : PetType.values())
{ {
Map<EntityType, String> pets = getPlugin().getPetManager().Get(getPlayer()).getPets(); Map<PetType, String> pets = getPlugin().getPetManager().Get(getPlayer()).getPets();
if (pets != null && pets.containsKey(pet.getPetType())) if (pets != null && pets.containsKey(type))
{ {
petOwned++; petOwned++;
} }

View File

@ -1,5 +1,9 @@
package mineplex.core.cosmetic.ui.page; package mineplex.core.cosmetic.ui.page;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.CosmeticManager;
@ -10,9 +14,6 @@ import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.ShopItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
public class MorphPage extends GadgetPage public class MorphPage extends GadgetPage
{ {
@ -24,7 +25,7 @@ public class MorphPage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.MORPH)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.MORPH))
{ {
@ -36,10 +37,8 @@ public class MorphPage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 17 || slot == 26 || slot == 35)
slot = 28; slot += 2;
if (slot == 35)
slot = 37;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -39,15 +39,15 @@ public class MountPage extends ShopPageBase<CosmeticManager, CosmeticShop>
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Mount<?> mount : getPlugin().getMountManager().getMounts()) for (Mount<?> mount : getPlugin().getMountManager().getMounts())
{ {
addMount(mount, slot); addMount(mount, slot);
slot++; slot++;
if (slot == 26) if (slot == 17)
slot = 28; slot += 2;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -26,7 +26,7 @@ public class MusicPage extends GadgetPage
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.MUSIC_DISC)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.MUSIC_DISC))
{ {
@ -34,8 +34,8 @@ public class MusicPage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 17)
slot = 28; slot += 2;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -24,7 +24,7 @@ public class ParticlePage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.PARTICLE)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.PARTICLE))
{ {
@ -35,10 +35,8 @@ public class ParticlePage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 17 || slot == 26)
slot = 28; slot += 2;
if(slot == 35)
slot = 37;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -1,7 +1,9 @@
package mineplex.core.cosmetic.ui.page; package mineplex.core.cosmetic.ui.page;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import net.minecraft.server.v1_8_R3.Blocks; import net.minecraft.server.v1_8_R3.Blocks;
@ -25,14 +27,13 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText;
import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop; import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.cosmetic.ui.PetSorter;
import mineplex.core.cosmetic.ui.button.PetButton; import mineplex.core.cosmetic.ui.button.PetButton;
import mineplex.core.cosmetic.ui.button.RenamePetButton; import mineplex.core.cosmetic.ui.button.RenamePetButton;
import mineplex.core.cosmetic.ui.button.activate.ActivatePetButton; import mineplex.core.cosmetic.ui.button.activate.ActivatePetButton;
import mineplex.core.cosmetic.ui.button.deactivate.DeactivatePetButton; import mineplex.core.cosmetic.ui.button.deactivate.DeactivatePetButton;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.pet.Pet;
import mineplex.core.pet.PetExtra; import mineplex.core.pet.PetExtra;
import mineplex.core.pet.PetType;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.AnvilContainer; import mineplex.core.shop.page.AnvilContainer;
@ -49,87 +50,91 @@ public class PetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
List<Pet> pets = new ArrayList<Pet>(getPlugin().getPetManager().getFactory().GetPets()); PetType[] pets = PetType.values();
Arrays.sort(pets, Comparator.comparing(type -> type.getEntityType().getTypeId()));
Collections.sort(pets, new PetSorter()); for (PetType pet : pets)
for (Pet pet : pets)
{ {
List<String> itemLore = new ArrayList<String>(); List<String> itemLore = new ArrayList<String>();
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
if (pet.getLore() != null) if (pet.getLore().isPresent())
{ {
Collections.addAll(itemLore, UtilText.splitLineToArray(C.cGray + pet.getLore(), LineFormat.LORE)); Collections.addAll(itemLore, UtilText.splitLineToArray(C.cGray + pet.getLore().get(), LineFormat.LORE));
} }
else else
{ {
itemLore.add(C.cGray + "Your very own " + pet.getName() + "!"); itemLore.add(C.cGray + "Your very own " + pet.getName() + "!");
} }
//Chest Unlocks //Chest Unlocks
if (!getPlugin().getPetManager().Get(getPlayer()).getPets().containsKey(pet.getPetType())) if (!getPlugin().getPetManager().Get(getPlayer()).getPets().containsKey(pet))
{ {
if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -1) if (pet.getPrice() == -1)
{ {
//Nothing //Nothing
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -2 || pet.getCost(GlobalCurrency.TREASURE_SHARD) > 0) else if (pet.getPrice() == -2 || pet.getPrice() > 0)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cBlue + "Found in Treasure Chests"); itemLore.add(C.cBlue + "Found in Treasure Chests");
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -3) else if (pet.getPrice() == -3)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cBlue + "Found in Winter Holiday Treasure"); itemLore.add(C.cBlue + "Found in Winter Holiday Treasure");
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -4) else if (pet.getPrice() == -4)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cBlue + "Earned by defeating the Pumpkin King"); itemLore.add(C.cBlue + "Earned by defeating the Pumpkin King");
itemLore.add(C.cBlue + "in the 2014 Christmas Chaos Event."); itemLore.add(C.cBlue + "in the 2014 Christmas Chaos Event.");
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -5) else if (pet.getPrice() == -5)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cBlue + "Found in Easter Holiday Treasure"); itemLore.add(C.cBlue + "Found in Easter Holiday Treasure");
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -8) else if (pet.getPrice() == -8)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cBlue + "Found in Pumpkin's Revenge"); itemLore.add(C.cBlue + "Found in Pumpkin's Revenge");
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -9) else if (pet.getPrice() == -9)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cBlue + "Found in Haunted Chests"); itemLore.add(C.cBlue + "Found in Haunted Chests");
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -14) else if (pet.getPrice() == -14)
{
itemLore.add(C.cBlack);
itemLore.add(C.cBlue + "Found in Power Play Club");
}
else if (pet.getPrice() == -14)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cBlue + "Found in Power Play Club"); itemLore.add(C.cBlue + "Found in Power Play Club");
} }
//Rank Unlocks //Rank Unlocks
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -10) else if (pet.getPrice() == -10)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cAqua + "Unlocked with Ultra Rank"); itemLore.add(C.cAqua + "Unlocked with Ultra Rank");
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -11) else if (pet.getPrice() == -11)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cPurple + "Unlocked with Hero Rank"); itemLore.add(C.cPurple + "Unlocked with Hero Rank");
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -12) else if (pet.getPrice() == -12)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cGreen + "Unlocked with Legend Rank"); itemLore.add(C.cGreen + "Unlocked with Legend Rank");
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) == -13) else if (pet.getPrice() == -13)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cRed + "Unlocked with Titan Rank"); itemLore.add(C.cRed + "Unlocked with Titan Rank");
@ -137,21 +142,21 @@ public class PetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
} }
//Owned //Owned
if (getPlugin().getPetManager().Get(getPlayer()).getPets().containsKey(pet.getPetType())) if (getPlugin().getPetManager().Get(getPlayer()).getPets().containsKey(pet))
{ {
String petName = getPlugin().getPetManager().Get(getPlayer()).getPets().get(pet.getPetType()); String petName = getPlugin().getPetManager().Get(getPlayer()).getPets().get(pet);
if (petName == null) if (petName == null)
{ {
petName = pet.getName(); petName = pet.getName();
} }
if (getPlugin().getPetManager().hasActivePet(getPlayer().getName()) && getPlugin().getPetManager().getActivePet(getPlayer().getName()).getType() == pet.getPetType()) if (getPlugin().getPetManager().hasActivePet(getPlayer().getName()) && getPlugin().getPetManager().getActivePetType(getPlayer().getName()) == pet)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cGreen + "Click to Disable"); itemLore.add(C.cGreen + "Click to Disable");
addButton(slot, new ShopItem(Material.MONSTER_EGG, (byte) pet.getPetType().getTypeId(), addButton(slot, new ShopItem(Material.MONSTER_EGG, (byte) pet.getEntityType().getTypeId(),
pet.getPetName() + " (" + C.cWhite + petName + C.cGreen + ")", pet.getName() + " (" + C.cWhite + petName + C.cGreen + ")",
itemLore.toArray(new String[itemLore.size()]), 1, false, false), new DeactivatePetButton(this, getPlugin().getPetManager())); itemLore.toArray(new String[itemLore.size()]), 1, false, false), new DeactivatePetButton(this, getPlugin().getPetManager()));
addGlow(slot); addGlow(slot);
@ -160,56 +165,76 @@ public class PetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cGreen + "Click to Enable"); itemLore.add(C.cGreen + "Click to Enable");
/*
ItemStack petItem = ItemStackFactory.Instance.CreateStack(pet.getMaterial(), pet.getData(), 1,
pet.getName() + " (" + C.cWhite + petName + C.cGreen + ")", itemLore);
addButton(slot, new ShopItem(Material.MONSTER_EGG, (byte) pet.getPetType().getTypeId(), IButton iButton = new ActivatePetButton(pet, this);
pet.getPetName() + " (" + C.cWhite + petName + C.cGreen + ")",
if (pet.equals(PetType.SHULKER))
{
petItem = UtilItem.getVersionSpecificItem(_player, UtilPlayer.PlayerVersion._1_9, petItem);
if (petItem.getType().equals(Material.BARRIER))
{
iButton = null;
}
else
{
// Does not set the item stack yet
//petItem.setType(Material.getMaterial(201));
}
}*/
addButton(slot, new ShopItem(Material.MONSTER_EGG, (byte) pet.getEntityType().getTypeId(),
pet.getName() + " (" + C.cWhite + petName + C.cGreen + ")",
itemLore.toArray(new String[itemLore.size()]), 1, false, false), new ActivatePetButton(pet, this)); itemLore.toArray(new String[itemLore.size()]), 1, false, false), new ActivatePetButton(pet, this));
//addButton(slot, new ShopItem(petItem, false, false), iButton);
} }
} }
//Not Owned //Not Owned
else else
{ {
if (pet.getCost(GlobalCurrency.TREASURE_SHARD) > 0) if (pet.getPrice() > 0)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cWhiteB + "Cost: " + C.cAqua + pet.getCost(GlobalCurrency.TREASURE_SHARD) + " Treasure Shards"); itemLore.add(C.cWhiteB + "Cost: " + C.cAqua + pet.getPrice() + " Treasure Shards");
} }
if (pet.getCost(GlobalCurrency.TREASURE_SHARD) > 0 && getDonationManager().Get(getPlayer()).getBalance(GlobalCurrency.TREASURE_SHARD) >= pet.getCost(GlobalCurrency.TREASURE_SHARD)) if (pet.getPrice() > 0 && getDonationManager().Get(getPlayer()).getBalance(GlobalCurrency.TREASURE_SHARD) >= pet.getPrice())
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cGreen + "Click to Purchase"); itemLore.add(C.cGreen + "Click to Purchase");
addButton(slot, new ShopItem(Material.INK_SACK, (byte) 8, pet.getPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false), new PetButton(pet, this)); addButton(slot, new ShopItem(Material.INK_SACK, (byte) 8, pet.getName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false), new PetButton(pet, this));
} }
else if (pet.getCost(GlobalCurrency.TREASURE_SHARD) > 0) else if (pet.getPrice() > 0)
{ {
itemLore.add(C.cBlack); itemLore.add(C.cBlack);
itemLore.add(C.cRed + "Not enough Treasure Shards."); itemLore.add(C.cRed + "Not enough Treasure Shards.");
setItem(slot, new ShopItem(Material.INK_SACK, (byte)8, pet.getPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false)); setItem(slot, new ShopItem(Material.INK_SACK, (byte)8, pet.getName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false));
} }
else else
{ {
setItem(slot, new ShopItem(Material.INK_SACK, (byte)8, pet.getPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false)); setItem(slot, new ShopItem(Material.INK_SACK, (byte)8, pet.getName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false));
} }
} }
slot++; slot++;
if (slot == 26) if (slot == 17 || slot == 26)
slot = 28; slot += 2;
} }
slot = 49; slot = 49;
for (PetExtra petExtra : getPlugin().getPetManager().getFactory().GetPetExtras()) for (PetExtra petExtra : PetExtra.values())
{ {
List<String> itemLore = new ArrayList<String>(); List<String> itemLore = new ArrayList<String>();
if (!getPlugin().getPetManager().hasActivePet(getPlayer().getName())) if (!getPlugin().getPetManager().hasActivePet(getPlayer().getName()))
{ {
itemLore.add(C.cWhite + "You must have an active pet to use this!"); itemLore.add(C.cWhite + "You must have an active pet to use this!");
getInventory().setItem(slot, new ShopItem(petExtra.GetMaterial(), (byte)0, C.cRed + petExtra.getName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false).getHandle()); getInventory().setItem(slot, new ShopItem(petExtra.getMaterial(), (byte)0, C.cRed + petExtra.getName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false).getHandle());
} }
// Silverfish = Wither disguised // Silverfish = Wither disguised
// Villager = Elf // Villager = Elf
@ -218,7 +243,7 @@ public class PetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
|| getPlugin().getPetManager().getActivePet(getPlayer().getName()).getType() != EntityType.VILLAGER || getPlugin().getPetManager().getActivePet(getPlayer().getName()).getType() != EntityType.VILLAGER
|| getPlugin().getPetManager().getActivePet(getPlayer().getName()).getType() != EntityType.ZOMBIE) || getPlugin().getPetManager().getActivePet(getPlayer().getName()).getType() != EntityType.ZOMBIE)
{ {
addButton(slot, new ShopItem(petExtra.GetMaterial(), (byte) 0, "Rename " + getPlugin().getPetManager().getActivePet(getPlayer().getName()).getCustomName() + " for " + C.cYellow + petExtra.getCost(GlobalCurrency.TREASURE_SHARD) + C.cGreen + " Shards", itemLore.toArray(new String[itemLore.size()]), 1, false, false), new RenamePetButton(this)); addButton(slot, new ShopItem(petExtra.getMaterial(), (byte) 0, "Rename " + getPlugin().getPetManager().getActivePet(getPlayer().getName()).getCustomName() + " for " + C.cYellow + petExtra.getPrice(), itemLore.toArray(new String[itemLore.size()]), 1, false, false), new RenamePetButton(this));
} }
slot++; slot++;
@ -233,12 +258,12 @@ public class PetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
}); });
} }
public void purchasePet(final Player player, final Pet pet) public void purchasePet(final Player player, final PetType petType)
{ {
renamePet(player, pet, true); renamePet(player, petType, true);
} }
public void renamePet(Player player, Pet pet, boolean petPurchase) public void renamePet(Player player, PetType pet, boolean petPurchase)
{ {
playAcceptSound(player); playAcceptSound(player);

View File

@ -1,9 +1,14 @@
package mineplex.core.cosmetic.ui.page; package mineplex.core.cosmetic.ui.page;
import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.Items;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.cache.player.PlayerCache; import mineplex.cache.player.PlayerCache;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.CosmeticManager;
@ -11,31 +16,26 @@ import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.cosmetic.ui.button.CloseButton; import mineplex.core.cosmetic.ui.button.CloseButton;
import mineplex.core.cosmetic.ui.button.SelectTagButton; import mineplex.core.cosmetic.ui.button.SelectTagButton;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.pet.Pet;
import mineplex.core.pet.PetExtra; import mineplex.core.pet.PetExtra;
import mineplex.core.pet.PetType;
import mineplex.core.pet.repository.token.PetChangeToken; import mineplex.core.pet.repository.token.PetChangeToken;
import mineplex.core.pet.repository.token.PetToken; import mineplex.core.pet.repository.token.PetToken;
import mineplex.core.shop.confirmation.ConfirmationPage; import mineplex.core.shop.confirmation.ConfirmationPage;
import mineplex.core.shop.item.SalesPackageBase; import mineplex.core.shop.item.SalesPackageBase;
import mineplex.core.shop.item.SalesPackageProcessor; import mineplex.core.shop.item.SalesPackageProcessor;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.Items;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
public class PetTagPage extends ShopPageBase<CosmeticManager, CosmeticShop> public class PetTagPage extends ShopPageBase<CosmeticManager, CosmeticShop>
{ {
private String _tagName = "Pet Tag"; private String _tagName = "Pet Tag";
private Pet _pet; private PetType _petType;
private boolean _petPurchase; private boolean _petPurchase;
public PetTagPage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, Pet pet, boolean petPurchase) public PetTagPage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, PetType petType, boolean petPurchase)
{ {
super(plugin, shop, clientManager, donationManager, name, player, 3); super(plugin, shop, clientManager, donationManager, name, player, 3);
_pet = pet; _petType = petType;
_petPurchase = petPurchase; _petPurchase = petPurchase;
buildPage(); buildPage();
@ -84,7 +84,7 @@ public class PetTagPage extends ShopPageBase<CosmeticManager, CosmeticShop>
return; return;
} }
if (_tagName.equalsIgnoreCase("ULTRA")) if (_tagName.toLowerCase().contains("ultra"))
{ {
UtilPlayer.message(getPlayer(), F.main(getPlugin().getName(), ChatColor.RED + _tagName + " is a restricted name.")); UtilPlayer.message(getPlayer(), F.main(getPlugin().getName(), ChatColor.RED + _tagName + " is a restricted name."));
playDenySound(getPlayer()); playDenySound(getPlayer());
@ -93,10 +93,15 @@ public class PetTagPage extends ShopPageBase<CosmeticManager, CosmeticShop>
return; return;
} }
PetExtra tag = new PetExtra("Rename " + _pet.getName() + " to " + _tagName, Material.NAME_TAG, 100); final SalesPackageBase salesPackage;
final SalesPackageBase salesPackage = _petPurchase ? _pet : tag; if (_petPurchase)
{
salesPackage = _petType.toSalesPackage(_tagName);
_pet.setDisplayName(C.cGreen + "Purchase " + _tagName); } else
{
salesPackage = PetExtra.NAME_TAG.toSalesPackage("Rename " + _petType.getName() + " to " + _tagName);
}
getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<>(_player, this, new SalesPackageProcessor(_player, GlobalCurrency.TREASURE_SHARD, salesPackage, _donationManager, () -> getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<>(_player, this, new SalesPackageProcessor(_player, GlobalCurrency.TREASURE_SHARD, salesPackage, _donationManager, () ->
{ {
@ -108,8 +113,7 @@ public class PetTagPage extends ShopPageBase<CosmeticManager, CosmeticShop>
token.AccountId = PlayerCache.getInstance().getPlayer(getPlayer().getUniqueId()).getAccountId(); token.AccountId = PlayerCache.getInstance().getPlayer(getPlayer().getUniqueId()).getAccountId();
token.Name = getPlayer().getName(); token.Name = getPlayer().getName();
token.PetType = _pet.getPetType().toString(); token.PetType = _petType.toString();
token.PetId = _pet.getPetType().ordinal();
token.PetName = _tagName; token.PetName = _tagName;
PetToken petToken = new PetToken(); PetToken petToken = new PetToken();
@ -118,7 +122,7 @@ public class PetTagPage extends ShopPageBase<CosmeticManager, CosmeticShop>
if (_petPurchase) if (_petPurchase)
{ {
getPlugin().getPetManager().getRepository().AddPet(token); getPlugin().getPetManager().getRepository().AddPet(token);
getPlugin().getPetManager().addPetOwnerToQueue(getPlayer().getName(), _pet.getPetType()); getPlugin().getPetManager().addPetOwnerToQueue(getPlayer().getName(), _petType);
} }
else else
{ {
@ -126,7 +130,7 @@ public class PetTagPage extends ShopPageBase<CosmeticManager, CosmeticShop>
getPlugin().getPetManager().addRenamePetToQueue(getPlayer().getName(), token.PetName); getPlugin().getPetManager().addRenamePetToQueue(getPlayer().getName(), token.PetName);
} }
getPlugin().getPetManager().Get(getPlayer()).getPets().put(_pet.getPetType(), token.PetName); getPlugin().getPetManager().Get(getPlayer()).getPets().put(_petType, token.PetName);
getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer())); getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer()));
}), salesPackage.buildIcon())); }), salesPackage.buildIcon()));

View File

@ -29,7 +29,7 @@ public class TauntPage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
List<Gadget> list = getPlugin().getGadgetManager().getGadgets(GadgetType.TAUNT); List<Gadget> list = getPlugin().getGadgetManager().getGadgets(GadgetType.TAUNT);
if(list != null) if(list != null)
@ -43,7 +43,7 @@ public class TauntPage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 26)
slot = 28; slot += 2;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -26,7 +26,7 @@ public class WinEffectPage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.WIN_EFFECT)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.WIN_EFFECT))
{ {
@ -37,8 +37,8 @@ public class WinEffectPage extends GadgetPage
slot++; slot++;
if (slot == 26) if (slot == 17)
slot = 28; slot += 2;
} }
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton() addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()

View File

@ -2,8 +2,6 @@ package mineplex.core.cosmetic.ui.page.gamemodifiers;
import java.util.List; import java.util.List;
import mineplex.core.cosmetic.ui.page.GadgetPage;
import mineplex.core.cosmetic.ui.page.Menu;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
@ -14,6 +12,8 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop; import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.cosmetic.ui.page.GadgetPage;
import mineplex.core.cosmetic.ui.page.Menu;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType; import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType;
import mineplex.core.gadget.types.GameModifierGadget; import mineplex.core.gadget.types.GameModifierGadget;
@ -32,7 +32,7 @@ public class GameModifierPage extends GadgetPage
@Override @Override
protected void buildPage() protected void buildPage()
{ {
int slot = 19; int slot = 10;
for (GameModifierType type : GameModifierType.values()) for (GameModifierType type : GameModifierType.values())
{ {

View File

@ -1,24 +1,24 @@
package mineplex.core.cosmetic.ui.page.gamemodifiers; package mineplex.core.cosmetic.ui.page.gamemodifiers;
import mineplex.core.cosmetic.ui.page.GadgetPage; import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop; import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.cosmetic.ui.page.GadgetPage;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType; import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType;
import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitModifierType; import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitModifierType;
import mineplex.core.gadget.types.GameModifierGadget; import mineplex.core.gadget.types.GameModifierGadget;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.ShopItem;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
public class GameModifierSubPage extends GadgetPage public class GameModifierSubPage extends GadgetPage
{ {
@ -38,7 +38,7 @@ public class GameModifierSubPage extends GadgetPage
{ {
if(_type == null) return; if(_type == null) return;
int slot = 19; int slot = 10;
if (_type.hasKits()) if (_type.hasKits())
{ {

View File

@ -1,5 +1,9 @@
package mineplex.core.cosmetic.ui.page.gamemodifiers; package mineplex.core.cosmetic.ui.page.gamemodifiers;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.CosmeticManager;
@ -12,9 +16,6 @@ import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitModifierType;
import mineplex.core.gadget.types.GameModifierGadget; import mineplex.core.gadget.types.GameModifierGadget;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.ShopItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
public class KitGameModifierPage extends GadgetPage public class KitGameModifierPage extends GadgetPage
{ {
@ -36,7 +37,7 @@ public class KitGameModifierPage extends GadgetPage
{ {
if(_type == null) return; if(_type == null) return;
int slot = 19; int slot = 10;
for (GameModifierGadget gadget : getPlugin().getGadgetManager().getGameModifiers(_kitType)) for (GameModifierGadget gadget : getPlugin().getGadgetManager().getGameModifiers(_kitType))
{ {

View File

@ -10,6 +10,7 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Guardian;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
@ -164,6 +165,16 @@ public class MobCommand extends MultiCommandBase<Creature>
argHandle.add(arg); argHandle.add(arg);
} }
else if (arg.equalsIgnoreCase("elder"))
{
for (Entity ent : entSet)
if (ent instanceof Guardian)
((Guardian)ent).setElder(true);
UtilPlayer.message(caller, F.desc("Elder", "True"));
argHandle.add(arg);
}
//Profession //Profession
else if (arg.toLowerCase().charAt(0) == 'p') else if (arg.toLowerCase().charAt(0) == 'p')
{ {

View File

@ -114,6 +114,7 @@ import mineplex.core.gadget.gadgets.morph.MorphCow;
import mineplex.core.gadget.gadgets.morph.MorphCreeper; import mineplex.core.gadget.gadgets.morph.MorphCreeper;
import mineplex.core.gadget.gadgets.morph.MorphEnderman; import mineplex.core.gadget.gadgets.morph.MorphEnderman;
import mineplex.core.gadget.gadgets.morph.MorphGrimReaper; import mineplex.core.gadget.gadgets.morph.MorphGrimReaper;
import mineplex.core.gadget.gadgets.morph.MorphMetalMan;
import mineplex.core.gadget.gadgets.morph.MorphPig; import mineplex.core.gadget.gadgets.morph.MorphPig;
import mineplex.core.gadget.gadgets.morph.MorphPumpkinKing; import mineplex.core.gadget.gadgets.morph.MorphPumpkinKing;
import mineplex.core.gadget.gadgets.morph.MorphSlime; import mineplex.core.gadget.gadgets.morph.MorphSlime;
@ -366,10 +367,11 @@ public class GadgetManager extends MiniPlugin
addGadget(new MorphSquid(this)); addGadget(new MorphSquid(this));
addGadget(new MorphWitch(this)); addGadget(new MorphWitch(this));
addGadget(new MorphGrimReaper(this)); addGadget(new MorphGrimReaper(this));
addGadget(new MorphMetalMan(this));
addGadget(new MorphTurkey(this)); addGadget(new MorphTurkey(this));
// Hidden in this update // Not in this update
//addGadget(new MorphSleigh(this)); //addGadget(new MorphStray(this));
//addGadget(new MorphMetalMan(this)); //addGadget(new MorphSanta(this));
// Particles // Particles
addGadget(new ParticleFoot(this)); addGadget(new ParticleFoot(this));

View File

@ -1,6 +1,7 @@
package mineplex.core.gadget.commands; package mineplex.core.gadget.commands;
import mineplex.core.account.CoreClient; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -8,7 +9,6 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import org.bukkit.entity.Player;
public class AmmoCommand extends CommandBase<GadgetManager> public class AmmoCommand extends CommandBase<GadgetManager>
{ {

View File

@ -1,5 +1,8 @@
package mineplex.core.gadget.commands; package mineplex.core.gadget.commands;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -10,10 +13,7 @@ import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.mount.Mount; import mineplex.core.mount.Mount;
import mineplex.core.pet.Pet; import mineplex.core.pet.PetType;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class LockCosmeticsCommand extends CommandBase<GadgetManager> public class LockCosmeticsCommand extends CommandBase<GadgetManager>
{ {
@ -106,11 +106,10 @@ public class LockCosmeticsCommand extends CommandBase<GadgetManager>
private void removePets(Player caller) private void removePets(Player caller)
{ {
int removed = 0; int removed = 0;
for (Pet pet : _plugin.getPetManager().getFactory().GetPets()) for (PetType pet : PetType.values())
{ {
if (_plugin.getPetManager().Get(caller).getPets().containsKey(pet.getPetType())) if (_plugin.getPetManager().Get(caller).getPets().remove(pet) != null)
{ {
_plugin.getPetManager().Get(caller).getPets().remove(pet.getPetType());
removed++; removed++;
} }
} }

View File

@ -1,85 +0,0 @@
package mineplex.core.gadget.commands;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilServer;
import mineplex.core.gadget.GadgetManager;
public class ReindeerTestCommand extends CommandBase<GadgetManager>
{
private GadgetManager _plugin;
private Horse _horse;
private ArmorStand _armorStand;
public ReindeerTestCommand(GadgetManager plugin)
{
super(plugin, Rank.JNR_DEV, "reindeer");
_plugin = plugin;
}
@Override
public void Execute(Player caller, String[] args)
{
if (_horse == null)
{
Location testHorse = new Location(caller.getWorld(), 8.5, 71, 0.5, 0, 0);
testHorse.setYaw(180);
Horse horse = testHorse.getWorld().spawn(testHorse, Horse.class);
horse.setVariant(Horse.Variant.HORSE);
horse.setColor(Horse.Color.BROWN);
horse.setStyle(Horse.Style.NONE);
UtilEnt.Vegetate(horse, true);
UtilEnt.ghost(horse, true, false);
/**
* South
* .4 1 .6
* .2 1 .7
* 0 4 0
* 0 2 0
*
* North
*/
Location hornALoc = horse.getLocation().clone().add(-.3, 1, -.5);
Location hornBLoc = horse.getLocation().clone().add(-.25, 1, -.6);
ArmorStand hornA = hornALoc.getWorld().spawn(hornALoc, ArmorStand.class);
hornA.setVisible(false);
hornA.setGravity(false);
hornA.getEquipment().setItemInHand(new ItemStack(Material.DEAD_BUSH));
hornA.setRightArmPose(new EulerAngle(0, 4, 0));
ArmorStand hornB = hornBLoc.getWorld().spawn(hornBLoc, ArmorStand.class);
hornB.setVisible(false);
hornB.setGravity(false);
hornB.getEquipment().setItemInHand(new ItemStack(Material.DEAD_BUSH));
hornB.setRightArmPose(new EulerAngle(0, 2, 0));
_horse = horse;
Bukkit.getScheduler().scheduleSyncRepeatingTask(UtilServer.getPlugin(), new Runnable()
{
@Override
public void run()
{
Location location = _horse.getLocation();
location.setYaw(180);
_horse.teleport(location);
}
}, 1l, 1l);
}
}
}

View File

@ -1,5 +1,8 @@
package mineplex.core.gadget.commands; package mineplex.core.gadget.commands;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -10,10 +13,7 @@ import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.mount.Mount; import mineplex.core.mount.Mount;
import mineplex.core.pet.Pet; import mineplex.core.pet.PetType;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class UnlockCosmeticsCommand extends CommandBase<GadgetManager> public class UnlockCosmeticsCommand extends CommandBase<GadgetManager>
{ {
@ -111,11 +111,11 @@ public class UnlockCosmeticsCommand extends CommandBase<GadgetManager>
private void addPets(Player caller) private void addPets(Player caller)
{ {
int added = 0; int added = 0;
for (Pet pet : _plugin.getPetManager().getFactory().GetPets()) for (PetType pet : PetType.values())
{ {
if (!_plugin.getPetManager().Get(caller).getPets().containsKey(pet.getPetType())) if (!_plugin.getPetManager().Get(caller).getPets().containsKey(pet))
{ {
_plugin.getPetManager().Get(caller).getPets().put(pet.getPetType(), pet.getName()); _plugin.getPetManager().Get(caller).getPets().put(pet, pet.getName());
added++; added++;
} }
} }

View File

@ -6,7 +6,7 @@ import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.particles.ColoredParticle; import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor; import mineplex.core.common.util.particles.DustSpellColor;
import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.particle.unrelated.BabyFireworkEffect; import mineplex.core.particleeffects.BabyFireworkEffect;
import mineplex.core.gadget.types.ArrowEffectGadget; import mineplex.core.gadget.types.ArrowEffectGadget;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Color; import org.bukkit.Color;

View File

@ -1,6 +1,5 @@
package mineplex.core.gadget.gadgets.item; package mineplex.core.gadget.gadgets.item;
import mineplex.core.gadget.gadgets.hat.HatType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -19,16 +18,18 @@ import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.ItemGadgetOutOfAmmoEvent; import mineplex.core.gadget.event.ItemGadgetOutOfAmmoEvent;
import mineplex.core.gadget.gadgets.Ammo; import mineplex.core.gadget.gadgets.Ammo;
import mineplex.core.gadget.gadgets.hat.HatType;
import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes; import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes;
import mineplex.core.gadget.types.ItemGadget; import mineplex.core.gadget.types.ItemGadget;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.pet.PetType;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.reward.RewardData; import mineplex.core.reward.RewardData;
import mineplex.core.reward.RewardRarity; import mineplex.core.reward.RewardRarity;
@ -130,7 +131,7 @@ public class ItemCoal extends ItemGadget
Manager.getPetManager(), Manager.getPetManager(),
Manager.getInventoryManager(), Manager.getInventoryManager(),
Manager.getDonationManager(), Manager.getDonationManager(),
"Coal Apparition", "Coal Apparition", EntityType.PIG_ZOMBIE, RewardRarity.OTHER, 0, 0); "Coal Apparition", "Coal Apparition", PetType.PIG_ZOMBIE, RewardRarity.OTHER, 0, 0);
if (reward.canGiveReward(player)) if (reward.canGiveReward(player))
reward.giveReward(null, player, new Callback<RewardData>() reward.giveReward(null, player, new Callback<RewardData>()

View File

@ -105,6 +105,8 @@ public class MorphGrimReaper extends MorphGadget
public void disableCustom(Player player, boolean message) public void disableCustom(Player player, boolean message)
{ {
this.removeArmor(player); this.removeArmor(player);
player.setFlying(false);
player.setAllowFlight(false);
_flying.remove(player); _flying.remove(player);
_flyReady.remove(player); _flyReady.remove(player);
_soulManager.resetSouls(player); _soulManager.resetSouls(player);
@ -189,7 +191,7 @@ public class MorphGrimReaper extends MorphGadget
private void setFlying(Player player, boolean flying, boolean isFast) private void setFlying(Player player, boolean flying, boolean isFast)
{ {
if (flying) if (flying && isActive(player))
{ {
if (UtilPlayer.isSpectator(player)) if (UtilPlayer.isSpectator(player))
return; return;

View File

@ -2,15 +2,21 @@ package mineplex.core.gadget.gadgets.morph;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
@ -18,29 +24,39 @@ import mineplex.core.common.skin.SkinData;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime;
import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.GadgetSelectLocationEvent; import mineplex.core.gadget.event.GadgetSelectLocationEvent;
import mineplex.core.gadget.gadgets.morph.managers.UtilMorph; import mineplex.core.gadget.gadgets.morph.managers.UtilMorph;
import mineplex.core.gadget.gadgets.particle.unrelated.MetalManEffect;
import mineplex.core.gadget.types.MorphGadget; import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.particleeffects.MetalManEffect;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilGameProfile; import mineplex.core.utils.UtilGameProfile;
public class MorphMetalMan extends MorphGadget public class MorphMetalMan extends MorphGadget
{ {
private Map<UUID, Integer> _playerColors = new HashMap<>(); private Map<UUID, Integer> _playerColors = new HashMap<>();
private Map<Player, Long> _flying = new HashMap<>();
private static final int FLY_TIME = 15;
public MorphMetalMan(GadgetManager manager) public MorphMetalMan(GadgetManager manager)
{ {
super(manager, "Metal Man Morph", UtilText.splitLinesToArray(new String[]{ super(manager, "Metal Man Morph", UtilText.splitLinesToArray(new String[]{
C.cGray + "This powerful suit forged of metal makes the wearer strong enough to even battle the gods", C.cGray + "This powerful suit forged of metal makes the wearer strong enough to even battle the gods",
"", "",
C.cWhite + "Left-click to shoot laser beam" C.cWhite + "Left-click to shoot laser beam",
C.cWhite + "Sneak to hover"
}, LineFormat.LORE), }, LineFormat.LORE),
-14, Material.IRON_INGOT, (byte) 0); -14, Material.IRON_INGOT, (byte) 0);
} }
@ -57,6 +73,8 @@ public class MorphMetalMan extends MorphGadget
DisguisePlayer disguisePlayer = new DisguisePlayer(player, gameProfile); DisguisePlayer disguisePlayer = new DisguisePlayer(player, gameProfile);
disguisePlayer.showInTabList(true, 0); disguisePlayer.showInTabList(true, 0);
UtilMorph.disguise(player, disguisePlayer, Manager); UtilMorph.disguise(player, disguisePlayer, Manager);
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 1, true, false));
} }
@Override @Override
@ -65,6 +83,21 @@ public class MorphMetalMan extends MorphGadget
removeArmor(player); removeArmor(player);
UtilMorph.undisguise(player, Manager.getDisguiseManager()); UtilMorph.undisguise(player, Manager.getDisguiseManager());
if (_playerColors.containsKey(player.getUniqueId()))
{
_playerColors.remove(player.getUniqueId());
}
if (_flying.containsKey(player))
{
_flying.remove(player);
}
player.setFlying(false);
player.setAllowFlight(false);
player.removePotionEffect(PotionEffectType.SLOW);
} }
@EventHandler @EventHandler
@ -81,7 +114,7 @@ public class MorphMetalMan extends MorphGadget
if (player.getItemInHand().getType() != Material.AIR) if (player.getItemInHand().getType() != Material.AIR)
return; return;
if (!Recharge.Instance.use(player, getName(), 5000, true, false, "Cosmetics")) if (!Recharge.Instance.use(player, "Metal Man Missile", 5000, true, false, "Cosmetics"))
return; return;
// Creates colored laser // Creates colored laser
@ -114,6 +147,61 @@ public class MorphMetalMan extends MorphGadget
metalManEffect.start(); metalManEffect.start();
} }
@EventHandler
public void onSneak(PlayerToggleSneakEvent event)
{
if (!isActive(event.getPlayer()))
return;
if (!event.isSneaking())
return;
if (_flying.containsKey(event.getPlayer()))
return;
Player player = event.getPlayer();
if (!Recharge.Instance.use(player, "Metal Man Fly", 45000, true, false, "Cosmetics"))
return;
UtilAction.velocity(player, new Vector(0, 1, 0));
player.teleport(player.getLocation().add(0, 1, 0));
player.playSound(player.getLocation(), Sound.WITHER_SHOOT, 1, 1);
_flying.put(player, System.currentTimeMillis());
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
Iterator<Map.Entry<Player, Long>> iterator = _flying.entrySet().iterator();
while (iterator.hasNext())
{
Map.Entry<Player, Long> entry = iterator.next();
Player player = entry.getKey();
if (!isActive(player))
{
iterator.remove();
continue;
}
long started = entry.getValue();
if (UtilTime.elapsed(started, 15000))
{
player.setFlying(false);
player.setAllowFlight(false);
iterator.remove();
continue;
}
player.setAllowFlight(true);
player.setFlying(true);
int filledBars = (int) ((started + 15000 - System.currentTimeMillis()) / 1000);
UtilTextBottom.displayProgress("Flying", "", 15, filledBars, player);
UtilParticle.PlayParticle(UtilParticle.ParticleType.FLAME, player.getLocation(), 0, 0, 0, 0, 5, UtilParticle.ViewDist.NORMAL);
}
}
public void increaseColor(UUID uuid) public void increaseColor(UUID uuid)
{ {
if (_playerColors.containsKey(uuid)) if (_playerColors.containsKey(uuid))

View File

@ -0,0 +1,281 @@
package mineplex.core.gadget.gadgets.morph;
import java.time.Month;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import com.mojang.authlib.GameProfile;
import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.skin.SkinData;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilFirework;
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.UtilText;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.morph.managers.SantaPresent;
import mineplex.core.gadget.gadgets.morph.managers.UtilMorph;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilGameProfile;
public class MorphSanta extends MorphGadget
{
private HashMap<Item, SantaPresent> _items = new HashMap<>();
private static final int SHARD_CHARGE = 50;
public MorphSanta(GadgetManager manager)
{
super(manager, "Santa Morph", UtilText.splitLinesToArray(new String[]{"Placeholder"}, LineFormat.LORE), -14, Material.STAINED_CLAY, (byte) 14, YearMonth.of(2016, Month.DECEMBER));
}
@Override
public void enableCustom(Player player, boolean message)
{
applyArmor(player, message);
GameProfile profile = UtilGameProfile.getGameProfile(player);
profile.getProperties().clear();
profile.getProperties().put("textures", SkinData.SANTA.getProperty());
DisguisePlayer disguisePlayer = new DisguisePlayer(player, profile);
disguisePlayer.showInTabList(true, 0);
UtilMorph.disguise(player, disguisePlayer, Manager);
}
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player);
UtilMorph.undisguise(player, Manager.getDisguiseManager());
}
// PRESENT
@EventHandler
public void throwPresent(PlayerInteractEvent event)
{
if (!isActive(event.getPlayer()))
return;
if (!UtilEvent.isAction(event, UtilEvent.ActionType.L))
return;
Player player = event.getPlayer();
int type = 0;
if (UtilMath.random(0.1, 1.1) > 0.76)
{
type = 1;
}
if (player.getItemInHand().getType() != Material.AIR)
return;
//if (!Recharge.Instance.use(player, getName(), 150000, true, false, "Cosmetics"))
//return;
if (type == 0)
{
int shards = UtilMath.rRange(250, 500);
if (Manager.getDonationManager().Get(player).getBalance(GlobalCurrency.TREASURE_SHARD) < shards + SHARD_CHARGE)
{
UtilPlayer.message(player, F.main("Gadget", "You do not have enough Shards."));
return;
}
Item present = player.getWorld().dropItem(player.getEyeLocation().add(player.getLocation().getDirection()),
SkinData.PRESENT.getSkull("Present " + System.currentTimeMillis(), new ArrayList<>()));
UtilAction.velocity(present, player.getLocation().getDirection(), 0.2, false, 0, 0.2, 1, false);
Manager.getDonationManager().RewardCoinsLater(this.getName() + " Present Hide", player, -(shards + SHARD_CHARGE));
present.setPickupDelay(40);
_items.put(present, new SantaPresent(player.getName(), SantaPresent.PresentType.PRESENT, shards));
//Announce
Bukkit.broadcastMessage(C.cYellow + C.Bold + player.getName() +
ChatColor.RESET + C.Bold + " hid a " +
C.cRed + C.Bold + "Christmas Present" +
ChatColor.RESET + C.Bold + " worth " +
C.cRed + C.Bold + shards + " Shards");
for (Player other : UtilServer.getPlayers())
other.playSound(other.getLocation(), Sound.BLAZE_HIT, 1.5f, 1.5f);
}
else
{
ItemStack coalStack = ItemStackFactory.Instance.CreateStack(Material.COAL, (byte)0, 1, "Hidden Coal" + System.currentTimeMillis());
Item coal = player.getWorld().dropItem(player.getEyeLocation().add(player.getLocation().getDirection()), coalStack);
UtilAction.velocity(coal, player.getLocation().getDirection(), 0.2, false, 0, 0.2, 1, false);
int coals = UtilMath.rRange(1, 3);
coal.setPickupDelay(40);
_items.put(coal, new SantaPresent(player.getName(), SantaPresent.PresentType.COAL, coals));
//Announce
Bukkit.broadcastMessage(C.cYellow + C.Bold + player.getName() +
ChatColor.RESET + C.Bold + " hid a " +
C.cRed + C.Bold + "Christmas Coal" +
ChatColor.RESET + C.Bold + " worth " +
C.cRed + C.Bold + coals + " Coal Ammo");
for (Player other : UtilServer.getPlayers())
other.playSound(other.getLocation(), Sound.DIG_SNOW, 1.5f, 1.5f);
}
}
@EventHandler
public void presentPickup(PlayerPickupItemEvent event)
{
if (_items.containsKey(event.getItem()) && !_items.get(event.getItem()).getThrower().equals(event.getPlayer().getName()))
{
SantaPresent santaPresent = _items.get(event.getItem());
_items.remove(event.getItem());
event.setCancelled(true);
event.getItem().remove();
int presentsLeft = 0, coalsLeft = 0;
for (SantaPresent present : _items.values())
{
if (present.getPresentType().equals(SantaPresent.PresentType.PRESENT))
{
presentsLeft++;
}
else if (present.getPresentType().equals(SantaPresent.PresentType.COAL))
{
coalsLeft++;
}
}
if (santaPresent.getPresentType().equals(SantaPresent.PresentType.PRESENT))
{
Manager.getDonationManager().RewardCoinsLater(getName() + " Present Pickup", event.getPlayer(), santaPresent.getAmmo());
//Announce
Bukkit.broadcastMessage(C.cGold + C.Bold + event.getPlayer().getName() +
ChatColor.RESET + C.Bold + " found a " +
C.cGold + C.Bold + "Christmas Present" +
ChatColor.RESET + C.Bold + "! " + presentsLeft + " Presents left!");
}
else if (santaPresent.getPresentType().equals(SantaPresent.PresentType.COAL))
{
// Gives coals
Manager.getInventoryManager().addItemToInventory(event.getPlayer(), "Coal", santaPresent.getAmmo());
//Announce
Bukkit.broadcastMessage(C.cGold + C.Bold + event.getPlayer().getName() +
ChatColor.RESET + C.Bold + " found a " +
C.cGold + C.Bold + "Christmas Coal" +
ChatColor.RESET + C.Bold + "! " + coalsLeft + " Coals left!");
}
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1.5f, 0.75f);
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1.5f, 1.25f);
UtilFirework.playFirework(event.getItem().getLocation(), FireworkEffect.Type.BURST, Color.RED, true, true);
}
}
@EventHandler
public void presentClean(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
Iterator<Item> presentIter = _items.keySet().iterator();
while (presentIter.hasNext())
{
Item presentItem = presentIter.next();
if (!presentItem.isValid() || presentItem.getTicksLived() > 24000)
{
SantaPresent santaPresent = _items.get(presentItem);
presentItem.remove();
presentIter.remove();
//Announce
if (santaPresent.getPresentType().equals(SantaPresent.PresentType.PRESENT))
{
int presentsLeft = 0;
for (SantaPresent present : _items.values())
{
if (present.getPresentType().equals(SantaPresent.PresentType.PRESENT))
{
presentsLeft++;
}
}
Bukkit.broadcastMessage(
ChatColor.RESET + C.Bold + "No one found a " +
C.cGold + C.Bold + "Christmas Present" +
ChatColor.RESET + C.Bold + "! " + presentsLeft + " Presents left!");
}
else if (santaPresent.getPresentType().equals(SantaPresent.PresentType.COAL))
{
int coalsLeft = 0;
for (SantaPresent present : _items.values())
{
if (present.getPresentType().equals(SantaPresent.PresentType.COAL))
{
coalsLeft++;
}
}
Bukkit.broadcastMessage(
ChatColor.RESET + C.Bold + "No one found a " +
C.cGold + C.Bold + "Christmas Coal" +
ChatColor.RESET + C.Bold + "! " + coalsLeft + " Coals left!");
}
}
else
{
UtilParticle.PlayParticle(UtilParticle.ParticleType.SNOW_SHOVEL, presentItem.getLocation().add(0, 0.1, 0), 0.1f, 0.1f, 0.1f, 0, 1,
UtilParticle.ViewDist.NORMAL, UtilServer.getPlayers());
}
}
}
@EventHandler
public void presentDespawnCancel(ItemDespawnEvent event)
{
if (_items.containsKey(event.getEntity()))
event.setCancelled(true);
}
}

View File

@ -1,238 +0,0 @@
package mineplex.core.gadget.gadgets.morph;
import java.io.File;
import java.io.IOException;
import java.time.Month;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.morph.managers.sleigh.Sleigh;
import mineplex.core.gadget.gadgets.morph.managers.sleigh.SleighPosition;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class MorphSleigh extends MorphGadget
{
/**
* Directions of the Sleigh, with the correct coord for the player to be teleported and the schematic name
*/
public enum SleighDirection
{
NORTH("SleighMorphNorth.schematic", 0.5, 4.5),
SOUTH("SleighMorphSouth.schematic", 0.5, 1.5),
EAST("SleighMorphEast.schematic", 1.5, 1.5),
WEST("SleighMorphWest.schematic", 4.5, 1.5);
private String _schematic;
private double _fixedX;
private double _fixedZ;
SleighDirection(String schematic, double fixedX, double fixedZ)
{
_schematic = schematic;
_fixedX = fixedX;
_fixedZ = fixedZ;
}
public String getSchematic()
{
return _schematic;
}
public double getFixedX()
{
return _fixedX;
}
public double getFixedZ()
{
return _fixedZ;
}
}
private Map<Player, Sleigh> _sleighs = new HashMap<>();
private Map<SleighDirection, Schematic> _schematics = new HashMap<>();
private List<SleighPosition> _positions = new ArrayList<>();
private Long _rightClickStart = null;
public MorphSleigh(GadgetManager manager)
{
super(manager, "Sleigh Morph", UtilText.splitLinesToArray(new String[]{"Placeholder"}, LineFormat.LORE), -14, Material.STAINED_CLAY, (byte) 14, YearMonth.of(2016, Month.DECEMBER));
// Loads sleigh schematics
for (SleighDirection sleighDirection : SleighDirection.values())
{
try
{
Schematic schematic = UtilSchematic.loadSchematic(new File("../../update/schematic/" + sleighDirection.getSchematic()));
_schematics.put(sleighDirection, schematic);
} catch (IOException e)
{
e.printStackTrace();
}
}
buildPositions();
}
@Override
public void enableCustom(Player player, boolean message)
{
applyArmor(player, message);
// TODO DISGUISE
}
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player);
// TODO UNDISGUISE
if (_sleighs.containsKey(player))
{
_sleighs.get(player).stopEffect();
_sleighs.remove(player);
}
}
/**
* Activates the sleigh effect when left-clicking
* This will be changed in the next releases
* @param event
*/
@EventHandler
public void activateSleigh(PlayerInteractEvent event)
{
if (!isActive(event.getPlayer()))
return;
if (!UtilEvent.isAction(event, UtilEvent.ActionType.L))
return;
Player player = event.getPlayer();
if (player.getItemInHand().getType() != Material.AIR)
return;
//if (!Recharge.Instance.use(player, getName(), 150000, true, false, "Cosmetics"))
//return;
List<SleighPosition> freePositions = _positions.stream().filter(position -> !position.isUsed()).collect(Collectors.toList());
if (freePositions.size() == 0)
{
UtilPlayer.message(player, F.main("Sleigh Ride", "There are too many sleighs in the sky right now! Please wait a minute and try again!"));
return;
}
int randomPosition = UtilMath.random.nextInt(freePositions.size());
SleighPosition position = freePositions.get(randomPosition);
position.setUsed(true);
SleighDirection direction = position.getDirection();
Schematic schematic = _schematics.get(direction);
if (schematic == null)
{
try
{
schematic = UtilSchematic.loadSchematic(new File("../../update/schematic/SleighMorph.schematic"));
Location fixYaw = player.getLocation().clone();
fixYaw.setYaw(90);
player.teleport(fixYaw);
}
catch (IOException e)
{
e.printStackTrace();
}
}
Sleigh sleigh = new Sleigh(player, schematic, position);
sleigh.startEffect();
_sleighs.put(player, sleigh);
}
/**
* Stops player from leaving the sleigh if it's activte
* @param event
*/
@EventHandler
public void onLeaveVehicle(VehicleExitEvent event)
{
if (event.getExited() instanceof Player)
{
Player player = (Player) event.getExited();
if (isActive(player))
{
event.setCancelled(true);
}
}
}
/**
* Creates positions in the hub map
* TODO add arcade positions
*/
private void buildPositions()
{
_positions.add(new SleighPosition(-11, 143, -30, SleighDirection.SOUTH, -9.5, 145.5, -28.5));
_positions.add(new SleighPosition(57, 109, -150, SleighDirection.SOUTH, 58.5, 111.5, -148.5));
_positions.add(new SleighPosition(141, 101, 80, SleighDirection.NORTH, 142.5, 103.5, 84.5));
_positions.add(new SleighPosition(-12, 88, 85, SleighDirection.NORTH, -10.5, 90.5, 89.5));
_positions.add(new SleighPosition(-95, 90, 70, SleighDirection.NORTH, -93.5, 92.5, 74.5));
_positions.add(new SleighPosition(-105, 115, -80, SleighDirection.EAST, -103.5, 117.5, -78.5));
_positions.add(new SleighPosition(-135, 97, -8, SleighDirection.EAST, -133.5, 99.5, -6.5));
_positions.add(new SleighPosition(-45, 97, 15, SleighDirection.EAST, -43.5, 99.5, 16.5));
_positions.add(new SleighPosition(136, 116, 85, SleighDirection.WEST, 140.5, 118.5, 86.5));
}
/**
* Removes sleighs if they run out of time, or moves them if they still have time
* @param event
*/
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() == UpdateType.FASTER)
{
_sleighs.values().forEach(Sleigh::playSound);
}
if (event.getType() != UpdateType.TICK)
return;
Iterator<Map.Entry<Player, Sleigh>> iterator = _sleighs.entrySet().iterator();
while (iterator.hasNext())
{
Map.Entry<Player, Sleigh> entry = iterator.next();
Sleigh sleigh = entry.getValue();
if (!sleigh.update())
{
iterator.remove();
}
}
}
}

View File

@ -0,0 +1,128 @@
package mineplex.core.gadget.gadgets.morph;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilText;
import mineplex.core.disguise.disguises.DisguiseSquid;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.morph.managers.UtilMorph;
import mineplex.core.gadget.types.MorphGadget;
import mineplex.core.itemstack.ItemStackFactory;
/**
* THIS MORPH IS 1.9+ ONLY
*/
public class MorphStray extends MorphGadget
{
private List<Arrow> _strayArrows = new ArrayList<>();
private ItemStack _arrow;
public MorphStray(GadgetManager manager)
{
super(manager, "Stray Morph", UtilText.splitLinesToArray(new String[]{
C.cGray + "Even though it's a stray your mom probably won't let you keep this puppy.",
"",
C.cWhite + "Gains an arrow every 5 seconds with EXTREME knockback."
}, LineFormat.LORE),
0, Material.BARRIER, (byte) 0);
_arrow = ItemStackFactory.Instance.CreateStack(Material.ARROW, (byte) 0, 1, C.cGreen + "Stray Arrow", UtilText.splitLinesToArray(new String[]{"Placeholder"}, LineFormat.LORE));
}
@Override
public void enableCustom(Player player, boolean message)
{
// TODO CHECK IF LOBBY IS 1.9+
applyArmor(player, message);
DisguiseSquid disguiseSquid = new DisguiseSquid(player);
UtilMorph.disguise(player, disguiseSquid, Manager);
// Gives bow and arrow
ItemStack bow = ItemStackFactory.Instance.CreateStack(Material.BOW, (byte) 0, 1, C.cGreen + "Stray Bow", UtilText.splitLinesToArray(new String[]{"Placeholder"}, LineFormat.LORE));
player.getInventory().setItem(2, bow);
player.getInventory().setItem(17, _arrow);
}
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player);
UtilMorph.undisguise(player, Manager.getDisguiseManager());
// Removes bow and arrow
player.getInventory().setItem(2, new ItemStack(Material.AIR));
player.getInventory().setItem(17, new ItemStack(Material.AIR));
}
@EventHandler
public void onShoot(EntityShootBowEvent event)
{
if (!(event.getEntity() instanceof Player))
return;
if (!(event.getProjectile() instanceof Arrow))
return;
Player player = (Player) event.getEntity();
if (!isActive(player))
return;
_strayArrows.add((Arrow) event.getProjectile());
Bukkit.getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
{
@Override
public void run()
{
player.getInventory().setItem(17, _arrow);
}
}, 3 * 20L);
}
@EventHandler
public void onArrowHitPlayer(EntityDamageByEntityEvent event)
{
if (!(event.getDamager() instanceof Arrow))
return;
if (!(event.getEntity() instanceof Player))
return;
if (!(((Arrow) event.getDamager()).getShooter() instanceof Player))
return;
Arrow arrow = (Arrow) event.getDamager();
Player player = (Player) event.getEntity();
if (!_strayArrows.contains(arrow))
return;
_strayArrows.remove(arrow);
Player shooter = (Player) arrow.getShooter();
arrow.remove();
if (shooter.getUniqueId().equals(player.getUniqueId()))
return;
player.setVelocity(player.getVelocity().multiply(-15).setY(15));
UtilPlayer.message(player, F.main("Stray Arrow", "You were hit with a " + F.greenElem("Stray Arrow") + " from " + F.name(shooter.getName()) + " and got knocked back!"));
UtilPlayer.message(shooter, F.main("Stray Arrow", "You hit " + F.name(player.getName()) + " with the " + F.greenElem("Stray Arrow") + " and they got knocked back!"));
}
}

View File

@ -5,7 +5,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.gadget.gadgets.particle.unrelated.WitchParticleEffect; import mineplex.core.particleeffects.WitchParticleEffect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Bat; import org.bukkit.entity.Bat;

View File

@ -0,0 +1,38 @@
package mineplex.core.gadget.gadgets.morph.managers;
public class SantaPresent
{
public enum PresentType
{
PRESENT,
COAL
}
private final String _thrower;
private final PresentType _presentType;
private final int _ammo;
public SantaPresent(String thrower, PresentType presentType, int ammo)
{
_thrower = thrower;
_presentType = presentType;
_ammo = ammo;
}
public String getThrower()
{
return _thrower;
}
public PresentType getPresentType()
{
return _presentType;
}
public int getAmmo()
{
return _ammo;
}
}

View File

@ -1,187 +0,0 @@
package mineplex.core.gadget.gadgets.morph.managers.sleigh;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilServer;
import mineplex.core.gadget.gadgets.morph.MorphSleigh;
/**
* Creates the sleigh effect for the Sleigh Morph
*/
public class Sleigh
{
private Map<Location, Material> _oldBlockMaterials = new HashMap<>();
private Map<Location, Byte> _oldBlockDatas = new HashMap<>();
private Player _player;
private Location _originalLocation;
private Schematic _schematic;
private SleighPosition _sleighPosition;
private Arrow _arrow;
private float _yaw;
private int _moves = 0;
public Sleigh(Player player, Schematic schematic, SleighPosition sleighPosition)
{
_player = player;
_schematic = schematic;
_sleighPosition = sleighPosition;
_yaw = (sleighPosition.getDirection() == MorphSleigh.SleighDirection.SOUTH) ? 0f :
(sleighPosition.getDirection() == MorphSleigh.SleighDirection.NORTH) ? 180f :
(sleighPosition.getDirection() == MorphSleigh.SleighDirection.WEST) ? 90f : -90f;
}
/**
* Starts the sleigh effect
*/
public void startEffect()
{
_originalLocation = _player.getLocation().clone();
Location origin = new Location(_originalLocation.getWorld(), _sleighPosition.getX(),
_sleighPosition.getY(), _sleighPosition.getZ());
try
{
pasteSchematic(origin, 0, 0);
} catch (IOException e)
{
e.printStackTrace();
}
}
/**
* Stops the sleigh effect
*/
public void stopEffect()
{
restoreBlocks();
_arrow.remove();
_player.teleport(_originalLocation.clone().add(0, 5, 0));
_sleighPosition.setUsed(false);
}
/**
* Pastes the schematic for the sleigh
* @param origin The location where the sleigh schematic will be placed
* @param playerX The X coord where player will be teleported
* @param playerZ The Z coord where player will be teleported
* @throws IOException
*/
private void pasteSchematic(Location origin, int playerX, int playerZ) throws IOException
{
restoreBlocks();
short width = _schematic.getWidth();
short height = _schematic.getHeight();
short length = _schematic.getLength();
for (short x = 0; x < width; x++)
{
for (short y = 0; y < height; y++)
{
for (short z = 0; z < length; z++)
{
Location location = origin.clone().add(x, y, z);
_oldBlockMaterials.put(location, location.getBlock().getType());
_oldBlockDatas.put(location, location.getBlock().getData());
}
}
}
_schematic.paste(origin);
Location playerLoc = new Location(_originalLocation.getWorld(), _sleighPosition.getPlayerX() + playerX,
_sleighPosition.getPlayerY(), _sleighPosition.getPlayerZ() + playerZ);
// Spawns arrow so it looks like player is sitting on the sleigh
if (_arrow != null)
{
_arrow.remove();
}
_arrow = playerLoc.getWorld().spawn(playerLoc, Arrow.class);
UtilEnt.ghost(_arrow, true, true);
playerLoc.setYaw(_yaw);
playerLoc.setPitch(0.0f);
_player.teleport(playerLoc);
_arrow.setPassenger(_player);
}
/**
* Updates sleigh to look like its moving
* @return true if the sleigh was moved, false if the time is over (3 seconds)
*/
public boolean update()
{
_moves++;
int x = 0, z = 0;
switch (_sleighPosition.getDirection())
{
case NORTH:
z = -1 * _moves;
break;
case SOUTH:
z = _moves;
break;
case WEST:
x = -1 * _moves;
break;
case EAST:
x = _moves;
}
Location newOrigin = new Location(_originalLocation.getWorld(), _sleighPosition.getX() + x,
_sleighPosition.getY(), _sleighPosition.getZ() + z);
restoreBlocks();
UtilParticle.PlayParticle(UtilParticle.ParticleType.SNOW_SHOVEL, _player.getLocation(), 0f, 0f, 0f, 0.6f, 100,
UtilParticle.ViewDist.LONGER, UtilServer.getPlayers());
try
{
pasteSchematic(newOrigin, x, z);
} catch (IOException e)
{
e.printStackTrace();
}
if (_moves >= 20 * 3)
{
stopEffect();
return false;
}
return true;
}
/**
* Plays sleigh sound to the player
*/
public void playSound()
{
_player.playSound(_player.getLocation(), Sound.ORB_PICKUP, 1f, 1f);
}
/**
* Restores the blocks that were changed from pasting the schematic
*/
private void restoreBlocks()
{
for (Map.Entry<Location, Material> entry : _oldBlockMaterials.entrySet())
{
Location location = entry.getKey();
Material material = entry.getValue();
byte data = 0;
if (_oldBlockDatas.containsKey(location))
{
data = _oldBlockDatas.get(location);
}
location.getBlock().setType(material);
location.getBlock().setData(data);
}
_oldBlockMaterials.clear();
_oldBlockDatas.clear();
}
}

View File

@ -1,76 +0,0 @@
package mineplex.core.gadget.gadgets.morph.managers.sleigh;
import mineplex.core.gadget.gadgets.morph.MorphSleigh;
/**
* Handles positions from Sleigh and player, and the direction of the sleigh and player
*/
public class SleighPosition
{
private int _x;
private int _y;
private int _z;
private MorphSleigh.SleighDirection _direction;
private double _playerX;
private double _playerY;
private double _playerZ;
private boolean _used;
public SleighPosition(int x, int y, int z, MorphSleigh.SleighDirection direction, double playerX, double playerY, double playerZ)
{
_x = x;
_y = y;
_z = z;
_direction = direction;
_playerX = playerX;
_playerY = playerY;
_playerZ = playerZ;
_used = false;
}
public int getX()
{
return _x;
}
public int getY()
{
return _y;
}
public int getZ()
{
return _z;
}
public MorphSleigh.SleighDirection getDirection()
{
return _direction;
}
public double getPlayerX()
{
return _playerX;
}
public double getPlayerY()
{
return _playerY;
}
public double getPlayerZ()
{
return _playerZ;
}
public void setUsed(boolean used)
{
_used = used;
}
public boolean isUsed()
{
return _used;
}
}

View File

@ -7,7 +7,7 @@ import java.util.UUID;
import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.particle.unrelated.FreedomFireworkEffect; import mineplex.core.particleeffects.FreedomFireworkEffect;
import mineplex.core.gadget.types.ParticleGadget; import mineplex.core.gadget.types.ParticleGadget;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;

View File

@ -3,16 +3,6 @@ package mineplex.core.gadget.gadgets.wineffect;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import mineplex.core.common.skin.SkinData;
import mineplex.core.common.util.*;
import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.particle.unrelated.BabyFireworkEffect;
import mineplex.core.gadget.types.WinEffectGadget;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -22,6 +12,26 @@ import org.bukkit.entity.Skeleton;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.common.skin.SkinData;
import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.common.util.UtilSkull;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.particleeffects.BabyFireworkEffect;
import mineplex.core.gadget.types.WinEffectGadget;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilVariant;
public class WinEffectHalloween extends WinEffectGadget public class WinEffectHalloween extends WinEffectGadget
{ {
@ -119,10 +129,9 @@ public class WinEffectHalloween extends WinEffectGadget
private void spawnSkeleton() private void spawnSkeleton()
{ {
Skeleton skeleton = getBaseLocation().getWorld().spawn(getBaseLocation(), Skeleton.class); Skeleton skeleton = UtilVariant.spawnWitherSkeleton(getBaseLocation());
skeleton.setCustomName(getRank(_player) + _player.getName()); skeleton.setCustomName(getRank(_player) + _player.getName());
skeleton.setCustomNameVisible(true); skeleton.setCustomNameVisible(true);
skeleton.setSkeletonType(Skeleton.SkeletonType.WITHER);
skeleton.getEquipment().setHelmet(new ItemStack(Material.JACK_O_LANTERN)); skeleton.getEquipment().setHelmet(new ItemStack(Material.JACK_O_LANTERN));
UtilEnt.ghost(skeleton, true, false); UtilEnt.ghost(skeleton, true, false);
UtilEnt.Vegetate(skeleton); UtilEnt.Vegetate(skeleton);

View File

@ -1,14 +1,12 @@
package mineplex.core.hologram; package mineplex.core.hologram;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import net.minecraft.server.v1_8_R3.DataWatcher; import net.minecraft.server.v1_8_R3.DataWatcher;
import net.minecraft.server.v1_8_R3.EntityArmorStand; import net.minecraft.server.v1_8_R3.EntityArmorStand;
import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.Packet;
@ -18,6 +16,14 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
public class Hologram { public class Hologram {
public enum HologramTarget { public enum HologramTarget {
@ -481,12 +487,6 @@ public class Hologram {
// Send update metadata packets // Send update metadata packets
Integer entityId = _entityIds.get(i); Integer entityId = _entityIds.get(i);
PacketPlayOutEntityMetadata metadata1_8 = new PacketPlayOutEntityMetadata();
PacketPlayOutEntityMetadata metadata1_9 = new PacketPlayOutEntityMetadata();
metadata1_8.a = entityId;
metadata1_9.a = entityId;
DataWatcher watcher1_8 = new DataWatcher(null); DataWatcher watcher1_8 = new DataWatcher(null);
DataWatcher watcher1_9 = new DataWatcher(null); DataWatcher watcher1_9 = new DataWatcher(null);
@ -504,11 +504,9 @@ public class Hologram {
watcher1_9.a(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16); watcher1_9.a(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16);
} }
} }
metadata1_8.b = watcher1_8.c();
metadata1_9.b = watcher1_9.c();
packets1_8.add(metadata1_8); packets1_8.add(new PacketPlayOutEntityMetadata(entityId, watcher1_8, true));
packets1_9.add(metadata1_9); packets1_9.add(new PacketPlayOutEntityMetadata(entityId, watcher1_9, true));
} }
} }

View File

@ -5,15 +5,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -30,14 +23,20 @@ import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
public class ItemStackFactory extends MiniPlugin public class ItemStackFactory extends MiniPlugin
{ {
public static ItemStackFactory Instance; public static ItemStackFactory Instance;

View File

@ -23,6 +23,7 @@ import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilVariant;
public class HorseMount extends Mount<SingleEntityMountData<Horse>> public class HorseMount extends Mount<SingleEntityMountData<Horse>>
{ {
@ -104,12 +105,11 @@ public class HorseMount extends Mount<SingleEntityMountData<Horse>>
//Remove other mounts //Remove other mounts
Manager.DeregisterAll(player); Manager.DeregisterAll(player);
Horse horse = player.getWorld().spawn(player.getLocation(), Horse.class); Horse horse = UtilVariant.spawnHorse(player.getLocation(), _variant);
horse.setAdult(); horse.setAdult();
horse.setAgeLock(true); horse.setAgeLock(true);
horse.setColor(_color); horse.setColor(_color);
horse.setStyle(_style); horse.setStyle(_style);
horse.setVariant(_variant);
horse.setOwner(player); horse.setOwner(player);
horse.setMaxDomestication(1); horse.setMaxDomestication(1);
horse.setJumpStrength(_jump); horse.setJumpStrength(_jump);

View File

@ -28,6 +28,7 @@ import mineplex.core.mount.SingleEntityMountData;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilVariant;
public class MountChicken extends HorseMount public class MountChicken extends HorseMount
{ {
@ -61,12 +62,11 @@ public class MountChicken extends HorseMount
//Remove other mounts //Remove other mounts
Manager.DeregisterAll(player); Manager.DeregisterAll(player);
Horse horse = player.getWorld().spawn(player.getLocation(), Horse.class); Horse horse = UtilVariant.spawnHorse(player.getLocation(), _variant);
horse.setAdult(); horse.setAdult();
horse.setAgeLock(true); horse.setAgeLock(true);
horse.setColor(_color); horse.setColor(_color);
horse.setStyle(_style); horse.setStyle(_style);
horse.setVariant(_variant);
horse.setOwner(player); horse.setOwner(player);
horse.setMaxDomestication(1); horse.setMaxDomestication(1);
horse.setJumpStrength(_jump); horse.setJumpStrength(_jump);

View File

@ -3,10 +3,9 @@ package mineplex.core.mount.types;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.gadgets.particle.unrelated.FreedomTrailEffect; import mineplex.core.particleeffects.FreedomTrailEffect;
import mineplex.core.mount.HorseMount; import mineplex.core.mount.HorseMount;
import mineplex.core.mount.MountManager; import mineplex.core.mount.MountManager;
import mineplex.core.mount.SingleEntityMountData; import mineplex.core.mount.SingleEntityMountData;

View File

@ -35,6 +35,7 @@ import mineplex.core.mount.SingleEntityMountData;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilVariant;
public class MountSpider extends HorseMount public class MountSpider extends HorseMount
{ {
@ -76,7 +77,7 @@ public class MountSpider extends HorseMount
//Remove other mounts //Remove other mounts
Manager.DeregisterAll(player); Manager.DeregisterAll(player);
Horse horse = player.getWorld().spawn(player.getLocation(), Horse.class); Horse horse = UtilVariant.spawnHorse(player.getLocation(), _variant);
horse.setAdult(); horse.setAdult();
horse.setAgeLock(true); horse.setAgeLock(true);
horse.setColor(_color); horse.setColor(_color);

View File

@ -1,14 +1,15 @@
package mineplex.core.gadget.gadgets.particle.unrelated; package mineplex.core.particleeffects;
import java.util.Random; import java.util.Random;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.particles.ColoredParticle; import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor; import mineplex.core.common.util.particles.DustSpellColor;
import mineplex.core.common.util.particles.NormalParticle; import mineplex.core.common.util.particles.NormalParticle;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
public class BabyFireworkEffect extends Effect public class BabyFireworkEffect extends Effect
{ {

View File

@ -1,4 +1,4 @@
package mineplex.core.gadget.gadgets.particle.unrelated; package mineplex.core.particleeffects;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -11,6 +11,7 @@ public abstract class Effect
public EffectLocation _effectLocation; public EffectLocation _effectLocation;
public EffectLocation _targetLocation; public EffectLocation _targetLocation;
protected JavaPlugin _javaPlugin; protected JavaPlugin _javaPlugin;
private boolean _running = false;
public Effect(int ticks, EffectLocation effectLocation, JavaPlugin javaPlugin) public Effect(int ticks, EffectLocation effectLocation, JavaPlugin javaPlugin)
{ {
@ -29,6 +30,8 @@ public abstract class Effect
public void start() public void start()
{ {
onStart();
_running = true;
_task = Bukkit.getScheduler().scheduleSyncRepeatingTask(_javaPlugin, new Runnable() _task = Bukkit.getScheduler().scheduleSyncRepeatingTask(_javaPlugin, new Runnable()
{ {
@Override @Override
@ -42,9 +45,15 @@ public abstract class Effect
public void stop() public void stop()
{ {
_running = false;
Bukkit.getScheduler().cancelTask(_task); Bukkit.getScheduler().cancelTask(_task);
onStop();
} }
public void onStart(){};
public void onStop(){};
private void update() private void update()
{ {
_ticks++; _ticks++;
@ -52,6 +61,11 @@ public abstract class Effect
Bukkit.getScheduler().cancelTask(_task); Bukkit.getScheduler().cancelTask(_task);
} }
public boolean isRunning()
{
return _running;
}
public abstract void runEffect(); public abstract void runEffect();
public void setTargetLocation(EffectLocation effectLocation) public void setTargetLocation(EffectLocation effectLocation)
@ -64,4 +78,9 @@ public abstract class Effect
return _targetLocation; return _targetLocation;
} }
public EffectLocation getEffectLocation()
{
return _effectLocation;
}
} }

View File

@ -1,4 +1,4 @@
package mineplex.core.gadget.gadgets.particle.unrelated; package mineplex.core.particleeffects;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;

View File

@ -1,4 +1,4 @@
package mineplex.core.gadget.gadgets.particle.unrelated; package mineplex.core.particleeffects;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Location; import org.bukkit.Location;

View File

@ -1,13 +1,15 @@
package mineplex.core.gadget.gadgets.particle.unrelated; package mineplex.core.particleeffects;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.particles.ColoredParticle; import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor; import mineplex.core.common.util.particles.DustSpellColor;
import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class FreedomTrailEffect extends Effect public class FreedomTrailEffect extends Effect
{ {

View File

@ -1,10 +1,11 @@
package mineplex.core.gadget.gadgets.particle.unrelated; package mineplex.core.particleeffects;
import mineplex.core.common.util.UtilFirework;
import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilFirework;
public class HalloweenSmashedEffect extends Effect public class HalloweenSmashedEffect extends Effect
{ {

View File

@ -1,18 +1,24 @@
package mineplex.core.gadget.gadgets.particle.unrelated; package mineplex.core.particleeffects;
import java.awt.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import mineplex.core.common.util.*;
import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor;
import org.bukkit.Color; import org.bukkit.Color;
import mineplex.core.gadget.types.Gadget;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor;
import mineplex.core.gadget.types.Gadget;
public class MetalManEffect extends Effect public class MetalManEffect extends Effect
{ {
@ -23,20 +29,28 @@ public class MetalManEffect extends Effect
private Location _fixedLoc; private Location _fixedLoc;
private Gadget _gadget; private Gadget _gadget;
private Player _player; private Player _player;
private int _totalCount = 0;
private boolean _forceStop = false;
public MetalManEffect(Location location, Location target, int color, Gadget gadget, Player player) public MetalManEffect(Location location, Location target, int color, Gadget gadget, Player player)
{ {
super(-1, new EffectLocation(location), gadget.Manager.getPlugin()); super(-1, new EffectLocation(player), gadget.Manager.getPlugin());
_color = color; _color = color;
_gadget = gadget; _gadget = gadget;
_player = player; _player = player;
setTargetLocation(new EffectLocation(target)); setTargetLocation(new EffectLocation(target));
} }
@Override
public void onStart()
{
_player.getWorld().playSound(_player.getLocation(), Sound.PISTON_RETRACT, 1f, 1f);
}
@Override @Override
public void runEffect() public void runEffect()
{ {
Location location = _effectLocation.getFixedLocation().clone(); Location location = _effectLocation.getFixedLocation().clone().add(0, 1, 0);
if (_vector == null) if (_vector == null)
{ {
Location targetLoc = getTargetLocation().getFixedLocation().clone(); Location targetLoc = getTargetLocation().getFixedLocation().clone();
@ -54,21 +68,41 @@ public class MetalManEffect extends Effect
coloredParticle.setLocation(_fixedLoc); coloredParticle.setLocation(_fixedLoc);
coloredParticle.display(UtilParticle.ViewDist.LONG); coloredParticle.display(UtilParticle.ViewDist.LONG);
} }
if (_fixedLoc.getBlock().getType() != Material.AIR || _count == 1000) if (_fixedLoc.getBlock().getType() != Material.AIR )
{ {
explode(); stop();
}
else if (_count >= 1000)
{
_forceStop = true;
stop();
} }
_count += 5; _count += 5;
} }
private void explode() @Override
public void onStop()
{ {
this.stop(); if (!_forceStop)
{
_count = 0;
_vector = null;
HashSet<Material> ignore = new HashSet<Material>();
ignore.add(Material.AIR);
Location loc = _player.getTargetBlock(ignore, 64).getLocation().add(0.5, 0.5, 0.5);
_effectLocation = new EffectLocation(_player);
setTargetLocation(new EffectLocation(loc));
_totalCount++;
if (_totalCount != 3)
{
start();
}
}
// Creates the explosion and knockback players // Creates the explosion and knockback players
Location loc = _fixedLoc; Location loc = _fixedLoc;
loc.getWorld().createExplosion(loc, 0f); loc.getWorld().createExplosion(loc, 0f);
UtilParticle.PlayParticle(UtilParticle.ParticleType.EXPLODE, loc, 3f, 3f, 3f, 0, 32, UtilParticle.ViewDist.MAX, UtilServer.getPlayers()); UtilParticle.PlayParticle(UtilParticle.ParticleType.EXPLODE, loc, 3f, 3f, 3f, 0, 32, UtilParticle.ViewDist.MAX, UtilServer.getPlayers());
HashMap<Player, Double> players = UtilPlayer.getInRadius(loc, 5d); HashMap<Player, Double> players = UtilPlayer.getInRadius(loc, 9d);
for (Player ent : players.keySet()) for (Player ent : players.keySet())
{ {
if (_gadget.Manager.collideEvent(_player, _gadget, ent)) if (_gadget.Manager.collideEvent(_player, _gadget, ent))

View File

@ -0,0 +1,155 @@
package mineplex.core.particleeffects;
public class NewYearEffect //extends Effect
{
/*private static final int SECONDS_IN_A_MINUTE = 60;
private final Location _ballLocation, _clockLocation, _timerLocation, _timerLocationTen;
private int _seconds = 90;
private Collection<Block> _blocks = new ArrayList<>();
private List<Schematic> _schematics = new ArrayList<>();
private boolean _placed = false;
private int _currentRun = 0;
public NewYearEffect(JavaPlugin plugin, Location location)
{
super(-1, new EffectLocation(location), plugin, 10);
_ballLocation = new Location(location.clone().getWorld(), 0, 71, 38);
_clockLocation = _ballLocation.clone().add(-12, 0, -15);
_timerLocation = _clockLocation.clone().add(19, 7, 0);
_timerLocationTen = _timerLocation.clone().add(1, 0, 0);
try
{
for (int i = 0; i <= 10; i++)
{
Schematic schematic = UtilSchematic.loadSchematic(new File("../../update/schematic/NewYearBall" + i + ".schematic"));
_schematics.add(i, schematic);
}
Schematic schematic = UtilSchematic.loadSchematic(new File("../../update/schematic/NewYearClock.schematic"));
_schematics.add(11, schematic);
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public void runEffect()
{
if (!_placed)
{
pasteSchematic(10, true);
_placed = true;
}
if (_seconds == -60)
{
stop();
return;
}
if (_seconds == 0)
{
List<int[]> fireworkLocations = new ArrayList<>();
List<int[]> fixedFireworkLocations = new ArrayList<>();
int[][] fireworkCoords = new int[][]
{
{0, 77, -37},
{-6, 71, 17},
{6, 71, 17},
{12, 71, 7},
{-12, 71, 7},
{5, 71, 92},
{-7, 71, 92},
{-9, 103, 37},
{13, 107, 40}
};
fireworkLocations.addAll(Arrays.asList(fireworkCoords));
int[][] fixedFireworkCoords = new int[][]
{
{0, 80, 0},
{0, 80, -32},
{6, 80, -26},
{-6, 80, -26}
};
fixedFireworkLocations.addAll(Arrays.asList(fixedFireworkCoords));
NewYearFireworkEffect newYearFireworkEffect = new NewYearFireworkEffect(_javaPlugin, fireworkLocations, fixedFireworkLocations, getEffectLocation().getFixedLocation().getWorld());
newYearFireworkEffect.start();
}
if (_currentRun % 2 != 0 && _seconds >= 0)
{
//Format seconds
int totalMinutes = 0, totalSeconds = 0, placeholder;
placeholder = _seconds;
if (_seconds > SECONDS_IN_A_MINUTE)
{
while (placeholder > SECONDS_IN_A_MINUTE)
{
totalMinutes++;
placeholder -= SECONDS_IN_A_MINUTE;
}
}
totalSeconds = placeholder;
String formatted = String.format("%02d:%02d", totalMinutes, totalSeconds);
if (_seconds <= 10)
{
formatted = "| " + _seconds + " |";
pasteSchematic(_seconds, false);
}
updateTimer(formatted, (byte) 0);
_seconds--;
}
else if (_seconds >= 0 && _seconds <= 10)
{
updateTimer("| " + _seconds + " |", (byte) 14);
}
else if (_currentRun % 2 != 0 && _seconds < 0)
{
updateTimer("2017!", (byte) 0);
_seconds--;
}
else if (_seconds < 0)
{
updateTimer("2017!", (byte) 14);
}
_currentRun++;
}
@Override
public void onStop()
{
_blocks.forEach(b -> b.setType(Material.AIR));
_blocks.clear();
updateTimer("2017!", (byte) 14);
}
private void pasteSchematic(int second, boolean pasteClock)
{
Schematic schematic = _schematics.get(second);
if (schematic != null)
{
schematic.paste(_ballLocation, false, true);
if (pasteClock)
{
Schematic clockSchematic = _schematics.get(11);
clockSchematic.paste(_clockLocation);
}
}
}
private void updateTimer(String time, byte color)
{
// Clears previous blocks
_blocks.forEach(b -> b.setType(Material.AIR));
Collection<Block> blocks = UtilBlockText.MakeText(time, (_seconds <= 10 && _seconds >= 0) ? _timerLocationTen : _timerLocation, BlockFace.WEST, Material.STAINED_CLAY.getId(), color, UtilBlockText.TextAlign.LEFT, false);
_blocks = blocks;
}*/
}

View File

@ -0,0 +1,46 @@
package mineplex.core.particleeffects;
public class NewYearFireworkEffect //extends Effect
{
/*private static final int MAX_TICKS = 1200;
private List<Location> _locations = new ArrayList<>();
private List<Location> _fixedLocations = new ArrayList<>();
private int _ticks = 0;
public NewYearFireworkEffect(JavaPlugin plugin, List<int[]> locations, List<int[]> fixedLocations, World world)
{
super(-1, null, plugin, 5);
for (int[] locCoords : locations)
{
_locations.add(new Location(world, locCoords[0], locCoords[1], locCoords[2]));
}
for (int[] locCoords : fixedLocations)
{
_locations.add(new Location(world, locCoords[0], locCoords[1], locCoords[2]));
}
}
@Override
public void runEffect()
{
for (int i = 0; i < 5; i++)
{
int r = UtilMath.random.nextInt(_locations.size() - 1);
Location location = _locations.get(r);
UtilFirework.launchFirework(location, UtilFirework.getRandomFireworkEffect(true, 2, 2),
new Vector((Math.random() - 0.5) * 0.05, 0.1, (Math.random() - 0.5) * 0.05), 1);
}
for (Location location : _fixedLocations)
{
UtilFirework.launchFirework(location, UtilFirework.getRandomFireworkEffect(true, 2, 2),
new Vector((Math.random() - 0.5) * 0.05, 0.1, (Math.random() - 0.5) * 0.05), 1);
}
_ticks += 5;
if (_ticks >= MAX_TICKS)
{
stop();
}
}*/
}

View File

@ -0,0 +1,87 @@
package mineplex.core.particleeffects;
import java.awt.*;
import java.awt.image.BufferedImage;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.particles.ColoredParticle;
import mineplex.core.common.util.particles.DustSpellColor;
public class TextEffect extends Effect
{
private static final double IMAGE_SIZE = 0.2;
private String _text;
private Font _font;
private boolean _realtime;
private boolean _invert;
private BufferedImage _bufferedImage;
private ColoredParticle _coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, new DustSpellColor(Color.GREEN), null);
public TextEffect(JavaPlugin plugin, int ticks, String text, Location location, boolean realtime, boolean invert) throws Exception
{
super(ticks, new EffectLocation(location), plugin);
_text = text;
_font = new Font("Tahoma", Font.PLAIN, 16);
_realtime = realtime;
_invert = invert;
}
public void setText(String text)
{
if (!_realtime)
return;
_text = text;
}
@Override
public void runEffect()
{
if (_text == null || _font == null)
{
stop();
return;
}
if (_bufferedImage == null || _realtime)
{
_bufferedImage = UtilText.stringToBufferedImage(_font, _text);
}
int color = 0;
for (int y = 0; y < _bufferedImage.getHeight(); y++)
{
for (int x = 0; x < _bufferedImage.getWidth(); x++)
{
color = _bufferedImage.getRGB(x, y);
if (!_invert && java.awt.Color.black.getRGB() != color)
continue;
else if (_invert && java.awt.Color.black.getRGB() == color)
continue;
Vector vector = new Vector((float) _bufferedImage.getWidth() / 2 - x, (float) _bufferedImage.getHeight() / 2 - y, 0).multiply(IMAGE_SIZE);
vector = rotateAroundAxisY(vector, -_effectLocation.getFixedLocation().getYaw() * (Math.PI / 180));
_coloredParticle.setLocation(_effectLocation.getFixedLocation().clone().add(vector));
_coloredParticle.display();
}
}
}
private Vector rotateAroundAxisY(Vector v, double angle)
{
double x, z, cos, sin;
cos = Math.cos(angle);
sin = Math.sin(angle);
x = v.getX() * cos + v.getZ() * sin;
z = v.getX() * -sin + v.getZ() * cos;
return v.setX(x).setZ(z);
}
}

View File

@ -1,9 +1,10 @@
package mineplex.core.gadget.gadgets.particle.unrelated; package mineplex.core.particleeffects;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
public class WitchParticleEffect extends Effect public class WitchParticleEffect extends Effect
{ {

View File

@ -1,57 +0,0 @@
package mineplex.core.pet;
import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.pet.repository.token.PetSalesToken;
import mineplex.core.shop.item.SalesPackageBase;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
public class Pet extends SalesPackageBase
{
private String _name;
private EntityType _petType;
private String _lore = null;
public Pet(String name, EntityType petType, int cost)
{
super(name, Material.MONSTER_EGG, (byte)petType.getTypeId(), new String[] {});
_name = name;
_petType = petType;
CurrencyCostMap.put(GlobalCurrency.TREASURE_SHARD, cost);
KnownPackage = false;
}
public Pet(String name, EntityType petType, int cost, String lore)
{
super(name, Material.MONSTER_EGG, (byte)petType.getTypeId(), new String[] {});
_name = name;
_petType = petType;
CurrencyCostMap.put(GlobalCurrency.TREASURE_SHARD, cost);
_lore = lore;
KnownPackage = false;
}
public EntityType getPetType()
{
return _petType;
}
public void update(PetSalesToken petToken)
{
_name = petToken.Name;
}
public String getPetName()
{
return _name;
}
public String getLore()
{
return _lore;
}
}

View File

@ -1,33 +1,28 @@
package mineplex.core.pet; package mineplex.core.pet;
import org.bukkit.entity.EntityType;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.pet.repository.token.ClientPetToken;
import mineplex.core.pet.repository.token.PetToken;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import mineplex.core.pet.repository.token.ClientPetToken;
import mineplex.core.pet.repository.token.PetToken;
public class PetClient public class PetClient
{ {
private Map<EntityType, String> _pets = new HashMap<>(); private Map<PetType, String> _pets = new HashMap<>();
private int _petNameTagCount; private int _petNameTagCount;
public void load(ClientPetToken token) public void load(ClientPetToken token)
{ {
for (PetToken petToken : token.Pets) for (PetToken petToken : token.Pets)
{ {
if (petToken.PetName == null) PetType type = PetType.valueOf(petToken.PetType);
petToken.PetName = Enum.valueOf(EntityType.class, petToken.PetType).getName(); _pets.put(type, petToken.PetName != null ? petToken.PetName : type.getName());
_pets.put(Enum.valueOf(EntityType.class, petToken.PetType), petToken.PetName);
} }
_petNameTagCount = Math.max(0, token.PetNameTagCount); _petNameTagCount = Math.max(0, token.PetNameTagCount);
} }
public Map<EntityType, String> getPets() public Map<PetType, String> getPets()
{ {
return _pets; return _pets;
} }

View File

@ -1,30 +1,22 @@
package mineplex.core.pet; package mineplex.core.pet;
import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.pet.repository.token.PetExtraToken;
import mineplex.core.shop.item.SalesPackageBase;
import org.bukkit.Material; import org.bukkit.Material;
public class PetExtra extends SalesPackageBase import mineplex.core.pet.sales.PetExtraSalesPackage;
{
private String _name;
private Material _material;
public PetExtra(String name, Material material, int cost) public enum PetExtra
{ {
super(name, material, (byte)0, new String[] { }); NAME_TAG("Name Tag", Material.NAME_TAG, 100)
;
private final String _name;
private final Material _material;
private final int _price;
PetExtra(String name, Material material, int price)
{
_name = name; _name = name;
_material = material; _material = material;
CurrencyCostMap.put(GlobalCurrency.TREASURE_SHARD, cost); _price = price;
KnownPackage = false;
OneTimePurchaseOnly = false;
}
public void Update(PetExtraToken token)
{
} }
public String getName() public String getName()
@ -32,8 +24,18 @@ public class PetExtra extends SalesPackageBase
return _name; return _name;
} }
public Material GetMaterial() public Material getMaterial()
{ {
return _material; return _material;
} }
public int getPrice()
{
return _price;
}
public PetExtraSalesPackage toSalesPackage(String text)
{
return new PetExtraSalesPackage(text, _material, _price);
}
} }

View File

@ -1,72 +0,0 @@
package mineplex.core.pet;
import java.util.Collection;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.pet.repository.PetRepository;
import mineplex.core.pet.types.Elf;
import mineplex.core.pet.types.PetCoalApparition;
import mineplex.core.pet.types.Pumpkin;
public class PetFactory
{
private PetRepository _repository;
private NautHashMap<EntityType, Pet> _pets;
private NautHashMap<Material, PetExtra> _petExtras;
public PetFactory(PetRepository repository)
{
_repository = repository;
_pets = new NautHashMap<>();
_petExtras = new NautHashMap<>();
CreatePets();
CreatePetExtras();
}
private void CreatePets()
{
_pets.put(EntityType.ZOMBIE, new Pumpkin());
_pets.put(EntityType.PIG_ZOMBIE, new PetCoalApparition());
_pets.put(EntityType.VILLAGER, new Elf());
_pets.put(EntityType.PIG, new Pet("Pig", EntityType.PIG, 5000));
_pets.put(EntityType.SHEEP, new Pet("Sheep", EntityType.SHEEP, 3000));
_pets.put(EntityType.COW, new Pet("Cow", EntityType.COW, 2000));
_pets.put(EntityType.CHICKEN, new Pet("Chicken", EntityType.CHICKEN, 7000));
_pets.put(EntityType.WOLF, new Pet("Dog", EntityType.WOLF, 8000));
_pets.put(EntityType.OCELOT, new Pet("Cat", EntityType.OCELOT, 6000));
_pets.put(EntityType.MUSHROOM_COW, new Pet("Mooshroom", EntityType.MUSHROOM_COW, 5000));
_pets.put(EntityType.WITHER, new Pet("Widder", EntityType.WITHER, -12));
_pets.put(EntityType.SKELETON, new Pet("Guardian", EntityType.SKELETON, -13));
_pets.put(EntityType.RABBIT, new Pet("Baby Zombie", EntityType.RABBIT, -9, "They're so cute - until a pack of them chases down your family and eats them."));
_pets.put(EntityType.BLAZE, new Pet("Grim Reaper", EntityType.BLAZE, -8, "Aww isn't he so cute with his little wings and little scythe?"));
}
private void CreatePetExtras()
{
_petExtras.put(Material.SIGN, new PetExtra("Name Tag", Material.NAME_TAG, 100));
}
public Collection<Pet> GetPets()
{
return _pets.values();
}
public Collection<PetExtra> GetPetExtras()
{
return _petExtras.values();
}
public Collection<PetExtra> GetPetExtraBySalesId(int salesId)
{
return _petExtras.values();
}
public Pet getPet(EntityType type)
{
return _pets.get(type);
}
}

View File

@ -1,37 +1,33 @@
package mineplex.core.pet; package mineplex.core.pet;
import java.util.*; import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID;
import com.google.gson.Gson;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.ClientWebResponseEvent;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.Rank;
import mineplex.core.common.shape.ShapeWings;
import mineplex.core.common.util.*;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseChicken;
import mineplex.core.disguise.disguises.DisguiseGuardian;
import mineplex.core.disguise.disguises.DisguiseWither;
import mineplex.core.disguise.disguises.DisguiseZombie;
import mineplex.core.donation.DonationManager;
import mineplex.core.events.AddConditionEvent;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.pet.repository.PetRepository;
import mineplex.core.pet.repository.token.ClientPetTokenWrapper;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import net.minecraft.server.v1_8_R3.EntityCreature; import net.minecraft.server.v1_8_R3.EntityCreature;
import net.minecraft.server.v1_8_R3.NavigationAbstract; import net.minecraft.server.v1_8_R3.NavigationAbstract;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.SkullType;
import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreature; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreature;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPigZombie; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPigZombie;
import org.bukkit.entity.*; import org.bukkit.entity.Ageable;
import org.bukkit.entity.Blaze;
import org.bukkit.entity.Creature;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
@ -45,6 +41,35 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import com.google.gson.Gson;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.ClientWebResponseEvent;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.Rank;
import mineplex.core.common.shape.ShapeWings;
import mineplex.core.common.util.NautHashMap;
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.UtilServer;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseChicken;
import mineplex.core.disguise.disguises.DisguiseGuardian;
import mineplex.core.disguise.disguises.DisguiseWither;
import mineplex.core.disguise.disguises.DisguiseZombie;
import mineplex.core.donation.DonationManager;
import mineplex.core.events.AddConditionEvent;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.pet.repository.PetRepository;
import mineplex.core.pet.repository.token.ClientPetTokenWrapper;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class PetManager extends MiniClientPlugin<PetClient> public class PetManager extends MiniClientPlugin<PetClient>
{ {
private static Object _petOwnerSynch = new Object(); private static Object _petOwnerSynch = new Object();
@ -53,13 +78,13 @@ public class PetManager extends MiniClientPlugin<PetClient>
private DisguiseManager _disguiseManager; private DisguiseManager _disguiseManager;
private mineplex.core.creature.Creature _creatureModule; private mineplex.core.creature.Creature _creatureModule;
private PetRepository _repository; private PetRepository _repository;
private PetFactory _petFactory;
private BlockRestore _blockRestore; private BlockRestore _blockRestore;
private Map<String, PetType> _activePetOwnerTypes = new HashMap<>();
private NautHashMap<String, Creature> _activePetOwners; private NautHashMap<String, Creature> _activePetOwners;
private NautHashMap<String, Integer> _failedAttempts; private NautHashMap<String, Integer> _failedAttempts;
private NautHashMap<String, EntityType> _petOwnerQueue = new NautHashMap<String, EntityType>(); private Map<String, PetType> _petOwnerQueue = new HashMap<>();
private NautHashMap<String, String> _petRenameQueue = new NautHashMap<String, String>(); private NautHashMap<String, String> _petRenameQueue = new NautHashMap<String, String>();
private DonationManager _donationManager; private DonationManager _donationManager;
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
@ -78,7 +103,6 @@ public class PetManager extends MiniClientPlugin<PetClient>
_creatureModule = creatureModule; _creatureModule = creatureModule;
_disguiseManager = disguiseManager; _disguiseManager = disguiseManager;
_repository = new PetRepository(plugin, webAddress); _repository = new PetRepository(plugin, webAddress);
_petFactory = new PetFactory(_repository);
_blockRestore = restore; _blockRestore = restore;
_donationManager = donationManager; _donationManager = donationManager;
_clientManager = clientManager; _clientManager = clientManager;
@ -88,11 +112,11 @@ public class PetManager extends MiniClientPlugin<PetClient>
_failedAttempts = new NautHashMap<String, Integer>(); _failedAttempts = new NautHashMap<String, Integer>();
} }
public void addPetOwnerToQueue(String playerName, EntityType entityType) public void addPetOwnerToQueue(String playerName, PetType petType)
{ {
synchronized (_petOwnerSynch) synchronized (_petOwnerSynch)
{ {
_petOwnerQueue.put(playerName, entityType); _petOwnerQueue.put(playerName, petType);
} }
} }
@ -150,22 +174,22 @@ public class PetManager extends MiniClientPlugin<PetClient>
if (rank.has(Rank.LEGEND)) if (rank.has(Rank.LEGEND))
{ {
if (!Get(p).getPets().containsKey(EntityType.WITHER)) if (!Get(p).getPets().containsKey(PetType.WITHER))
Get(p).getPets().put(EntityType.WITHER, "Widder"); Get(p).getPets().put(PetType.WITHER, "Widder");
} }
if (rank.has(Rank.TITAN)) if (rank.has(Rank.TITAN))
{ {
if (!Get(p).getPets().containsKey(EntityType.SKELETON)) if (!Get(p).getPets().containsKey(PetType.SKELETON))
Get(p).getPets().put(EntityType.SKELETON, "Guardian"); Get(p).getPets().put(PetType.SKELETON, "Guardian");
} }
} }
public void addPetOwner(Player player, EntityType entityType, Location location) public void addPetOwner(Player player, PetType petType, Location location)
{ {
if (_activePetOwners.containsKey(player.getName())) if (_activePetOwnerTypes.containsKey(player.getName()))
{ {
if (_activePetOwners.get(player.getName()).getType() != entityType) if (_activePetOwnerTypes.get(player.getName()) != petType)
{ {
removePet(player, true); removePet(player, true);
} }
@ -174,6 +198,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
} }
Creature pet; Creature pet;
EntityType entityType = petType.getEntityType();
//Wither Spawn //Wither Spawn
if (entityType == EntityType.WITHER) if (entityType == EntityType.WITHER)
@ -200,14 +225,14 @@ public class PetManager extends MiniClientPlugin<PetClient>
//Default Spawn //Default Spawn
else else
{ {
pet = (Creature)_creatureModule.SpawnEntity(location, entityType); pet = (Creature)_creatureModule.SpawnEntity(location, petType.getEntityType());
} }
//Named Pet //Named Pet
if (Get(player).getPets().get(entityType) != null && Get(player).getPets().get(entityType).length() > 0) if (Get(player).getPets().get(petType) != null && Get(player).getPets().get(petType).length() > 0)
{ {
//pet.setCustomNameVisible(true); //pet.setCustomNameVisible(true);
pet.setCustomName(Get(player).getPets().get(entityType)); pet.setCustomName(Get(player).getPets().get(petType));
} }
if (pet instanceof Zombie) if (pet instanceof Zombie)
@ -282,6 +307,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
_grimReaperMorphs.put((Blaze) pet, grimReaperPetManager); _grimReaperMorphs.put((Blaze) pet, grimReaperPetManager);
} }
_activePetOwnerTypes.put(player.getName(), petType);
_activePetOwners.put(player.getName(), pet); _activePetOwners.put(player.getName(), pet);
_failedAttempts.put(player.getName(), 0); _failedAttempts.put(player.getName(), 0);
@ -318,6 +344,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
if (removeOwner) if (removeOwner)
{ {
_activePetOwnerTypes.remove(player.getName());
_activePetOwners.remove(player.getName()); _activePetOwners.remove(player.getName());
} }
} }
@ -504,11 +531,6 @@ public class PetManager extends MiniClientPlugin<PetClient>
return new PetClient(); return new PetClient();
} }
public PetFactory getFactory()
{
return _petFactory;
}
public PetRepository getRepository() public PetRepository getRepository()
{ {
return _repository; return _repository;
@ -516,7 +538,12 @@ public class PetManager extends MiniClientPlugin<PetClient>
public boolean hasActivePet(String name) public boolean hasActivePet(String name)
{ {
return _activePetOwners.containsKey(name); return _activePetOwnerTypes.containsKey(name);
}
public PetType getActivePetType(String name)
{
return _activePetOwnerTypes.get(name);
} }
public Creature getActivePet(String name) public Creature getActivePet(String name)

View File

@ -0,0 +1,104 @@
package mineplex.core.pet;
import java.util.Optional;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import mineplex.core.pet.sales.PetSalesPackage;
public enum PetType
{
// These pets are named by EntityType for historic reasons -- the enum
// name() is stored by MSSQL to determine pet ownership. Future pet names
// can be made more accurate.
ZOMBIE("Pumpling", EntityType.ZOMBIE, -5), // Pumpling
PIG_ZOMBIE("Coal Apparition", EntityType.PIG_ZOMBIE, -1),
VILLAGER("Christmas Elf", EntityType.VILLAGER, -4),
PIG("Pig", EntityType.PIG, 5000),
SHEEP("Sheep", EntityType.SHEEP, 3000),
COW("Cow", EntityType.COW, 2000),
CHICKEN("Chicken", EntityType.CHICKEN, 7000),
WOLF("Dog", EntityType.WOLF, 8000),
OCELOT("Cat", EntityType.OCELOT, 6000),
MUSHROOM_COW("Mooshroom", EntityType.MUSHROOM_COW, 5000),
WITHER("Widder", EntityType.WITHER, -12),
SKELETON("Guardian", EntityType.SKELETON, -13),
RABBIT("Baby Zombie", EntityType.RABBIT, -9, "They're so cute - until a pack of them chases down your family and eats them."),
BLAZE("Grim Reaper", EntityType.BLAZE, -8, "Aww isn't he so cute with his little wings and little scythe?"),
// TODO CHECK IF LOBBY IS 1.9+
// Not in this update
//SHULKER("Shulker Pet", EntityType.BAT, 0, "Is it a turtle or an alien? Either way its shot can be really UPLIFTING.")
;
private final String _name;
private final EntityType _entityType;
private final int _price;
private final Optional<String> _lore;
private final Material _material;
private final byte _data;
PetType(String name, EntityType entityType, int price)
{
_name = name;
_entityType = entityType;
_price = price;
_lore = Optional.empty();
_material = Material.MONSTER_EGG;
_data = (byte) entityType.getTypeId();
}
PetType(String name, EntityType entityType, int price, String lore)
{
_name = name;
_entityType = entityType;
_price = price;
_lore = Optional.of(lore);
_material = Material.MONSTER_EGG;
_data = (byte) entityType.getTypeId();
}
PetType(String name, EntityType entityType, int price, String lore, Material material, byte data)
{
_name = name;
_entityType = entityType;
_price = price;
_lore = Optional.of(lore);
_material = material;
_data = data;
}
public String getName()
{
return _name;
}
public EntityType getEntityType()
{
return _entityType;
}
public int getPrice()
{
return _price;
}
public Optional<String> getLore()
{
return _lore;
}
public Material getMaterial()
{
return _material;
}
public byte getData()
{
return _data;
}
public PetSalesPackage toSalesPackage(String tagName)
{
return new PetSalesPackage(this, tagName);
}
}

View File

@ -2,19 +2,16 @@ package mineplex.core.pet.repository;
import java.util.List; import java.util.List;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import mineplex.serverdata.database.DBPool; import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.core.pet.repository.token.PetChangeToken; import mineplex.core.pet.repository.token.PetChangeToken;
import mineplex.core.pet.repository.token.PetExtraToken; import mineplex.core.pet.repository.token.PetExtraToken;
import mineplex.core.server.remotecall.AsyncJsonWebCall; import mineplex.core.server.remotecall.AsyncJsonWebCall;
import mineplex.core.server.remotecall.JsonWebCall; import mineplex.core.server.remotecall.JsonWebCall;
import mineplex.serverdata.database.DBPool;
public class PetRepository extends MinecraftRepository public class PetRepository extends MinecraftRepository
{ {
@ -30,37 +27,11 @@ public class PetRepository extends MinecraftRepository
public void AddPet(final PetChangeToken token) public void AddPet(final PetChangeToken token)
{ {
new AsyncJsonWebCall(_webAddress + "Pets/AddPet").Execute(token); new AsyncJsonWebCall(_webAddress + "Pets/AddPet").Execute(token);
getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
{
if (token.PetId == 0 || token.AccountId == 0)
return;
executeInsert("INSERT INTO accountPets(petName, petId, accountId) VALUES (?, ?, ?);", null, new ColumnVarChar("petName", 32, token.PetName)
, new ColumnInt("petId", token.PetId)
, new ColumnInt("accountId", token.AccountId));
}
});
} }
public void RemovePet(final PetChangeToken token) public void RemovePet(final PetChangeToken token)
{ {
new AsyncJsonWebCall(_webAddress + "Pets/RemovePet").Execute(token); new AsyncJsonWebCall(_webAddress + "Pets/RemovePet").Execute(token);
getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
{
if (token.PetId == 0 || token.AccountId == 0)
return;
executeUpdate("DELETE FROM accountPets WHERE petId = ? AND accountId = ?;"
, new ColumnInt("petId", token.PetId)
, new ColumnInt("accountId", token.AccountId));
}
});
} }
public List<PetExtraToken> GetPetExtras(List<PetExtraToken> petExtraTokens) public List<PetExtraToken> GetPetExtras(List<PetExtraToken> petExtraTokens)
@ -71,26 +42,6 @@ public class PetRepository extends MinecraftRepository
public void UpdatePet(final PetChangeToken token) public void UpdatePet(final PetChangeToken token)
{ {
new AsyncJsonWebCall(_webAddress + "Pets/UpdatePet").Execute(token); new AsyncJsonWebCall(_webAddress + "Pets/UpdatePet").Execute(token);
getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
{
if (token.PetId == 0 || token.AccountId == 0)
return;
int rowsChanged = executeUpdate("UPDATE accountPets SET petName = ? WHERE petId = ? AND accountId = ?;", new ColumnVarChar("petName", 32, token.PetName)
, new ColumnInt("petId", token.PetId)
, new ColumnInt("accountId", token.AccountId));
if (rowsChanged < 1)
{
executeInsert("INSERT INTO accountPets(petName, petId, accountId) VALUES (?, ?, ?);", null, new ColumnVarChar("petName", 32, token.PetName)
, new ColumnInt("petId", token.PetId)
, new ColumnInt("accountId", token.AccountId));
}
}
});
} }
@Override @Override

View File

@ -0,0 +1,19 @@
package mineplex.core.pet.sales;
import org.bukkit.Material;
import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.shop.item.SalesPackageBase;
public class PetExtraSalesPackage extends SalesPackageBase
{
public PetExtraSalesPackage(String name, Material material, int price)
{
super(name, material, (byte)0, new String[0]);
CurrencyCostMap.put(GlobalCurrency.TREASURE_SHARD, price);
KnownPackage = false;
OneTimePurchaseOnly = false;
}
}

View File

@ -0,0 +1,22 @@
package mineplex.core.pet.sales;
import org.bukkit.Material;
import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.util.C;
import mineplex.core.pet.PetType;
import mineplex.core.shop.item.SalesPackageBase;
public class PetSalesPackage extends SalesPackageBase
{
@SuppressWarnings("deprecation")
public PetSalesPackage(PetType type, String tagName)
{
super(type.getName(), Material.MONSTER_EGG, (byte)type.getEntityType().getTypeId(), new String[0]);
CurrencyCostMap.put(GlobalCurrency.TREASURE_SHARD, type.getPrice());
KnownPackage = false;
setDisplayName(C.cGreen + "Purchase " + tagName);
}
}

View File

@ -1,14 +0,0 @@
package mineplex.core.pet.types;
import org.bukkit.entity.EntityType;
import mineplex.core.pet.Pet;
public class Elf extends Pet
{
public Elf()
{
super("Christmas Elf", EntityType.VILLAGER, -4);
}
}

View File

@ -1,14 +0,0 @@
package mineplex.core.pet.types;
import org.bukkit.entity.EntityType;
import mineplex.core.pet.Pet;
public class PetCoalApparition extends Pet
{
public PetCoalApparition()
{
super("Coal Apparition", EntityType.PIG_ZOMBIE, -1);
}
}

View File

@ -1,13 +0,0 @@
package mineplex.core.pet.types;
import org.bukkit.entity.EntityType;
import mineplex.core.pet.Pet;
public class Pumpkin extends Pet
{
public Pumpkin()
{
super("Pumpling", EntityType.ZOMBIE, -5);
}
}

View File

@ -1,53 +1,40 @@
package mineplex.core.playwire; package mineplex.core.playwire;
import mineplex.core.common.util.UtilTime.TimeUnit;
/**
*
*/
public class PlayWireClientData public class PlayWireClientData
{ {
private int _accountId;
private int _ticketsRemaining;
private long _ticketRefresh;
private long _redeemTime; public PlayWireClientData(int accountId, int ticketsRemaining, long ticketRefresh)
private int _streak;
public PlayWireClientData(long date)
{ {
_redeemTime = date; _accountId = accountId;
long curr = System.currentTimeMillis(); _ticketsRemaining = ticketsRemaining;
_ticketRefresh = ticketRefresh;
if (_redeemTime <= 0)
{
_streak = 0;
}
} }
public long getRedeemTime() public int getAccountId()
{ {
return _redeemTime; return _accountId;
} }
public void setRedeemTime(long date) public int getTicketsRemaining()
{ {
long old = _redeemTime; return _ticketsRemaining;
_redeemTime = date;
if (_redeemTime - old > TimeUnit.DAYS.getMilliseconds() * 2)
{
_streak = 0;
} else
{
setStreak(getStreak() + 1);
}
} }
public int getStreak() public long getTicketRefresh()
{ {
return _streak; return _ticketRefresh;
} }
public void setStreak(int streak) public void setTicketsRemaining(int ticketsRemaining)
{ {
_streak = streak; _ticketsRemaining = ticketsRemaining;
}
public void setTicketRefresh(long ticketRefresh)
{
_ticketRefresh = ticketRefresh;
} }
} }

View File

@ -4,10 +4,13 @@ import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.Managers; import mineplex.core.Managers;
@ -16,72 +19,100 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.BonusManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.donation.DonationManager; import mineplex.core.updater.UpdateType;
import mineplex.core.inventory.InventoryManager; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.treasure.TreasureType;
import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DBPool;
/**
*
*/
public class PlayWireManager extends MiniDbClientPlugin<PlayWireClientData> public class PlayWireManager extends MiniDbClientPlugin<PlayWireClientData>
{ {
private static final int MAX_TICKETS_PER_PERIOD = 5;
private final long COOL_DOWN = TimeUnit.HOURS.getMilliseconds(); private final long COOL_DOWN = TimeUnit.HOURS.getMilliseconds() * 24;
private static final int REWARD_MESSAGE_DELAY_SECONDS = 10; private static final int REWARD_MESSAGE_DELAY_SECONDS = 10;
private final CoreClientManager _clientManager; private final CoreClientManager _clientManager;
private final DonationManager _donationManager;
private final PlayWireRepository _repository; private final PlayWireRepository _repository;
public PlayWireManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) public PlayWireManager(JavaPlugin plugin, CoreClientManager clientManager)
{ {
super("PlayWire", plugin, clientManager); super("PlayWire", plugin, clientManager);
_clientManager = clientManager; _clientManager = clientManager;
_donationManager = donationManager;
_repository = new PlayWireRepository(this); _repository = new PlayWireRepository(this);
getPlugin().getCommand("playwire").setExecutor(new PlayWireCommand(this)); getPlugin().getCommand("playwire").setExecutor(new PlayWireCommand(this));
} }
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
{
return;
}
final Map<PlayWireClientData, Player> update = new HashMap<>();
Bukkit.getOnlinePlayers().stream().filter(player -> Get(player) != null && Get(player).getAccountId() != -1 && Get(player).getTicketRefresh() != -1 && Get(player).getTicketRefresh() < System.currentTimeMillis()).forEach(player ->
{
PlayWireClientData data = Get(player);
data.setTicketRefresh(-1);
data.setTicketsRemaining(MAX_TICKETS_PER_PERIOD);
update.put(data, player);
});
if (!update.isEmpty())
{
runAsync(() ->
{
update.entrySet().forEach(entry ->
{
PlayWireClientData data = entry.getKey();
_repository.attemptPlayWire(data, () ->
{
UtilPlayer.message(entry.getValue(), F.main("Carl", "Your Ad Ticketssssss have refresssshed! Come ssssee me for ssssome " + F.elem("Spin Tickets") + "!"));
}, false);
});
update.clear();
});
}
}
@Override @Override
public String getQuery(int accountId, String uuid, String name) public String getQuery(int accountId, String uuid, String name)
{ {
return "SELECT `redeemed`, `streak` FROM `play_wire` WHERE `accountId`=" + accountId + ";"; return "SELECT ticketsRemaining, ticketRefresh FROM play_wire WHERE accountId=" + accountId + ";";
} }
public boolean canRedeem(Player player) public boolean canRedeemTickets(PlayWireClientData data)
{ {
PlayWireClientData data = Get(player);
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
return data == null || data.getRedeemTime() == -1 || (now - data.getRedeemTime()) > COOL_DOWN; return data == null || (data.getTicketRefresh() < now || data.getTicketRefresh() == -1) || data.getTicketsRemaining() > 0;
} }
public void attemptRedeem(Player player) public void attemptRedeem(Player player)
{ {
if (!canRedeem(player)) final PlayWireClientData client = Get(player);
if (client == null || client.getAccountId() == -1)
{ {
player.sendMessage(ResponseType.UNCOUNTED.getMessage()); player.sendMessage(ResponseType.UNFILLED.getMessage());
return;
}
if (!canRedeemTickets(client))
{
player.sendMessage(ResponseType.UNCOUNTED.getMessage(UtilTime.MakeStr(client.getTicketRefresh() - System.currentTimeMillis())));
return; return;
} }
PlayWireClientData client = Get(player); if (client.getTicketsRemaining() >= MAX_TICKETS_PER_PERIOD)
client.setRedeemTime(System.currentTimeMillis());
if(client.getStreak() == 7)
{ {
// client.setTicketRefresh(System.currentTimeMillis() + COOL_DOWN);
Managers.get(InventoryManager.class).addItemToInventory(player, TreasureType.ANCIENT.getItemName(), 1);
} else if(client.getStreak() == 14)
{
Managers.get(InventoryManager.class).addItemToInventory(player, TreasureType.ANCIENT.getItemName(), 1);
client.setStreak(0);
} }
client.setTicketsRemaining(Math.max(client.getTicketsRemaining() - 1, 0));
_repository.attemptPlayWire(player, client, () -> _repository.attemptPlayWireAsync(client, () ->
{ {
_donationManager.RewardCoinsLater("Watching Ad", player, 100);
final int accountId = _clientManager.Get(player).getAccountId(); final int accountId = _clientManager.Get(player).getAccountId();
final Callback<Integer> ticketCallback = new Callback<Integer>() final Callback<Integer> ticketCallback = new Callback<Integer>()
{ {
@ -118,7 +149,7 @@ public class PlayWireManager extends MiniDbClientPlugin<PlayWireClientData>
} }
}); });
Managers.get(BonusManager.class).addPendingExplosion(player, player.getName()); Managers.get(BonusManager.class).addPendingExplosion(player, player.getName());
Bukkit.getScheduler().runTaskLater(getClientManager().getPlugin(), () -> UtilPlayer.message(player, ResponseType.COUNTED.getMessage()), REWARD_MESSAGE_DELAY_SECONDS * 20L); Bukkit.getScheduler().runTaskLater(getClientManager().getPlugin(), () -> UtilPlayer.message(player, ResponseType.COUNTED.getMessage(client.getTicketsRemaining() + "")), REWARD_MESSAGE_DELAY_SECONDS * 20L);
}); });
} }
@ -136,6 +167,11 @@ public class PlayWireManager extends MiniDbClientPlugin<PlayWireClientData>
return; return;
} }
if (response == ResponseType.UNCOUNTED)
{
response = ResponseType.UNFILLED;
}
if (response == ResponseType.COUNTED) if (response == ResponseType.COUNTED)
{ {
attemptRedeem(player); attemptRedeem(player);
@ -151,18 +187,20 @@ public class PlayWireManager extends MiniDbClientPlugin<PlayWireClientData>
boolean hasRow = resultSet.next(); boolean hasRow = resultSet.next();
if (hasRow) if (hasRow)
{ {
PlayWireClientData client = new PlayWireClientData(resultSet.getLong(1)); PlayWireClientData client = new PlayWireClientData(accountId, resultSet.getInt("ticketsRemaining"), resultSet.getLong("ticketRefresh"));
client.setStreak(resultSet.getInt(2));
Set(uuid, client); Set(uuid, client);
} else }
else
{ {
Set(uuid, new PlayWireClientData(-1)); PlayWireClientData client = new PlayWireClientData(accountId, MAX_TICKETS_PER_PERIOD, -1L);
Set(uuid, client);
_repository.attemptPlayWire(client, null, false);
} }
} }
@Override @Override
protected PlayWireClientData addPlayer(UUID uuid) protected PlayWireClientData addPlayer(UUID uuid)
{ {
return new PlayWireClientData(-1); return new PlayWireClientData(-1, -1, -1);
} }
} }

View File

@ -1,20 +1,14 @@
package mineplex.core.playwire; package mineplex.core.playwire;
import mineplex.serverdata.database.DBPool;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
/** import mineplex.serverdata.database.DBPool;
* Totally original code I wrote, did not copy it from YouTubeRepo, no sir.
*/
public class PlayWireRepository public class PlayWireRepository
{ {
private static final String INSERT_LAST_REDEEMED = "INSERT INTO play_wire (accountId, ticketsRemaining, ticketRefresh) VALUES (?,?,?) ON DUPLICATE KEY UPDATE ticketsRemaining=VALUES(ticketsRemaining), ticketRefresh=VALUES(ticketRefresh)";
private static final String INSERT_LAST_REDEEMED = "INSERT INTO `play_wire` VALUES(?,?,?) ON DUPLICATE KEY UPDATE `redeemed` = ?, `streak` = ?";
private final PlayWireManager _manager; private final PlayWireManager _manager;
@ -23,30 +17,45 @@ public class PlayWireRepository
_manager = manager; _manager = manager;
} }
public void attemptPlayWire(Player player, PlayWireClientData client, Runnable runnable) public void attemptPlayWire(final PlayWireClientData client, final Runnable runnable, boolean forceAsync)
{ {
int accountId = _manager.getClientManager().Get(player).getAccountId(); if (client.getAccountId() == -1)
{
Bukkit.getScheduler().runTaskAsynchronously(_manager.getPlugin(), () -> return;
}
Runnable doSQL = () ->
{ {
try (Connection connection = DBPool.getAccount().getConnection()) try (Connection connection = DBPool.getAccount().getConnection())
{ {
PreparedStatement statement = connection.prepareStatement(INSERT_LAST_REDEEMED); PreparedStatement statement = connection.prepareStatement(INSERT_LAST_REDEEMED);
statement.setInt(1, accountId); statement.setInt(1, client.getAccountId());
statement.setLong(2, client.getRedeemTime()); statement.setInt(2, client.getTicketsRemaining());
statement.setInt(3, client.getStreak()); statement.setLong(3, client.getTicketRefresh());
statement.setLong(4, client.getRedeemTime());
statement.setInt(5, client.getStreak());
statement.executeUpdate(); statement.executeUpdate();
runnable.run(); if (runnable != null)
} catch (SQLException e) {
_manager.runSync(runnable);
}
}
catch (SQLException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
}); };
if (forceAsync)
{
_manager.runAsync(doSQL);
}
else
{
doSQL.run();
}
} }
public void attemptPlayWireAsync(final PlayWireClientData client, final Runnable runnable)
{
attemptPlayWire(client, runnable, false);
}
} }

View File

@ -7,11 +7,10 @@ import mineplex.core.common.util.F;
*/ */
public enum ResponseType public enum ResponseType
{ {
COUNTED(F.main("Carl", "Rewarded " + F.elem("1 Carl Spin Ticket") + " for watching the Ad! You have " + F.elem("%elem%") + " tickets remaining for the current 24 hour period!")),
COUNTED(F.main("Carl", "Rewarded " + F.elem("100 Treasure Shards") + " and " + F.elem("1 Carl Spin Ticket") + " for watching the Ad")), UNCOUNTED(F.main("Carl", "You already received your " + F.elem("5 Carl Spin Tickets") + " for the current 24 hour period! Your available tickets will refresh in " + F.elem("%elem%") + "!")),
UNCOUNTED(F.main("Carl", "You already watched the Ad within the past hour!")),
BLOCKED(F.main("Carl", "You have an AdBlocker on, but tried to watch the Ad! Ssssssslight problem there!")), BLOCKED(F.main("Carl", "You have an AdBlocker on, but tried to watch the Ad! Ssssssslight problem there!")),
UNFILLED(F.main("Carl", "Ssssomething went wrong with the Ad, we'll get it sorted ASAP.")),; UNFILLED(F.main("Carl", "Ssssomething went wrong with the Ad, we'll get it ssssorted ASAP. Try again in a few minutessss!")),;
private String _message; private String _message;
@ -20,9 +19,16 @@ public enum ResponseType
_message = message; _message = message;
} }
public String getMessage() public String getMessage(String... elements)
{ {
return _message; String message = _message;
if (elements.length > 0)
{
for (int i = 0; i < elements.length; i++)
{
message = message.replaceFirst("%elem%", elements[i]);
}
}
return message;
} }
} }

View File

@ -1,9 +1,22 @@
package mineplex.core.powerplayclub; package mineplex.core.powerplayclub;
import mineplex.core.account.CoreClientManager; import java.sql.Connection;
import mineplex.core.account.ILoginProcessor; import java.sql.Date;
import mineplex.core.donation.DonationManager; import java.sql.PreparedStatement;
import mineplex.serverdata.database.DBPool; import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -12,13 +25,10 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.sql.*; import mineplex.core.account.CoreClientManager;
import java.sql.Date; import mineplex.core.account.ILoginProcessor;
import java.time.LocalDate; import mineplex.core.donation.DonationManager;
import java.time.YearMonth; import mineplex.serverdata.database.DBPool;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
public class PowerPlayClubRepository implements Listener { public class PowerPlayClubRepository implements Listener {
// Data loaded by the first ILoginProcessor, waiting for the second // Data loaded by the first ILoginProcessor, waiting for the second
@ -29,6 +39,8 @@ public class PowerPlayClubRepository implements Listener {
// giving a player his/her rewards. // giving a player his/her rewards.
private final Map<UUID, PowerPlayData> _cachedPlayerData = new HashMap<>(); private final Map<UUID, PowerPlayData> _cachedPlayerData = new HashMap<>();
private final Set<UUID> _yearlySubscriptions = new HashSet<>();
private final CoreClientManager _clientManager; private final CoreClientManager _clientManager;
private final DonationManager _donationManager; private final DonationManager _donationManager;
@ -74,6 +86,10 @@ public class PowerPlayClubRepository implements Listener {
LocalDate date = resultSet.getDate("startDate").toLocalDate(); LocalDate date = resultSet.getDate("startDate").toLocalDate();
PowerPlayData.SubscriptionDuration duration = PowerPlayData.SubscriptionDuration.valueOf(resultSet.getString("duration").toUpperCase()); PowerPlayData.SubscriptionDuration duration = PowerPlayData.SubscriptionDuration.valueOf(resultSet.getString("duration").toUpperCase());
subscriptions.add(new PowerPlayData.Subscription(date, duration)); subscriptions.add(new PowerPlayData.Subscription(date, duration));
if (duration.equals(PowerPlayData.SubscriptionDuration.YEAR))
{
_yearlySubscriptions.add(uuid);
}
} }
// Now that we have the claims from the first processor and subscriptions from this one, combine them // Now that we have the claims from the first processor and subscriptions from this one, combine them
@ -97,6 +113,9 @@ public class PowerPlayClubRepository implements Listener {
PowerPlayClubRewards.rewardsForMonths(cached.getUsableCosmeticMonths()).stream() PowerPlayClubRewards.rewardsForMonths(cached.getUsableCosmeticMonths()).stream()
.map(PowerPlayClubRewards.PowerPlayClubItem::getPrize) .map(PowerPlayClubRewards.PowerPlayClubItem::getPrize)
.forEach(_donationManager.Get(player)::AddUnknownSalesPackagesOwned); .forEach(_donationManager.Get(player)::AddUnknownSalesPackagesOwned);
// Gives Metal Man for anyone subscribed
_donationManager.Get(player).AddUnknownSalesPackagesOwned("Metal Man Morph");
} }
@EventHandler @EventHandler
@ -104,6 +123,7 @@ public class PowerPlayClubRepository implements Listener {
{ {
_stageOneDataClaims.remove(event.getPlayer().getUniqueId()); // Just in case. _stageOneDataClaims.remove(event.getPlayer().getUniqueId()); // Just in case.
_cachedPlayerData.remove(event.getPlayer().getUniqueId()); _cachedPlayerData.remove(event.getPlayer().getUniqueId());
_yearlySubscriptions.remove(event.getPlayer().getUniqueId());
} }
public CompletableFuture<Void> addSubscription(int accountId, LocalDate date, String duration) public CompletableFuture<Void> addSubscription(int accountId, LocalDate date, String duration)

View File

@ -65,7 +65,8 @@ public class PreferencesManager extends MiniPlugin implements ILoginProcessor
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
int accountId = _clientManager.getAccountId(player); int accountId = _clientManager.getAccountId(player);
_repository.saveUserPreferences(_preferences.remove(accountId)); UserPreferences p = _preferences.remove(accountId);
if (p != null) _repository.saveUserPreferences(p);
} }
@EventHandler @EventHandler

View File

@ -0,0 +1,26 @@
package mineplex.core.punish.Command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.punish.Punish;
public class RulesCommand extends CommandBase<Punish>
{
private static final String RULES_MESSAGE = "The rules can be found here:" + C.cGreen + " www.mineplex.com/rules";
public RulesCommand(Punish plugin)
{
super(plugin, Rank.ALL, "rules");
}
@Override
public void Execute(Player caller, String[] args)
{
caller.sendMessage(F.main("Rules", RULES_MESSAGE));
}
}

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