Merge branch 'project-cosmetics' into develop

This commit is contained in:
cnr 2016-06-23 18:42:47 -05:00
commit 3433e0e3bc
299 changed files with 12522 additions and 8874 deletions

View File

@ -256,33 +256,36 @@ public class MapUtil
@SuppressWarnings({ "rawtypes" }) @SuppressWarnings({ "rawtypes" })
public static boolean ClearWorldReferences(String worldName) public static boolean ClearWorldReferences(String worldName)
{ {
HashMap regionfiles = (HashMap) RegionFileCache.a; synchronized (RegionFileCache.class)
try
{ {
for (Iterator<Object> iterator = regionfiles.entrySet().iterator(); iterator.hasNext();) HashMap regionfiles = (HashMap) RegionFileCache.a;
{
Map.Entry e = (Map.Entry) iterator.next();
RegionFile file = (RegionFile) e.getValue();
try try
{
for (Iterator<Object> iterator = regionfiles.entrySet().iterator(); iterator.hasNext(); )
{ {
file.c(); Map.Entry e = (Map.Entry) iterator.next();
iterator.remove(); RegionFile file = (RegionFile) e.getValue();
}
catch (Exception ex) try
{ {
ex.printStackTrace(); file.c();
iterator.remove();
}
catch (Exception ex)
{
ex.printStackTrace();
}
} }
} }
} catch (Exception ex)
catch (Exception ex) {
{ System.out.println("Exception while removing world reference for '" + worldName + "'!");
System.out.println("Exception while removing world reference for '" + worldName + "'!"); ex.printStackTrace();
ex.printStackTrace(); }
}
return true; return true;
}
} }
public static BlockPosition getBlockPos(int x, int y, int z) public static BlockPosition getBlockPos(int x, int y, int z)

View File

@ -11,6 +11,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -112,7 +113,7 @@ public class UtilServer
public static Plugin getPlugin() public static Plugin getPlugin()
{ {
return getPluginManager().getPlugins()[0]; return JavaPlugin.getProvidingPlugin(UtilServer.class);
} }
public static PluginManager getPluginManager() public static PluginManager getPluginManager()

View File

@ -33,6 +33,11 @@ public class UtilWorld
return chunkToStr(chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); return chunkToStr(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
} }
public static String chunkToStr(Location location)
{
return chunkToStr(location.getWorld().getName(), location.getBlockX() >> 4, location.getBlockZ() >> 4);
}
public static String chunkToStr(String world, int x, int z) public static String chunkToStr(String world, int x, int z)
{ {
return world + "," + x + "," + z; return world + "," + x + "," + z;

View File

@ -1,57 +1,59 @@
package mineplex.core.common.weight; package mineplex.core.common.weight;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
public class WeightSet<T> public class WeightSet<T>
{ {
private static Random random = new Random(); private static Random random = new Random();
private Set<Weight<T>> _weights; private Set<Weight<T>> _weights = new HashSet<Weight<T>>();
private volatile transient Set<T> _keyset;
public WeightSet() public WeightSet()
{ {
_weights = new HashSet<Weight<T>>();
} }
@SafeVarargs @SafeVarargs
public WeightSet(Weight<T>... weights) public WeightSet(Weight<T>... weights)
{ {
this();
for (Weight<T> weight : weights) for (Weight<T> weight : weights)
{ {
_weights.add(weight); _weights.add(weight);
} }
computeKeyset();
} }
@SafeVarargs @SafeVarargs
public WeightSet(T... elements) public WeightSet(T... elements)
{ {
this();
for (T element : elements) for (T element : elements)
{ {
_weights.add(new Weight<T>(1, element)); // Constant weight of 1 means all elements are equally likely _weights.add(new Weight<T>(1, element)); // Constant weight of 1 means all elements are equally likely
} }
computeKeyset();
} }
public WeightSet(Collection<T> elements) public WeightSet(Collection<T> elements)
{ {
this();
for (T element : elements) for (T element : elements)
{ {
_weights.add(new Weight<T>(1, element)); // Constant weight of 1 means all elements are equally likely _weights.add(new Weight<T>(1, element)); // Constant weight of 1 means all elements are equally likely
} }
computeKeyset();
} }
public void add(int weight, T element) public void add(int weight, T element)
{ {
_weights.add(new Weight<T>(weight, element)); _weights.add(new Weight<T>(weight, element));
computeKeyset();
} }
private int getTotalWeight() private int getTotalWeight()
@ -87,13 +89,11 @@ public class WeightSet<T>
public Set<T> elements() public Set<T> elements()
{ {
Set<T> elements = new HashSet<T>(); return this._keyset;
}
for (Weight<T> weight : _weights)
{ private void computeKeyset()
elements.add(weight.getValue()); {
} _keyset = Collections.unmodifiableSet(_weights.stream().map(Weight::getValue).collect(Collectors.toSet()));
return elements;
} }
} }

View File

@ -12,6 +12,7 @@ import mineplex.core.hologram.HologramManager;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.Region;
import mineplex.serverdata.redis.counter.Counter; import mineplex.serverdata.redis.counter.Counter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -24,6 +25,8 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
/** /**
* @author Shaun Bennett * @author Shaun Bennett
*/ */
@ -47,8 +50,10 @@ public class FountainManager extends MiniPlugin
_brawlShopProvider = shopProvider; _brawlShopProvider = shopProvider;
World world = Bukkit.getWorlds().get(0);//-43.5, 66, -38.5 World world = Bukkit.getWorlds().get(0);//-43.5, 66, -38.5
int goal = !new File("eu.dat").exists() ? 300000000 : 5000000;
_gemFountain = new Fountain(new Location(world, -32.5, 72, -23.5), new Location(world, -43.5, 67, -38.5), _gemFountain = new Fountain(new Location(world, -32.5, 72, -23.5), new Location(world, -43.5, 67, -38.5),
C.cGreen + "Gem Fountain", "GemFountain_01", 10000000, this, clientManager, donationManager, _hologramManager, _statsManager); C.cGreen + "Gem Fountain", "GemFountain_01", goal, this, clientManager, donationManager, _hologramManager, _statsManager);
} }
@Override @Override

View File

@ -20,7 +20,7 @@ public class GemFountainSalesPackage extends SalesPackageBase
} }
@Override @Override
public void Sold(Player player, CurrencyType currencyType) public void sold(Player player, CurrencyType currencyType)
{ {
} }

View File

@ -22,6 +22,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -59,7 +60,7 @@ public class Chat extends MiniPlugin
private PreferencesManager _preferences; private PreferencesManager _preferences;
private AchievementManager _achievements; private AchievementManager _achievements;
private IncognitoManager _incognitoManager; private IncognitoManager _incognitoManager;
private String[] _hackusations = {"hack", "hax", "hacker", "hacking", "cheat", "cheater", "cheating", "forcefield", "flyhack", "flyhacking", "autoclick", "aimbot"}; private String[] _hackusations = {"hack", "hax", "hacker", "hacking", "cheat", "cheater", "cheating", "forcefield", "flyhack", "flyhacking", "autoclick", "aimbot"};
private String _filterUrl = "https://chat.mineplex.com:8003/content/item/moderate"; private String _filterUrl = "https://chat.mineplex.com:8003/content/item/moderate";
private String _appId = "34018d65-466d-4a91-8e92-29ca49f022c4"; private String _appId = "34018d65-466d-4a91-8e92-29ca49f022c4";
@ -69,22 +70,22 @@ public class Chat extends MiniPlugin
private int _chatSlow = 0; private int _chatSlow = 0;
private long _silenced = 0; private long _silenced = 0;
private boolean _threeSecondDelay = true; private boolean _threeSecondDelay = true;
private List<Function<AsyncPlayerChatEvent, Boolean>> _highPriorityFilters = new ArrayList<>(); private List<Function<AsyncPlayerChatEvent, Boolean>> _highPriorityFilters = new ArrayList<>();
private List<Function<AsyncPlayerChatEvent, Boolean>> _lowPriorityFilters = new ArrayList<>(); private List<Function<AsyncPlayerChatEvent, Boolean>> _lowPriorityFilters = new ArrayList<>();
private HashMap<UUID, MessageData> _playerLastMessage = new HashMap<UUID, MessageData>(); private HashMap<UUID, MessageData> _playerLastMessage = new HashMap<UUID, MessageData>();
public Chat(JavaPlugin plugin, IncognitoManager incognitoManager, CoreClientManager clientManager, PreferencesManager preferences, AchievementManager achievements, String serverName) public Chat(JavaPlugin plugin, IncognitoManager incognitoManager, CoreClientManager clientManager, PreferencesManager preferences, AchievementManager achievements, String serverName)
{ {
super("Chat", plugin); super("Chat", plugin);
_incognitoManager = incognitoManager; _incognitoManager = incognitoManager;
_clientManager = clientManager; _clientManager = clientManager;
_serverName = serverName; _serverName = serverName;
_preferences = preferences; _preferences = preferences;
_achievements = achievements; _achievements = achievements;
try try
{ {
trustCert(); trustCert();
@ -207,7 +208,7 @@ public class Chat extends MiniPlugin
{ {
if (event.isCancelled()) if (event.isCancelled())
return; return;
if (event.isAsynchronous()) if (event.isAsynchronous())
{ {
for (Iterator<Player> playerIterator = event.getRecipients().iterator(); playerIterator.hasNext();) for (Iterator<Player> playerIterator = event.getRecipients().iterator(); playerIterator.hasNext();)
@ -230,24 +231,41 @@ public class Chat extends MiniPlugin
return; return;
} }
for (int i = 0; i < event.getLines().length; i++) String[] lines = event.getLines();
runAsync(() ->
{ {
String line = event.getLine(i); for (int i = 0; i < lines.length; i++)
if (line != null && line.length() > 0)
{ {
String filteredLine = getFilteredMessage(event.getPlayer(), line); String line = lines[i];
if (filteredLine != null) if (line != null && line.length() > 0)
event.setLine(i, filteredLine); {
String filteredLine = getFilteredMessage(event.getPlayer(), line);
if (filteredLine != null)
{
lines[i] = filteredLine;
}
}
} }
}
runSync(() ->
{
Sign sign = (Sign) event.getBlock().getState();
for (int i = 0; i < lines.length; i++)
{
sign.setLine(i, lines[i]);
}
sign.update();
});
});
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void filterChat(AsyncPlayerChatEvent event) public void filterChat(AsyncPlayerChatEvent event)
{ {
if (event.isCancelled()) if (event.isCancelled())
return; return;
if (event.isAsynchronous()) if (event.isAsynchronous())
{ {
event.setMessage(getFilteredMessage(event.getPlayer(), event.getMessage())); event.setMessage(getFilteredMessage(event.getPlayer(), event.getMessage()));
@ -266,7 +284,7 @@ public class Chat extends MiniPlugin
JSONObject message = buildJsonChatObject(filterType, displayName, playerName, originalMessage, _serverName, 1); JSONObject message = buildJsonChatObject(filterType, displayName, playerName, originalMessage, _serverName, 1);
String response = getResponseFromCleanSpeak(message, filterType); String response = getResponseFromCleanSpeak(message, filterType);
if (response == null) if (response == null)
{ {
System.out.println("[ERROR] Unable to filter chat message...thanks a lot CleanSpeak."); System.out.println("[ERROR] Unable to filter chat message...thanks a lot CleanSpeak.");
@ -284,7 +302,7 @@ public class Chat extends MiniPlugin
System.out.println(o.toString()); System.out.println(o.toString());
} }
*/ */
String filteredMsg = ""; String filteredMsg = "";
filteredMsg = ((JSONObject) JSONValue.parse(response)).get("content").toString(); filteredMsg = ((JSONObject) JSONValue.parse(response)).get("content").toString();
@ -293,7 +311,7 @@ public class Chat extends MiniPlugin
filteredMsg = ((JSONObject) JSONValue.parse(filteredMsg)).get("parts").toString(); filteredMsg = ((JSONObject) JSONValue.parse(filteredMsg)).get("parts").toString();
filteredMsg = filteredMsg.replace('[', ' ').replace(']', ' ').trim(); filteredMsg = filteredMsg.replace('[', ' ').replace(']', ' ').trim();
filteredMsg = ((JSONObject) JSONValue.parse(filteredMsg)).get("replacement").toString(); filteredMsg = ((JSONObject) JSONValue.parse(filteredMsg)).get("replacement").toString();
return filteredMsg; return filteredMsg;
} }
else else
@ -301,7 +319,7 @@ public class Chat extends MiniPlugin
return originalMessage; return originalMessage;
} }
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void HandleChat(AsyncPlayerChatEvent event) public void HandleChat(AsyncPlayerChatEvent event)
{ {
@ -309,14 +327,14 @@ public class Chat extends MiniPlugin
return; return;
Player sender = event.getPlayer(); Player sender = event.getPlayer();
if (_incognitoManager != null && _incognitoManager.Get(sender).Status) if (_incognitoManager != null && _incognitoManager.Get(sender).Status)
{ {
UtilPlayer.message(sender, C.cYellow + "You can not chat while incognito."); UtilPlayer.message(sender, C.cYellow + "You can not chat while incognito.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
for (Function<AsyncPlayerChatEvent, Boolean> filter : _highPriorityFilters) for (Function<AsyncPlayerChatEvent, Boolean> filter : _highPriorityFilters)
{ {
if (filter.apply(event).booleanValue()) if (filter.apply(event).booleanValue())
@ -325,7 +343,7 @@ public class Chat extends MiniPlugin
return; return;
} }
} }
if (SilenceCheck(sender)) if (SilenceCheck(sender))
{ {
event.setCancelled(true); event.setCancelled(true);
@ -349,7 +367,7 @@ public class Chat extends MiniPlugin
else if (!_clientManager.Get(sender).GetRank().has(Rank.HELPER) && else if (!_clientManager.Get(sender).GetRank().has(Rank.HELPER) &&
msgContainsHack(event.getMessage())) msgContainsHack(event.getMessage()))
{ {
UtilPlayer.message(sender, F.main("Chat", UtilPlayer.message(sender, F.main("Chat",
"Accusing players of cheating in-game is against the rules." "Accusing players of cheating in-game is against the rules."
+ "If you think someone is cheating, please gather evidence and report it at " + "If you think someone is cheating, please gather evidence and report it at "
+ F.link("www.mineplex.com/reports"))); + F.link("www.mineplex.com/reports")));
@ -372,10 +390,10 @@ public class Chat extends MiniPlugin
event.setCancelled(true); event.setCancelled(true);
} }
} }
if (!event.isCancelled()) if (!event.isCancelled())
_playerLastMessage.put(sender.getUniqueId(), new MessageData(event.getMessage())); _playerLastMessage.put(sender.getUniqueId(), new MessageData(event.getMessage()));
for (Function<AsyncPlayerChatEvent, Boolean> filter : _lowPriorityFilters) for (Function<AsyncPlayerChatEvent, Boolean> filter : _lowPriorityFilters)
{ {
if (filter.apply(event).booleanValue()) if (filter.apply(event).booleanValue())
@ -442,17 +460,17 @@ public class Chat extends MiniPlugin
JSONObject content = new JSONObject(); JSONObject content = new JSONObject();
content.put("content", msg); content.put("content", msg);
content.put("type", "text"); content.put("type", "text");
JSONArray parts = new JSONArray(); JSONArray parts = new JSONArray();
parts.add(content); parts.add(content);
JSONObject mainContent = new JSONObject(); JSONObject mainContent = new JSONObject();
mainContent.put("applicationId", _appId); mainContent.put("applicationId", _appId);
mainContent.put("createInstant", System.currentTimeMillis()); mainContent.put("createInstant", System.currentTimeMillis());
mainContent.put("parts", parts); mainContent.put("parts", parts);
mainContent.put("senderDisplayName", name); mainContent.put("senderDisplayName", name);
mainContent.put("senderId", player); mainContent.put("senderId", player);
message.put("content", mainContent); message.put("content", mainContent);
break; break;
case "username": case "username":
@ -558,7 +576,7 @@ public class Chat extends MiniPlugin
e.printStackTrace(); e.printStackTrace();
} }
} }
if (inputStream != null) if (inputStream != null)
{ {
try try
@ -573,10 +591,10 @@ public class Chat extends MiniPlugin
} }
String pmresponse = null; String pmresponse = null;
if (response != null) if (response != null)
pmresponse = response.toString(); pmresponse = response.toString();
return pmresponse; return pmresponse;
} }
@ -627,18 +645,18 @@ public class Chat extends MiniPlugin
_playerLastMessage.remove(event.getPlayer().getUniqueId()); _playerLastMessage.remove(event.getPlayer().getUniqueId());
} }
public void setThreeSecondDelay(boolean b) public void setThreeSecondDelay(boolean b)
{ {
_threeSecondDelay = b; _threeSecondDelay = b;
} }
/** /**
* If the function returns Boolean.TRUE then the message will be CANCELLED. * If the function returns Boolean.TRUE then the message will be CANCELLED.
*/ */
public void AddFilter(Function<AsyncPlayerChatEvent, Boolean> restriction, FilterPriority priority) public void AddFilter(Function<AsyncPlayerChatEvent, Boolean> restriction, FilterPriority priority)
{ {
Validate.isTrue(priority != null, "Priority must not be null."); Validate.isTrue(priority != null, "Priority must not be null.");
switch (priority) switch (priority)
{ {
case HIGH: case HIGH:
@ -648,5 +666,5 @@ public class Chat extends MiniPlugin
_lowPriorityFilters.add(restriction); _lowPriorityFilters.add(restriction);
} }
} }
} }

View File

@ -36,6 +36,17 @@ public abstract class MultiCommandBase<PluginType extends MiniPlugin> extends Co
command.SetCommandCenter(_commandCenter); command.SetCommandCenter(_commandCenter);
} }
} }
@Override
public void SetCommandCenter(CommandCenter commandCenter)
{
super.SetCommandCenter(commandCenter);
for (ICommand iCommand : Commands.values())
{
iCommand.SetCommandCenter(commandCenter);
}
}
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
{ {

View File

@ -0,0 +1,50 @@
package mineplex.core.progression;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.progression.data.PlayerKit;
import mineplex.core.progression.data.PlayerKitDataManager;
import mineplex.core.progression.gui.MenuListener;
import org.bukkit.plugin.java.JavaPlugin;
/**
* The main class, process logins and loads data.
*/
public class KitProgressionManager extends MiniClientPlugin<PlayerKit>
{
private PlayerKitDataManager _dataManager;
private KitProgressionRepository _kitProgressionRepository;
private CoreClientManager _coreClientManager;
public KitProgressionManager(JavaPlugin plugin, CoreClientManager clientManager)
{
super("Kit Progression", plugin);
_dataManager = new PlayerKitDataManager();
_kitProgressionRepository = new KitProgressionRepository(this);
_coreClientManager = clientManager;
getPlugin().getServer().getPluginManager().registerEvents(new MenuListener(), getPlugin());
}
public CoreClientManager getClientManager()
{
return _coreClientManager;
}
@Override
protected PlayerKit AddPlayer(String player)
{
return null;
}
public PlayerKitDataManager getDataManager()
{
return _dataManager;
}
public KitProgressionRepository getRepository()
{
return _kitProgressionRepository;
}
}

View File

@ -0,0 +1,220 @@
package mineplex.core.progression;
import mineplex.core.database.MinecraftRepository;
import mineplex.core.progression.data.PlayerKit;
import mineplex.core.progression.util.SQLStatement;
import mineplex.serverdata.database.DBPool;
import org.bukkit.Bukkit;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
/**
* Handles all things database related.
*/
public class KitProgressionRepository extends MinecraftRepository
{
private final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS `kitProgression` (" +
"`uuid` VARCHAR(36), " +
"`kitId` VARCHAR(64), " +
"`level` INT, " +
"`xp` INT, " +
"`upgrade_level` INT, " +
"`default` TINYINT, PRIMARY KEY(uuid, kitId))";
private final String INSERT_OR_UPDATE = "INSERT INTO `kitProgression` VALUES(?,?,?,?,?,?) ON DUPLICATE KEY UPDATE " +
"`level` = ?, `xp` = ?, `upgrade_level` = ?, `default` = ?";
private final String QUERY_KITS = "SELECT * FROM `kitProgression` WHERE `uuid` = ?;";
private KitProgressionManager _kitProgressionManager;
public KitProgressionRepository(KitProgressionManager plugin)
{
super(plugin.getPlugin(), DBPool.getAccount());
_kitProgressionManager = plugin;
}
@Override
protected void initialize()
{
}
@Override
protected void update()
{
}
/**
* Inserts data for a kit into the database
* This will update the info if the kit is already in there
*
* @param playerKit The reference to the Player Kit
* @param kit The kit's INTERNAL name
*/
public void insertOrUpdate(PlayerKit playerKit, String kit)
{
async(() -> {
int level = playerKit.getLevel(kit);
int upgradeLevel = playerKit.getUpgradeLevel(kit);
int xp = playerKit.getXp(kit);
int defaultType = playerKit.isDefault(kit) ? 1 : 0;
Connection connection = getConnection();
try
{
PreparedStatement statement = new SQLStatement(INSERT_OR_UPDATE)
.set(1, playerKit.getUuid())
.set(2, kit)
.set(3, level)
.set(4, xp)
.set(5, upgradeLevel)
.set(6, defaultType)
.set(7, level)
.set(8, xp)
.set(9, upgradeLevel)
.set(10, defaultType)
.prepare(connection);
int effect = executeUpdate(statement);
if (effect == -1)
{
//Something went wrong uh oh
this.getPlugin().getLogger().severe("Inserting new Kit Data for " + playerKit.getUuid() + " failed!");
}
} catch (SQLException e)
{
e.printStackTrace();
} finally
{
if (connection != null)
{
try
{
connection.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
});
}
/**
* Update whether or not the specified kit is a default kit
*
* @param playerKit The player's kit data object
* @param kit The INTERNAL name of the kit
* @param def The integer representing the boolean value (1 for true 0 for false)
*/
public void updateDefault(PlayerKit playerKit, String kit, int def)
{
async(() -> {
Connection connection = getConnection();
String update = "UPDATE `kitProgression` SET `default` = ? " + "WHERE `uuid` = ? AND`kitId` = ?";
try
{
PreparedStatement statement = new SQLStatement(update)
.set(1, def)
.set(2, playerKit.getUuid())
.set(3, kit)
.prepare(connection);
int effect = executeUpdate(statement);
if (effect == -1)
{
this.getPlugin().getLogger().severe("Updating default value for" + playerKit.getUuid().toString() + "'s kit failed!");
}
} catch (SQLException e)
{
e.printStackTrace();
} finally
{
if (connection != null)
{
try
{
connection.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
});
}
@SuppressWarnings("Duplicates")
public void getInfo(UUID uuid)
{
async(() -> {
PlayerKit playerKit = new PlayerKit(uuid);
try (Connection connection = getConnection())
{
PreparedStatement preparedStatement = new SQLStatement(QUERY_KITS).set(1, uuid).prepare(connection);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
String kitId = resultSet.getString("kitId");
int level = resultSet.getInt("level");
int xp = resultSet.getInt("xp");
int upgradeLevel = resultSet.getInt("upgrade_level");
boolean def = resultSet.getInt("default") == 1;
playerKit.setLevel(level, kitId);
playerKit.setXp(xp, kitId);
playerKit.setUpgradeLevel(upgradeLevel, kitId);
playerKit.setDefault(def, kitId);
}
} catch (SQLException e)
{
e.printStackTrace();
}
_kitProgressionManager.getDataManager().add(playerKit);
});
}
/**
* Internal method for updating the table
*
* @param preparedStatement The statement to execute
* @return The amount of rows effected
*/
private int executeUpdate(PreparedStatement preparedStatement)
{
try
{
return preparedStatement.executeUpdate();
} catch (SQLException e)
{
e.printStackTrace();
return -1;
} finally
{
try
{
if (preparedStatement != null)
{
preparedStatement.close();
}
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
private void async(Runnable runnable)
{
Bukkit.getScheduler().runTaskAsynchronously(_plugin, runnable);
}
}

View File

@ -0,0 +1,278 @@
package mineplex.core.progression;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.progression.data.KitAbilityDetail;
import mineplex.core.progression.math.Calculations;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.UUID;
/**
* The API class all kits with the new system must use
*/
public interface ProgressiveKit
{
/**
* The name of the kit for displaying
*
* @return The kit's display name
*/
String getDisplayName();
/**
* This is the name stored in the database and checked against
*
* @return The internal name of this kit
*/
String getInternalName();
/**
* Get the Icon to display in the GUI
*
* @return This kit's icon
*/
Material getIcon();
/**
* Get the description for this kit
*
* @return This kit's description
*/
String[] getDescription();
/**
* This method gives the GUI information to display about the kit's upgrades and what they do
* This information is being directly displayed in a GUI, so make sure it looks good
* For more information, see the {@link KitAbilityDetail} class
*
* @return The map of upgrades and their details
*/
List<KitAbilityDetail> getAbilityDetails();
/**
* Retrieve the current level of this kit
*
* @param player The UUID of the player whose level you wish to check
* @return The kit's current level
*/
int getLevel(UUID player);
//Should this be a double? I don't think so...
/**
* Get the current amount of XP for this kit
* NOTE: XP Resets after each level up
*
* @param player The UUID of the player whose XP you wish to check
* @return The kit's current XP
*/
int getXp(UUID player);
/**
* Get the current state of upgrades for this kit
* X/5 with 5 being the highest.
* Linearly activated upon meeting certain criteria
*
* @param player The UUID of the player whose upgrade level you wish to check
* @return The kit's current upgrade level out of 5
*/
int getUpgradeLevel(UUID player);
/**
* Is this kit set as a default kit for this player?
*
* @param player The UUID of the player whose default type for this kit you wish to check
* @return Whether or not this kit is a default
*/
boolean isDefault(UUID player);
/**
* Gets whether or not this kit has been selected by the player
*
* @param player The UUID of the player
* @return Whether or not this kit has been selected by the player
*/
boolean isSelected(UUID player);
/**
* Upgrade the player's kit to the current level
*
* @param upgradeLevel The level to upgrade too
* @param player The player who we want to upgrade for.
*/
void upgrade(int upgradeLevel, UUID player);
/**
* Toggle whether or not this kit is default for the specified player
*
* @param defaultValue Whether or not this kit should be default
* @param player The specific player for whom this kit's default staturs will be toggled
*/
void setDefault(boolean defaultValue, UUID player);
/**
* Set the player's overall level for this kit
*
* @param level The level to which you wish to set the player's kit
* @param player The UUID of the player
*/
void setLevel(int level, UUID player);
/**
* Set the player's overall xp for this kit (relative to his current level, this is not TOTAL xp)
*
* @param xp The xp to which you wish to set the player's kit
* @param player The UUID of the player
*/
void setXp(int xp, UUID player);
/**
* Set the player's overall upgradeLevel for this kit
*
* @param upgradeLevel The upgradeLevel to which you wish to set the player's kit
* @param player The UUID of the player
*/
void setUpgradeLevel(int upgradeLevel, UUID player);
/**
* This is called when a player selects a kit in the GUI
* This is where you do your logic for storing player kits in relation to the game
*
* @param player The player who selects this kit.
*/
void onSelected(UUID player);
/**
* This is called when a player clicks the default button in the gui
* It will change the state of default
*
* @param player The player who toggles this kit's default setting.
*/
void onSetDefault(UUID player);
/**
* This method is called when a player level ups
* If you have special effects or messages, here is the place to do it
*
* @param player The player who leveled up
*/
void onLevelUp(UUID player);
/**
* Gets whether or not the player can purchase the upgrade level
*
* @param upgradeLevel The level of the upgrade you wish to check.
* @param player The UUID of the player
* @return If the player can purchase the upgrade
*/
boolean canPurchaseUpgrade(UUID player, int upgradeLevel);
/* ======================================================================================================
*
*
* Below here are utility methods that I believe people will be using frequently.
* If you need to override them, feel free to do so.
*
*
* ====================================================================================================== */
/**
* Gets if a player has already leveled up
* Players are only allowed 1 level up per game.
*
* @param player The player's UUID we want to check against
* @return Whether or not the player has already leveled up in this game
*/
boolean alreadyLeveledUp(UUID player);
/**
* Increment the players current level for this kit, and reset his XP
*
* @param player The player whose level we want to increase
*/
default void levelUp(UUID player)
{
setXp(1, player);
setLevel(getLevel(player) + 1, player);
onLevelUp(player);
}
/**
* Check to see if this player is eligible for level up
*
* @param player The player who we want to check
* @return True if he is able to level up, or false if he's not
*/
default boolean isLevelUpReady(UUID player)
{
int currentLevel = getLevel(player);
int xp = getXp(player);
int nextXP = Calculations.getXpForNextLevel(currentLevel);
if (nextXP < xp)
{
//We don't want people to continue earning XP after the level up, so cancel this.
//Makes sure that they only get the exact amount required.
setXp(nextXP, player);
return true;
}
return xp >= nextXP;
}
/**
* Get the difference (the amount needed) between the players current XP and his next levels XP
*
* @param player The player who we want to check against
* @return The integer difference between his current XP and his next level's required XP
*/
default int getXpDifference(UUID player)
{
int currentLevel = getLevel(player);
int xp = getXp(player);
int nextXP = Calculations.getXpForNextLevel(currentLevel);
return nextXP - xp;
}
/**
* Retrieves whether or not the player currently owns this upgrade.
* This is the upgrade level, not the player level which the player must be to upgrade
* So it should be between 1 and 5
*
* @param player The UUID of the player you wish to check
* @param upgradeLevel The level to check and see if the player owns
* @return If the player has the current upgrade
*/
default boolean ownsUpgrade(UUID player, int upgradeLevel)
{
return getUpgradeLevel(player) >= upgradeLevel;
}
default void displaySelectedEffect(Entity kitHost, Player... displayTo)
{
for (int i = 0; i < 1; i++)
{
double lead = i * ((2d * Math.PI) / 2);
float x = (float) (Math.cos(kitHost.getTicksLived() / 5d + lead) * 1f);
float z1 = (float) (Math.sin(kitHost.getTicksLived() / 5d + lead) * 1f);
float z2 = (float) -(Math.sin(kitHost.getTicksLived() / 5d + lead) * 1f);
float y = (float) (Math.sin(kitHost.getTicksLived() / 5d + lead) + 1f);
UtilParticle.PlayParticle(ParticleType.HAPPY_VILLAGER, kitHost.getLocation().add(x, y, z1), 0f, 0f, 0f, 0, 1,
ViewDist.NORMAL, displayTo);
UtilParticle.PlayParticle(ParticleType.HAPPY_VILLAGER, kitHost.getLocation().add(x, y, z2), 0f, 0f, 0f, 0, 1,
ViewDist.NORMAL, displayTo);
}
}
}

View File

@ -0,0 +1,38 @@
package mineplex.core.progression.data;
import org.bukkit.Material;
/**
* General wrapper for Ability Details (The display properties of this kits Abilities) for a GUI
* The purpose is to limit the amount of hard coded data Kit's do and make it as flexible as possible.
*/
public class KitAbilityDetail
{
private Material _icon;
private String _displayName;
private String[] _description;
public KitAbilityDetail(Material icon, String displayName, String[] description)
{
_icon = icon;
_displayName = displayName;
_description = description;
}
public String getDisplayName()
{
return _displayName;
}
public Material getIcon()
{
return _icon;
}
public String[] getDescription()
{
return _description;
}
}

View File

@ -0,0 +1,103 @@
package mineplex.core.progression.data;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.UUID;
/**
* Player Wrapper for the Progressive kit system
*/
public class PlayerKit
{
private UUID _player;
private String _currentKit;
private Map<String, Integer> _kitLevels;
private Map<String, Integer> _kitXPs;
private Map<String, Integer> _kitUpgradeLevels;
private Map<String, Boolean> _kitDefaultTypes;
//We only want players to level up kits once per game
private boolean _hasLeveledUp;
public PlayerKit(UUID player)
{
_player = player;
_kitLevels = Maps.newHashMap();
_kitXPs = Maps.newHashMap();
_kitUpgradeLevels = Maps.newHashMap();
_kitDefaultTypes = Maps.newHashMap();
}
public String getCurrentKit()
{
return _currentKit;
}
public void setCurrentKit(String currentKit)
{
_currentKit = currentKit;
}
public int getLevel(String kit)
{
return _kitLevels.getOrDefault(kit, 1);
}
public int getXp(String kit)
{
return _kitXPs.getOrDefault(kit, 1);
}
public int getUpgradeLevel(String kit)
{
return _kitUpgradeLevels.getOrDefault(kit, 0);
}
public void setLevel(int level, String kit)
{
_kitLevels.put(kit, level);
}
public void setXp(int xp, String kit)
{
_kitXPs.put(kit, xp);
}
public void setUpgradeLevel(int upgradeLevel, String kit)
{
_kitUpgradeLevels.put(kit, upgradeLevel);
}
public boolean isDefault(String kit)
{
return _kitDefaultTypes.getOrDefault(kit, true);
}
public void setDefault(boolean value, String kit)
{
_kitDefaultTypes.put(kit, value);
}
public boolean hasLeveledUp()
{
return _hasLeveledUp;
}
public void levelUp()
{
this._hasLeveledUp = true;
}
public UUID getPlayer()
{
return _player;
}
public UUID getUuid()
{
return _player;
}
}

View File

@ -0,0 +1,40 @@
package mineplex.core.progression.data;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.UUID;
/**
* Manages all PlayerKit data in memory
*/
public class PlayerKitDataManager
{
private Map<UUID, PlayerKit> _dataMapAccountUUID;
public PlayerKitDataManager()
{
_dataMapAccountUUID = Maps.newConcurrentMap();
}
public PlayerKit get(UUID uuid)
{
return _dataMapAccountUUID.get(uuid);
}
public void add(PlayerKit playerKit)
{
_dataMapAccountUUID.put(playerKit.getUuid(), playerKit);
}
public void remove(PlayerKit kit)
{
_dataMapAccountUUID.remove(kit.getUuid());
}
public Map<UUID, PlayerKit> getAll()
{
return _dataMapAccountUUID;
}
}

View File

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

View File

@ -0,0 +1,191 @@
package mineplex.core.progression.gui;
import mineplex.core.progression.gui.buttons.misc.IconButton;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* A class to manage dynamic creation of GUI's
*/
public abstract class Menu
{
protected static final Button[] EMPTY = new Button[45];
protected static Map<UUID, Menu> MENUS = new HashMap<>();
private String _name;
protected Button[] _buttons;
public Menu(String name)
{
_name = name;
_buttons = EMPTY;
}
public static Menu get(UUID name)
{
return MENUS.get(name);
}
/**
* Create an icon (no click action)
*
* @param item The itemstack ti display
* @return The created button
*/
protected Button create(ItemStack item)
{
return new IconButton(item);
}
public String getName()
{
return ChatColor.translateAlternateColorCodes('&', _name);
}
/**
* Open and setup the inventory for the player to view
* Store a reference to it inside a map for retrieving later
*
* @param player The player who we wish to show the GUI to
*/
public void open(Player player)
{
setButtons(setUp());
if (MENUS.get(player.getUniqueId()) != null)
{
MENUS.remove(player.getUniqueId());
}
MENUS.put(player.getUniqueId(), this);
int size = (_buttons.length + 8) / 9 * 9;
Inventory inventory = Bukkit.createInventory(player, size, getName());
for (int i = 0; i < _buttons.length; i++)
{
if (_buttons[i] == null)
{
continue;
}
ItemStack item = _buttons[i].getItemStack();
inventory.setItem(i, item);
}
player.openInventory(inventory);
}
/**
* Set up the GUI with buttons
*
* @return The setup button array
*/
protected abstract Button[] setUp();
public Button[] getButtons()
{
return _buttons;
}
public void setButtons(Button[] buttons)
{
_buttons = buttons;
}
/**
* Retrieve the button based off the slot
*
* @param slot The slot in the inventory
* @return The button corresponding to that slot
*/
public Button getButton(int slot)
{
try
{
return _buttons[slot];
} catch (ArrayIndexOutOfBoundsException e)
{
//There isn't a button there, so no need to throw an error
//e.printStackTrace();
return null;
}
}
/**
* Replace a button, or create a new button dynamically
* Update the players GUI
*
* @param slot The slot to set the new button
* @param button The reference to the button
* @param player The player whose GUI we'll be updating
*/
public void setButton(int slot, Button button, Player player)
{
try
{
_buttons[slot] = button;
} catch (ArrayIndexOutOfBoundsException ignored)
{
ignored.printStackTrace();
}
update(player);
}
/**
* Refresh the players view, allows to change what the player sees, without opening and closing the GUI
*
* @param player The player whose view you wish to update
*/
public void update(Player player)
{
InventoryView view = player.getOpenInventory();
if (view == null)
{
return;
}
if (!view.getTitle().equalsIgnoreCase(getName()))
{
return;
}
Inventory inventory = view.getTopInventory();
for (int i = 0; i < _buttons.length; i++)
{
if (_buttons[i] == null)
{
continue;
}
ItemStack item = _buttons[i].getItemStack();
inventory.setItem(i, item);
}
}
public void setTitle(String title)
{
_name = title;
}
public void onClose(Player player)
{
MENUS.remove(player.getUniqueId());
}
public static Menu remove(UUID uniqueId)
{
return MENUS.remove(uniqueId);
}
}

View File

@ -0,0 +1,45 @@
package mineplex.core.progression.gui;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
/**
* Listener for the Menu system
*/
public class MenuListener implements Listener
{
@EventHandler
public void onClick(InventoryClickEvent event)
{
String name = event.getInventory().getName();
Player player = (Player) event.getWhoClicked();
Menu gui = Menu.get(player.getUniqueId());
if (gui == null)
{
return;
}
if (!gui.getName().equalsIgnoreCase(name))
{
return;
}
Button button = gui.getButton(event.getRawSlot());
event.setCancelled(true);
event.setResult(Event.Result.DENY);
if (button == null)
{
return;
}
button.onClick(player);
}
}

View File

@ -0,0 +1,50 @@
package mineplex.core.progression.gui.buttons;
import com.google.common.collect.Lists;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.progression.data.KitAbilityDetail;
import mineplex.core.progression.gui.buttons.misc.IconButton;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.List;
/**
* Representing this kits Abilities in a GUI
*/
public class KitAbilityButton extends IconButton
{
private ItemStack _item;
public KitAbilityButton(KitAbilityDetail detail)
{
super(null);
ItemBuilder builder = new ItemBuilder(detail.getIcon());
builder.setTitle(detail.getDisplayName());
List<String> lore = Lists.newArrayList(" ");
lore.addAll(Arrays.asList(detail.getDescription()));
lore.add(" ");
builder.setLore(lore.toArray(new String[lore.size()]));
_item = builder.build();
}
@Override
public ItemStack getItemStack()
{
return _item;
}
@Override
public void setItemStack(ItemStack item)
{
_item = item;
}
}

View File

@ -0,0 +1,27 @@
package mineplex.core.progression.gui.buttons;
import mineplex.core.progression.ProgressiveKit;
import mineplex.core.progression.gui.Button;
import org.bukkit.inventory.ItemStack;
/**
* Similar to KitMenu, this helps with organizing buttons related to kits
* Since they all share common features.
*/
public abstract class KitButton extends Button
{
private ProgressiveKit _kit;
public KitButton(ProgressiveKit kit, ItemStack itemStack)
{
super(itemStack);
_kit = kit;
}
protected ProgressiveKit getKit()
{
return _kit;
}
}

View File

@ -0,0 +1,75 @@
package mineplex.core.progression.gui.buttons;
import com.google.common.collect.Lists;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.progression.ProgressiveKit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
* This is the display icon for the Kit inside of the main GUI
*/
public class KitIconButton extends KitButton
{
private ItemStack _itemStack;
public KitIconButton(ProgressiveKit kit, Player player)
{
super(kit, null);
ItemBuilder builder = new ItemBuilder(kit.getIcon());
builder.setTitle(C.cYellow + kit.getDisplayName());
List<String> lore = Lists.newArrayList(" ");
boolean foundPerkStart = false;
for (String s : kit.getDescription())
{
if (!foundPerkStart)
{
lore.add(ChatColor.GRAY + s);
if (s.equalsIgnoreCase(" ") || s.isEmpty() || s.equalsIgnoreCase(""))
{
foundPerkStart = true;
}
} else
{
lore.add(ChatColor.WHITE + s);
}
}
builder.setLore(lore.toArray(new String[lore.size()]));
if (kit.isSelected(player.getUniqueId()))
{
builder.addEnchantment(UtilInv.getDullEnchantment(), 1);
}
_itemStack = builder.build();
}
@Override
public ItemStack getItemStack()
{
return _itemStack;
}
@Override
public void setItemStack(ItemStack itemStack)
{
_itemStack = itemStack;
}
@Override
public void onClick(Player player)
{
getKit().onSelected(player.getUniqueId());
}
}

View File

@ -0,0 +1,47 @@
package mineplex.core.progression.gui.buttons;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.progression.ProgressiveKit;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* This manages toggling default selection of a kit
* I.E. Whether or not this kit will be always enabled without the user doing anything
*/
public class KitPermanentDefaultButton extends KitButton
{
private static final String[] DESCRIPTION = {
" ",
ChatColor.WHITE + "Selects this kit as your default kit",
ChatColor.WHITE + "until you decide to change it.",
" ",
ChatColor.WHITE + "Default kits will be auto-selected",
ChatColor.WHITE + "when you join a lobby.",
" "
};
private static final ItemStack ITEM = new ItemBuilder(Material.STAINED_GLASS_PANE)
.setData(DyeColor.LIGHT_BLUE.getWoolData())
.setTitle(ChatColor.YELLOW + "Default Kit")
.setLore(DESCRIPTION)
.build();
public KitPermanentDefaultButton(ProgressiveKit kit)
{
super(kit, ITEM);
}
@Override
public void onClick(Player player)
{
getKit().onSelected(player.getUniqueId());
getKit().onSetDefault(player.getUniqueId());
}
}

View File

@ -0,0 +1,38 @@
package mineplex.core.progression.gui.buttons;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.progression.ProgressiveKit;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
/**
* This manages selecting of the kit for the current game.
*/
public class KitSelectButton extends KitButton
{
private static final String[] LORE = {
" ",
ChatColor.WHITE + "Click to select this kit",
" "
};
public KitSelectButton(ProgressiveKit kit)
{
super(kit, new ItemBuilder(Material.STAINED_GLASS_PANE)
.setData(DyeColor.LIME.getWoolData())
.setTitle(ChatColor.YELLOW + kit.getDisplayName())
.setLore(UtilText.splitLinesToArray(LORE, LineFormat.LORE))
.build());
}
@Override
public void onClick(Player player)
{
getKit().onSelected(player.getUniqueId());
}
}

View File

@ -0,0 +1,50 @@
package mineplex.core.progression.gui.buttons;
import mineplex.core.common.util.F;
import mineplex.core.progression.ProgressiveKit;
import mineplex.core.progression.gui.Menu;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
/**
* @author Timothy Andis (TadahTech) on 4/7/2016.
*/
public class KitUpgradeButton extends KitButton
{
private int _upgradeLevel;
private String _upggradeName;
public KitUpgradeButton(ProgressiveKit kit, ItemStack itemStack, int upgradeLevel, String upggradeName)
{
super(kit, itemStack);
_upgradeLevel = upgradeLevel;
_upggradeName = upggradeName;
}
@Override
public void onClick(Player player)
{
UUID uuid = player.getUniqueId();
if (!getKit().canPurchaseUpgrade(uuid, _upgradeLevel))
{
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 10.0F, 1.0F);
player.sendMessage(F.main("Kit Progression", "You cannot purchase this upgrade!"));
return;
}
getKit().upgrade(_upgradeLevel, uuid);
player.playSound(player.getLocation(), Sound.CAT_MEOW, 5.0f, 1.0f);
player.sendMessage(F.main("Kit Progression", "Purchased " + _upggradeName));
Menu.remove(uuid);
player.closeInventory();
}
}

View File

@ -0,0 +1,135 @@
package mineplex.core.progression.gui.buttons;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.progression.ProgressiveKit;
import mineplex.core.progression.gui.guis.KitInformationTrackerMenu;
import mineplex.core.progression.gui.guis.KitMenu;
import mineplex.core.progression.math.Calculations;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import static mineplex.core.common.util.UtilServer.getPlugin;
/**
* This is the button for upgrades. It'll flash when one is available
* Displays information regarding upgrades on hover
*/
public class KitUpgradeMenuButton extends KitButton
{
private static final ItemStack ITEM_STACK = new ItemBuilder(Material.ENCHANTMENT_TABLE)
.setTitle(C.cYellow + "Upgrade Level")
.setLore(" ", C.cRed + "Upgrades Coming Soon!")
.build();
private ItemStack _item;
private boolean _flash;
private BukkitTask _task;
public KitUpgradeMenuButton(ProgressiveKit kit, Player player)
{
super(kit, null);
_item = ITEM_STACK;
//The current upgrade level out of 5 for this kit
int upgradeLevel = kit.getUpgradeLevel(player.getUniqueId());
//The players level
int level = kit.getLevel(player.getUniqueId());
//What's the next UPGRADE LEVEL (1-5)
int nextUpgradeLevel = Calculations.getNextUpgradeLevel(level);
//The 1-100 Level
int nextUpgradeLevelPlayer = Calculations.getNextUpgradeLevelPlayer(level);
//The difference between the players current level, and the next upgrade level
int diff = nextUpgradeLevelPlayer - level;
//This ONLY flashes if their next upgrade level isn't their same one.
_flash = Calculations.isUpgradeLevelEligible(level) && (nextUpgradeLevel > upgradeLevel);
if (_flash)
{
flash();
}
ChatColor color = Calculations.getColor(level, nextUpgradeLevelPlayer);
}
@Override
public ItemStack getItemStack()
{
return _item;
}
@Override
public void setItemStack(ItemStack item)
{
_item = item;
}
private void flash()
{
this._task = new BukkitRunnable()
{
private ItemStack itemClone = ITEM_STACK.clone();
private ItemStack AIR = new ItemStack(Material.AIR);
private boolean resetItem = false;
@Override
public void run()
{
if (!_flash)
{
cancel();
return;
}
if (resetItem)
{
setItemStack(itemClone);
resetItem = false;
return;
}
setItemStack(AIR);
resetItem = true;
}
}.runTaskTimer(getPlugin(), 0L, 10L);
}
@Override
public void onClick(Player player)
{
this._flash = false;
if (_task != null)
{
this._task.cancel();
}
KitMenu menu = new KitInformationTrackerMenu(getKit());
menu.open(player);
}
/**
* Will be used later
*/
private ItemBuilder lore(ItemBuilder builder, int upgradeLevel, ChatColor color, int diff)
{
builder.setLore(" ",
ChatColor.WHITE + "Upgrade Level: " + ChatColor.GREEN + upgradeLevel + " out of 5",
ChatColor.WHITE + "Next Upgrade Unlocked in: " + color + diff + " level" + (diff == 1 ? "" : "s"),
"",
ChatColor.WHITE + "Click to view Upgrade and XP tracking");
return builder;
}
}

View File

@ -0,0 +1,95 @@
package mineplex.core.progression.gui.buttons;
import com.google.common.collect.Lists;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.progression.ProgressiveKit;
import mineplex.core.progression.gui.guis.KitInformationTrackerMenu;
import mineplex.core.progression.gui.guis.KitMenu;
import mineplex.core.progression.math.Calculations;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
* This the button which takes the player to {@link KitInformationTrackerMenu}
* Display's information regarding this kits level and experience
*/
public class KitXPButton extends KitButton
{
private ItemStack _item;
public KitXPButton(ProgressiveKit kit, Player player)
{
super(kit, null);
ItemBuilder builder = new ItemBuilder(Material.EXP_BOTTLE);
builder.setTitle(ChatColor.YELLOW + "XP and Level");
List<String> lore = Lists.newArrayList(" ");
StringBuilder levelStringBuilder = new StringBuilder();
StringBuilder xpStringBuilder = new StringBuilder();
int level = kit.getLevel(player.getUniqueId());
levelStringBuilder.append(level).append(" out of 100 ")
.append(ChatColor.GRAY).append("(")
.append(getColor(level, 100)).append(100 - level)
.append(ChatColor.GRAY).append(")");
int xp = kit.getXp(player.getUniqueId());
int nextXp = Calculations.getXpForNextLevel(kit.getLevel(player.getUniqueId()));
int diff = kit.getXpDifference(player.getUniqueId());
xpStringBuilder.append(xp).append(" out of ").append(nextXp)
.append(ChatColor.GRAY).append(" (")
.append(getColor(xp, nextXp)).append(diff)
.append(ChatColor.GRAY).append(")");
lore.add(addLoreLine("Level", levelStringBuilder.toString()));
lore.add(addLoreLine("XP", xpStringBuilder.toString()));
lore.add(" ");
lore.add(ChatColor.WHITE + "Click to view Upgrade and XP tracking");
builder.setLore(lore.toArray(new String[lore.size()]));
_item = builder.build();
}
private ChatColor getColor(int i, int n)
{
return Calculations.getColor(i, n);
}
private String addLoreLine(String key, Object value)
{
return ChatColor.WHITE + key + ": " + ChatColor.GREEN + value;
}
@Override
public ItemStack getItemStack()
{
return _item;
}
@Override
public void setItemStack(ItemStack item)
{
this._item = item;
}
@Override
public void onClick(Player player)
{
KitMenu menu = new KitInformationTrackerMenu(getKit());
menu.open(player);
}
}

View File

@ -0,0 +1,40 @@
package mineplex.core.progression.gui.buttons.misc;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.progression.gui.Button;
import mineplex.core.progression.gui.guis.KitMenu;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* This button take you back to the specified menu
*/
public class BackButton extends Button
{
private static ItemStack ITEM = new ItemBuilder(Material.BED)
.setTitle(ChatColor.GRAY + "\u21FD Go Back")
.build();
private KitMenu _toMenu;
public BackButton(KitMenu toMenu)
{
super(ITEM);
_toMenu = toMenu;
}
@Override
public void setItemStack(ItemStack itemStack)
{
//You can't remove this item
}
@Override
public void onClick(Player player)
{
_toMenu.open(player);
}
}

View File

@ -0,0 +1,23 @@
package mineplex.core.progression.gui.buttons.misc;
import mineplex.core.progression.gui.Button;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* A button designed for purely cosmetic reasons, but has no impact when clicked.
*/
public class IconButton extends Button
{
public IconButton(ItemStack item)
{
super(item);
}
@Override
public void onClick(Player player)
{
}
}

View File

@ -0,0 +1,109 @@
package mineplex.core.progression.gui.guis;
import mineplex.core.progression.ProgressiveKit;
import mineplex.core.progression.gui.Button;
import mineplex.core.progression.gui.buttons.*;
import mineplex.core.progression.gui.buttons.misc.IconButton;
import org.bukkit.entity.Player;
/**
* This is the main menu a player sees when we selects an NPC Kit
* Displays the most important information about this kit
*/
public class KitDisplayMenu extends KitMenu
{
private static final int[] UPGRADE_SLOTS = {
27, 29, 31, 33, 35
};
private static final int[] PERM_SLOTS = {
0, 1, 9, 10
};
private static final int[] SELECT_SLOTS = {
7, 8, 16, 17
};
public KitDisplayMenu(ProgressiveKit kit)
{
super(kit);
}
@Override
public Button[] setup(Player player)
{
Button[] buttons = new Button[51];
setUpSelecting(buttons);
setUpIcon(buttons, player);
setUpDetails(buttons);
setUpNextMenuButtons(buttons, player);
return buttons;
}
/**
* Set up the buttons corresponding to opening {@link KitInformationTrackerMenu}
*
* @param buttons The array of buttons we're modifying
* @param player The player whose data we'll be using
*/
private void setUpNextMenuButtons(Button[] buttons, Player player)
{
buttons[48] = new KitXPButton(getKit(), player);
buttons[50] = new KitUpgradeMenuButton(getKit(), player);
}
/**
* Set up the Kit display's icon
*
* @param buttons The array of buttons we're modifying
*/
private void setUpIcon(Button[] buttons, Player player)
{
buttons[13] = new KitIconButton(getKit(), player);
}
/**
* Set up the details (info) regarding the upgrades to this kit
* Lines commented out due to waiting to release upgrades
*
* @param buttons The array of buttons we're modifying
*/
private void setUpDetails(Button[] buttons)
{
for (int i : UPGRADE_SLOTS)
{
buttons[i] = new IconButton(COMING_SOON);
}
}
/**
* Set up the options for selecting this kit
* Either permanent or just for this game
*
* @param buttons The array of buttons we're modifying
*/
private void setUpSelecting(Button[] buttons)
{
for (int permSlot : PERM_SLOTS)
{
buttons[permSlot] = new KitPermanentDefaultButton(getKit());
}
for (int tempSlot : SELECT_SLOTS)
{
buttons[tempSlot] = new KitSelectButton(getKit());
}
}
@Override
public void onClose(Player player)
{
}
}

View File

@ -0,0 +1,298 @@
package mineplex.core.progression.gui.guis;
import com.google.common.collect.Lists;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.progression.ProgressiveKit;
import mineplex.core.progression.gui.Button;
import mineplex.core.progression.gui.buttons.misc.BackButton;
import mineplex.core.progression.gui.buttons.misc.IconButton;
import mineplex.core.progression.math.Calculations;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.UUID;
/**
* This is the secondary menu access by either the Enchantment table or XP Bottle
* Displays the more technical data of a kit for the player
*/
public class KitInformationTrackerMenu extends KitMenu
{
private final DyeColor[] COLORS = {
DyeColor.GRAY,
DyeColor.YELLOW,
DyeColor.ORANGE,
DyeColor.LIME,
DyeColor.BLACK
};
private final int[] XP_SLOTS = {
11, 12, 13, 14, 15
};
private final int[] LEVEL_SLOTS = {
29, 30, 31, 32, 33
};
private final int[] UPGRADE_SLOTS = {
47, 48, 49, 50, 51
};
public KitInformationTrackerMenu(ProgressiveKit kit)
{
super(kit);
}
@Override
public Button[] setup(Player player)
{
Button[] buttons = new Button[52];
buttons[0] = new BackButton(new KitDisplayMenu(getKit()));
setUpXP(buttons, player);
setUpLevel(buttons, player);
setUpUpgrade(buttons, player);
return buttons;
}
/**
* Set up the row of glass panes symbolizing the players XP advancement
*
* @param buttons The array of buttons we're modifying
* @param player The player whose data we'll be using
*/
private void setUpXP(Button[] buttons, Player player)
{
ProgressiveKit kit = getKit();
UUID uuid = player.getUniqueId();
int level = kit.getLevel(uuid);
int xp = kit.getXp(uuid);
int nextXp = Calculations.getXpForNextLevel(level);
float perc = (xp * 100.0f) / nextXp;
String[] lore = {
" ",
ChatColor.WHITE + "Current XP: " + Calculations.getColor(xp, nextXp) + xp +
ChatColor.GRAY + " (" + Calculations.getColor(xp, nextXp) + (int) perc + "%" + ChatColor.GRAY + ")",
xpLore(getKit(), player)
};
for (int i : XP_SLOTS)
{
buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE)
.setData(DyeColor.BLACK.getWoolData())
.setAmount(1)
.setTitle(ChatColor.YELLOW + "Experience Progression")
.setLore(lore)
.build());
}
percentButtons(true, perc, XP_SLOTS, buttons, xp, nextXp, player);
}
/**
* Set up the row of glass panes symbolizing the players level advancement
*
* @param buttons The array of buttons we're modifying
* @param player The player whose data we'll be using
*/
private void setUpLevel(Button[] buttons, Player player)
{
ProgressiveKit kit = getKit();
UUID uuid = player.getUniqueId();
int level = kit.getLevel(uuid);
float perc = (level * 100.0f) / 100;
String[] lore = {
" ",
ChatColor.WHITE + "Current Level: " + Calculations.getColor(level, 100) + level +
ChatColor.GRAY + " (" + Calculations.getColor(level, 100) + level +
"/" + ChatColor.GREEN + 100 + ChatColor.GRAY + ")"
};
for (int i : LEVEL_SLOTS)
{
buttons[i] = new IconButton(new ItemBuilder(Material.STAINED_GLASS_PANE)
.setData(DyeColor.BLACK.getWoolData())
.setAmount(1)
.setTitle(ChatColor.YELLOW + "Level Progression")
.setLore(lore)
.build());
}
percentButtons(false, perc, LEVEL_SLOTS, buttons, level, 100, player);
}
/**
* Set up the row of Dyes / Music discs symbolizing the players upgrade advancement
*
* @param buttons The array of buttons we're modifying
* @param player The player whose data we'll be using
*/
private void setUpUpgrade(Button[] buttons, Player player)
{
for (int i : UPGRADE_SLOTS)
{
buttons[i] = new IconButton(COMING_SOON);
}
}
/* ======================================================================================================
*
*
* Below here are utility methods that speed up the process for me, and makes the code neater and easier
* to read.
*
* ====================================================================================================== */
@SuppressWarnings("Duplicates")
private int getLocked(int level)
{
switch (level)
{
case 1:
return 5;
case 2:
return 10;
case 3:
return 30;
case 4:
return 75;
case 5:
return 100;
}
if (level >= 5)
{
return 100;
}
return -1;
}
private void percentButtons(boolean xp, float perc, int[] array, Button[] buttons, int number, int total, Player player)
{
float checkAgainst = perc;
if (perc <= 20)
{
//One button
buttons[array[0]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
return;
}
if (perc <= 40)
{
buttons[array[0]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
checkAgainst -= 20;
buttons[array[1]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
return;
}
if (perc <= 60)
{
buttons[array[0]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
buttons[array[1]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
checkAgainst -= 40;
buttons[array[2]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
return;
}
if (perc <= 80)
{
buttons[array[0]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
buttons[array[1]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
buttons[array[2]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
checkAgainst -= 60;
buttons[array[3]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
return;
}
buttons[array[0]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
buttons[array[1]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
buttons[array[2]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
buttons[array[3]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
checkAgainst -= 80;
buttons[array[4]] = new IconButton(paneIcon(xp, number, total, perc, checkAgainst, player));
}
private ItemStack paneIcon(boolean xp, int number, int total, float perc, float checkAgainst, Player player)
{
String title = ChatColor.YELLOW + (xp ? "Experience Progression" : "Level Progression");
String current = ChatColor.WHITE + "Current " + (xp ? "XP" : "Level") + ": " + Calculations.getColor(number, total) + number;
String calculatedPerc = ChatColor.GRAY + " (" + Calculations.getColor(number, total) + (int) perc + "%" + ChatColor.GRAY + ")";
List<String> loreList = Lists.newArrayList(" ");
if (xp)
{
loreList.add(current + calculatedPerc);
loreList.add(xpLore(getKit(), player));
} else
{
loreList.add(current + ChatColor.GRAY + " (" + Calculations.getColor(number, total) + number +
"/" + ChatColor.GREEN + total + ChatColor.GRAY + ")");
}
return new ItemBuilder(Material.STAINED_GLASS_PANE)
.setData(perc >= 20 ? DyeColor.LIME.getWoolData() : getColor(checkAgainst))
.setTitle(title)
.setLore(loreList.toArray(new String[loreList.size()]))
.build();
}
private byte getColor(float perc)
{
if (perc <= 5)
{
return COLORS[0].getWoolData();
}
if (perc <= 10)
{
return COLORS[1].getWoolData();
}
if (perc <= 15)
{
return COLORS[2].getWoolData();
}
if (perc <= 20)
{
return COLORS[3].getWoolData();
}
return COLORS[4].getWoolData();
}
private String xpLore(ProgressiveKit kit, Player player)
{
StringBuilder xp = new StringBuilder(C.cWhite + "Progress: ");
int xpInt = kit.getXp(player.getUniqueId());
int xpNext = Calculations.getXpForNextLevel(kit.getLevel(player.getUniqueId()));
int diff = kit.getXpDifference(player.getUniqueId());
xp.append(Calculations.getColor(xpInt, xpNext)).append(xpInt)
.append(ChatColor.GRAY).append("/")
.append(ChatColor.GREEN).append(xpNext)
.append(ChatColor.GRAY).append(" (")
.append(Calculations.getColor(xpInt, xpNext)).append(diff)
.append(" needed")
.append(ChatColor.GRAY).append(")");
return xp.toString();
}
}

View File

@ -0,0 +1,101 @@
package mineplex.core.progression.gui.guis;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.progression.ProgressiveKit;
import mineplex.core.progression.gui.Button;
import mineplex.core.progression.gui.Menu;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* An implementation of {@link Menu} corresponding to kits
*/
public abstract class KitMenu extends Menu
{
/**
* Coming soon icon for upgrades
*/
protected static final ItemStack COMING_SOON = new ItemBuilder(Material.INK_SACK)
.setAmount(1)
.setData(DyeColor.GRAY.getDyeData())
.setTitle(ChatColor.RED + "Coming Soon")
.setLore(" ", ChatColor.GRAY + "Upgrades coming soon!")
.build();
private ProgressiveKit _kit;
public KitMenu(ProgressiveKit kit)
{
super(kit.getDisplayName());
_kit = kit;
}
/**
* Set up a menu based on the specific player
*
* @param player The player who we want to tailor the GUI to
* @return The setup arrangement of buttons
*/
public abstract Button[] setup(Player player);
/**
* Open a GUI tailored to the player
*
* @param player The player who we wish to show the GUI to
*/
@Override
public void open(Player player)
{
this.setButtons(setup(player));
if (MENUS.get(player.getUniqueId()) != null)
{
MENUS.remove(player.getUniqueId());
}
MENUS.put(player.getUniqueId(), this);
int size = (this._buttons.length + 8) / 9 * 9;
Inventory inventory = Bukkit.createInventory(player, size, getName());
for (int i = 0; i < _buttons.length; i++)
{
if (_buttons[i] == null)
{
continue;
}
ItemStack item = _buttons[i].getItemStack();
inventory.setItem(i, item);
}
player.openInventory(inventory);
}
/**
* Get the kit specific to this GUI
*
* @return This GUI's kit
*/
public ProgressiveKit getKit()
{
return _kit;
}
/**
* We don't want to use this, as we may require per player GUI's
* @return The arrangement of buttons
*/
@Override
public Button[] setUp()
{
return new Button[45];
}
}

View File

@ -0,0 +1,208 @@
package mineplex.core.progression.math;
import com.google.common.collect.Maps;
import net.md_5.bungee.api.ChatColor;
import java.util.Map;
/**
* This class handles all the math and static fields needed for Kit Progressions
* You can find some util methods in here as well that relate to numbers
*/
public class Calculations
{
private static final int[] LEVELS = new int[100];
private static final int[] UPGRADE_LEVELS = {5, 10, 30, 75, 100};
private static final Map<Integer, Integer> GEMS_FOR_UPGRADE = Maps.newHashMap();
static
{
generateDefaultExperienceLevels();
for (int level : UPGRADE_LEVELS)
{
GEMS_FOR_UPGRADE.put(level, level * 1000);
}
}
/**
* Generate the default XP values for leveling up.
*/
private static void generateDefaultExperienceLevels()
{
int expReq = 0;
for (int i = 0; i < 10; i++)
{
expReq += 50;
LEVELS[i] = expReq;
}
for (int i = 10; i < 20; i++)
{
expReq += 100;
LEVELS[i] = expReq;
}
for (int i = 20; i < 40; i++)
{
expReq += 200;
LEVELS[i] = expReq;
}
for (int i = 40; i < 60; i++)
{
expReq += 300;
LEVELS[i] = expReq;
}
for (int i = 60; i < 80; i++)
{
expReq += 400;
LEVELS[i] = expReq;
}
for (int i = 80; i < LEVELS.length; i++)
{
expReq += 500;
LEVELS[i] = expReq;
}
}
/**
* Determines if the players current level is a level at which an upgrade is unlocked
*
* @param currentLevel The players level
* @return Whether or not the players level is within the {@code GEMS_FOR_UPGRADE} map
*/
public static boolean isUpgradeLevelEligible(int currentLevel)
{
return GEMS_FOR_UPGRADE.containsKey(currentLevel);
}
/**
* Determines if the players current level, and his gems, are what he needs to level up this upgrade
*
* @param currentLevel The players level
* @param gems The players current gems
* @return Whether or not the player can upgrade
*/
public static boolean canUpgrade(int currentLevel, int gems)
{
return GEMS_FOR_UPGRADE.containsKey(currentLevel) && GEMS_FOR_UPGRADE.get(currentLevel) <= gems;
}
/**
* Get the XP required for the next level
*
* @param currLevel The players current level
* @return The XP for the next level
*/
public static int getXpForNextLevel(int currLevel)
{
if (currLevel >= 100)
{
return LEVELS[LEVELS.length - 1];
}
//lets get this calculation right....
return LEVELS[currLevel - 1];
}
/**
* Get the difference between the players current level, and the next level he needs for upgrades
*
* @param currentLevel The players level
* @return The integer difference
*/
public static int getUpgradeLevelDifference(int currentLevel)
{
for (int i = 0; i < UPGRADE_LEVELS.length; i++) {
if (UPGRADE_LEVELS[i] > currentLevel) {
return UPGRADE_LEVELS[i] - currentLevel;
}
}
return 0;
}
/**
* Utility method for percentage based chat colors
*
* @param i The initial number
* @param n The total number
* @return The chat color corresponding to the percentage
*/
public static ChatColor getColor(int i, int n)
{
ChatColor color = ChatColor.GREEN;
float perc = (i * 100.0f) / n;
if (perc <= 25)
{
return ChatColor.GRAY;
}
if (perc <= 50)
{
return ChatColor.YELLOW;
}
if (perc <= 75)
{
return ChatColor.GOLD;
}
return color;
}
/**
* Get the next integer upgrade level based of the players current leve;
*
* @param currentLevel The players current level
* @return The next upgrade level
*/
public static int getNextUpgradeLevel(int currentLevel)
{
for (int i = 0; i < UPGRADE_LEVELS.length; i++) {
if (UPGRADE_LEVELS[i] <= currentLevel) {
return UPGRADE_LEVELS[i];
}
}
return 5;
}
/**
* Get the next level the player needs to reach to unlock an upgrade
*
* @param currentLevel The players current level
* @return The next level the player needs to reach to unlock an upgrade
*/
public static int getNextUpgradeLevelPlayer(int currentLevel)
{
for (int i = 0; i < UPGRADE_LEVELS.length; i++) {
if (UPGRADE_LEVELS[i] >= currentLevel) {
return UPGRADE_LEVELS[i];
}
}
return 100;
}
@SuppressWarnings("Duplicates")
public static int getLevelRequiredFor(int upgradeLevel)
{
switch (upgradeLevel)
{
case 1:
return 5;
case 2:
return 10;
case 3:
return 30;
case 4:
return 75;
case 5:
return 100;
}
return -1;
}
}

View File

@ -0,0 +1,75 @@
package mineplex.core.progression.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* Create and manager a prepared statement for inserting into SQL
*/
public class SQLStatement
{
/**
* The initial string literal statement
*/
private String _base;
/**
* The _map for inserting objects into a prepared statement
*/
private Map<Integer, Object> _map;
/**
* Create a new instance of an SQLStatement
*
* @param base The literal string MySQL query ('?' are allowed)
*/
public SQLStatement(String base)
{
this._base = base;
this._map = new HashMap<>();
}
/**
* Set an object to a value for inserting upon completion
*
* @param i The position of the object
* @param object The object to insert into the statement for the given position
* @return The local instance with an updated map
*/
public SQLStatement set(int i, Object object)
{
this._map.put(i, object);
return this;
}
/**
* Prepare a fully built statement for running
*
* @param connection The connection used to establish the statement
* @return The fully built PreparedStatement
* @throws SQLException
*/
public PreparedStatement prepare(Connection connection) throws SQLException
{
PreparedStatement statement = connection.prepareStatement(_base);
for (Map.Entry<Integer, Object> entry : _map.entrySet())
{
int slot = entry.getKey();
Object object = entry.getValue();
if (object instanceof UUID)
{
statement.setObject(slot, object.toString());
continue;
}
statement.setObject(slot, object);
}
return statement;
}
}

View File

@ -85,15 +85,6 @@ public class ClanEnergyManager extends MiniPlugin implements Runnable
return _clansManager; return _clansManager;
} }
@EventHandler
public void command(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().startsWith("/energyshop"))
{
openShop(event.getPlayer());
}
}
public int convertEnergyToGold(int energy) public int convertEnergyToGold(int energy)
{ {
return (energy / 8) + (energy % 8 == 0 ? 0 : 1); return (energy / 8) + (energy % 8 == 0 ? 0 : 1);

View File

@ -304,10 +304,11 @@ public class ClansGame extends MiniPlugin
return; return;
} }
// Banners/String // Banners/String/Heads
if (player.getGameMode() != GameMode.CREATIVE && player.getItemInHand() != null) if (player.getGameMode() != GameMode.CREATIVE && player.getItemInHand() != null)
{ {
if (player.getItemInHand().getType() == Material.BANNER || player.getItemInHand().getType() == Material.STRING) if (player.getItemInHand().getType() == Material.BANNER || player.getItemInHand().getType() == Material.STRING
|| player.getItemInHand().getType() == Material.SKULL_ITEM)
{ {
Location destLocation = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation(); Location destLocation = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation();
ClanTerritory territory = _clans.getClanUtility().getClaim(destLocation); ClanTerritory territory = _clans.getClanUtility().getClaim(destLocation);

View File

@ -71,6 +71,7 @@ import mineplex.game.clans.core.repository.tokens.ClanToken;
import mineplex.game.clans.economy.GoldManager; import mineplex.game.clans.economy.GoldManager;
import mineplex.game.clans.fields.Field; import mineplex.game.clans.fields.Field;
import mineplex.game.clans.gameplay.Gameplay; import mineplex.game.clans.gameplay.Gameplay;
import mineplex.game.clans.gameplay.HiddenChestManager;
import mineplex.game.clans.gameplay.safelog.SafeLog; import mineplex.game.clans.gameplay.safelog.SafeLog;
import mineplex.game.clans.gameplay.safelog.npc.NPCManager; import mineplex.game.clans.gameplay.safelog.npc.NPCManager;
import mineplex.game.clans.items.GearManager; import mineplex.game.clans.items.GearManager;
@ -241,6 +242,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_condition = new SkillConditionManager(plugin); _condition = new SkillConditionManager(plugin);
_damageManager = new DamageManager(plugin, _combatManager, _npcManager, _disguiseManager, _condition); _damageManager = new DamageManager(plugin, _combatManager, _npcManager, _disguiseManager, _condition);
_damageManager.addCommand(new KillCommand(_damageManager)); _damageManager.addCommand(new KillCommand(_damageManager));
_condition.setDamageManager(_damageManager);
_worldEvent = new WorldEventManager(plugin, this, _damageManager, _lootManager, blockRestore, _clanRegions, null); _worldEvent = new WorldEventManager(plugin, this, _damageManager, _lootManager, blockRestore, _clanRegions, null);
@ -290,6 +292,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
new Weapon(plugin, energy); new Weapon(plugin, energy);
new Gameplay(plugin, this, blockRestore, _damageManager); new Gameplay(plugin, this, blockRestore, _damageManager);
new HiddenChestManager(this, packetHandler);
_projectileManager = new ProjectileManager(plugin); _projectileManager = new ProjectileManager(plugin);
Fire fire = new Fire(plugin, _condition, _damageManager); Fire fire = new Fire(plugin, _condition, _damageManager);
@ -619,7 +622,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
continue; continue;
} }
other.sendMessage(F.sys("Quit ", event.getPlayer().getName())); other.sendMessage(F.sys("Quit", event.getPlayer().getName()));
} }
} }

View File

@ -1,30 +1,26 @@
package mineplex.game.clans.clans.map; package mineplex.game.clans.clans.map;
import java.io.BufferedReader; import java.io.*;
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import mineplex.core.common.util.*;
import mineplex.game.clans.tutorial.TutorialManager; import mineplex.game.clans.tutorial.TutorialManager;
import mineplex.game.clans.tutorial.map.TutorialMapManager; import net.minecraft.server.v1_8_R3.*;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.util.LongHash;
import org.bukkit.craftbukkit.v1_8_R3.util.LongObjectHashMap;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
@ -35,6 +31,8 @@ import org.bukkit.event.player.PlayerItemHeldEvent;
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.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.map.MapRenderer; import org.bukkit.map.MapRenderer;
@ -46,13 +44,6 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Multisets; import com.google.common.collect.Multisets;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.portal.ServerTransferEvent; import mineplex.core.portal.ServerTransferEvent;
@ -62,82 +53,119 @@ import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansUtility; import mineplex.game.clans.clans.ClansUtility;
import mineplex.game.clans.clans.map.events.PlayerGetMapEvent; import mineplex.game.clans.clans.map.events.PlayerGetMapEvent;
import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.WorldEventManager;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.MaterialMapColor;
import net.minecraft.server.v1_8_R3.PersistentCollection;
/*
* This class manages what the Clans map will show.
* It will scan all relevant chunks (eg players nearby) every <x> ticks
*/
public class ItemMapManager extends MiniPlugin public class ItemMapManager extends MiniPlugin
{ {
private int _blocksScan = 16 * 3; // Every BLOCK_SCAN_INTERVAL we add as a new region to scan
private static final int BLOCK_SCAN_INTERVAL = 16 * 3;
// 1536 is the width of the entire world from one borderland to the other
private static final int HALF_WORLD_SIZE = 1536 / 2;
// This slot is where the Clans Map will go by default
private static final int CLANS_MAP_SLOT = 8;
private static final String[] ZOOM_INFO;
static
{
ZOOM_INFO = new String[4];
for (int zoomLevel = 0; zoomLevel <= 3; zoomLevel++)
{
StringBuilder progressBar = new StringBuilder(C.cBlue);
boolean colorChange = false;
for (int i = 2; i >= 0; i--)
{
if (!colorChange && i < zoomLevel)
{
progressBar.append(C.cGray);
colorChange = true;
}
char c;
switch (i)
{
case 0:
c = '█';
break;
case 1:
c = '▆';
break;
default:
c = '▄';
break;
}
for (int a = 0; a < 4; a++)
{
progressBar.append(c);
}
if (i > 0)
{
progressBar.append(" ");
}
}
ZOOM_INFO[zoomLevel] = progressBar.toString();
}
}
private ClansUtility _clansUtility; private ClansUtility _clansUtility;
private Comparator<Entry<Integer, Integer>> _comparator; private Comparator<Entry<Integer, Integer>> _comparator;
private int _halfMapSize = 1536 / 2; private int[][] _heightMap = new int[(HALF_WORLD_SIZE * 2) + 16][];
private int[][] _heightMap = new int[(_halfMapSize * 2) + 16][];
private boolean _loadWorld = true;
private HashMap<Integer, Byte[][]> _map = new HashMap<Integer, Byte[][]>(); private HashMap<Integer, Byte[][]> _map = new HashMap<Integer, Byte[][]>();
private short _mapId = -1; private short _mapId = -1;
private HashMap<String, MapInfo> _mapInfo = new HashMap<String, MapInfo>(); private HashMap<String, MapInfo> _mapInfo = new HashMap<String, MapInfo>();
private HashMap<Integer, Integer> _scale = new HashMap<Integer, Integer>(); private HashMap<Integer, Integer> _scale = new HashMap<Integer, Integer>();
private ArrayList<Entry<Integer, Integer>> _scanList = new ArrayList<Entry<Integer, Integer>>(); // Use LinkedList because operations are either add(Entry) which is O(1) and remove(0) which is O(1) on LinkedList but O(n) on ArrayList
private LinkedList<Entry<Integer, Integer>> _scanList = new LinkedList<Entry<Integer, Integer>>();
private World _world; private World _world;
private WorldServer _nmsWorld;
private ChunkProviderServer _chunkProviderServer;
private ChunkRegionLoader _chunkRegionLoader;
private WorldEventManager _eventManager; private WorldEventManager _eventManager;
private TutorialManager _tutorial; private TutorialManager _tutorial;
public ItemMapManager(ClansManager clansManager, TutorialManager tutorial, WorldEventManager eventManager) public ItemMapManager(ClansManager clansManager, TutorialManager tutorial, WorldEventManager eventManager)
{ {
super("ItemMapManager", clansManager.getPlugin()); super("ItemMapManager", clansManager.getPlugin());
_clansUtility = clansManager.getClanUtility(); _clansUtility = clansManager.getClanUtility();
_eventManager = eventManager; _eventManager = eventManager;
_tutorial = tutorial; _tutorial = tutorial;
_comparator = new Comparator<Entry<Integer, Integer>>() _comparator = (o1, o2) ->
{ {
// Render the places outside the map first to speed up visual errors fixing
int outsideMap = Boolean.compare(o1.getValue() < -HALF_WORLD_SIZE, o2.getValue() < -HALF_WORLD_SIZE);
@Override if (outsideMap != 0)
public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2)
{ {
// Render the places outside the map first to speed up visual errors fixing return -outsideMap;
int outsideMap = Boolean.compare(o1.getValue() < -_halfMapSize, o2.getValue() < -_halfMapSize); }
if (outsideMap != 0) double dist1 = 0;
{ double dist2 = 0;
return -outsideMap;
}
double dist1 = 0; for (Player player : UtilServer.getPlayers())
double dist2 = 0; {
dist1 += getDistance(o1, player.getLocation().getX(), player.getLocation().getZ());
for (Player player : UtilServer.getPlayers()) dist2 += getDistance(o2, player.getLocation().getX(), player.getLocation().getZ());
{ }
dist1 += getDistance(o1, player.getLocation().getX(), player.getLocation().getZ());
dist2 += getDistance(o2, player.getLocation().getX(), player.getLocation().getZ());
}
if (dist1 != dist2)
{
return Double.compare(dist1, dist2);
}
dist1 = getDistance(o1, 0, 0);
dist2 = getDistance(o2, 0, 0);
if (dist1 != dist2)
{
return Double.compare(dist1, dist2); return Double.compare(dist1, dist2);
} }
dist1 = getDistance(o1, 0, 0);
dist2 = getDistance(o2, 0, 0);
return Double.compare(dist1, dist2);
}; };
for (int x = -_halfMapSize; x < _halfMapSize; x += _blocksScan)
{
for (int z = -_halfMapSize - 16; z < _halfMapSize; z += (z < -_halfMapSize ? 16 : _blocksScan))
{
_scanList.add(new HashMap.SimpleEntry(x, z));
}
}
_scale.put(0, 1); _scale.put(0, 1);
// _scale.put(1, 2); // _scale.put(1, 2);
_scale.put(1, 4); _scale.put(1, 4);
@ -147,7 +175,7 @@ public class ItemMapManager extends MiniPlugin
for (Entry<Integer, Integer> entry : _scale.entrySet()) for (Entry<Integer, Integer> entry : _scale.entrySet())
{ {
int size = (_halfMapSize * 2) / entry.getValue(); int size = (HALF_WORLD_SIZE * 2) / entry.getValue();
Byte[][] bytes = new Byte[size][]; Byte[][] bytes = new Byte[size][];
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
@ -165,6 +193,23 @@ public class ItemMapManager extends MiniPlugin
_world = Bukkit.getWorld("world"); _world = Bukkit.getWorld("world");
try
{
Field chunkLoader = ChunkProviderServer.class.getDeclaredField("chunkLoader");
chunkLoader.setAccessible(true);
_nmsWorld = ((CraftWorld) _world).getHandle();
_chunkProviderServer = _nmsWorld.chunkProviderServer;
_chunkRegionLoader = (ChunkRegionLoader) chunkLoader.get(_chunkProviderServer);
if (_chunkRegionLoader == null)
{
throw new RuntimeException("Did not expect null chunkLoader");
}
}
catch (ReflectiveOperationException e)
{
throw new RuntimeException("Could not reflectively access ChunkRegionLoader", e);
}
try try
{ {
File file = new File("world/clans_map_id"); File file = new File("world/clans_map_id");
@ -238,6 +283,58 @@ public class ItemMapManager extends MiniPlugin
} }
rebuildScan(); rebuildScan();
initialScan();
}
private void initialScan()
{
System.out.println("Beginning initial scan. There are " + _scanList.size() + " regions to scan");
// How many regions before logging an update (Currently set to every 20%)
int logPer = _scanList.size() / 5;
while (!_scanList.isEmpty())
{
Entry<Integer, Integer> entry = _scanList.remove(0);
if (_scanList.size() % logPer == 0)
{
System.out.println("Running initial render... " + _scanList.size() + " sections to go");
}
int startingX = entry.getKey();
int startingZ = entry.getValue();
boolean outsideMap = startingZ < -HALF_WORLD_SIZE;
scanWorldMap(startingX, startingZ, !outsideMap, true);
if (outsideMap)
{
continue;
}
for (int scale = 1; scale < _scale.size(); scale++)
{
if (scale == 3)
continue;
drawWorldScale(scale, startingX, startingZ);
colorWorldHeight(scale, startingX, startingZ);
}
colorWorldHeight(0, startingX, startingZ);
}
for (int x = -HALF_WORLD_SIZE; x < HALF_WORLD_SIZE; x += BLOCK_SCAN_INTERVAL)
{
for (int z = -HALF_WORLD_SIZE; z < HALF_WORLD_SIZE; z += BLOCK_SCAN_INTERVAL)
{
drawWorldScale(3, x, z);
colorWorldHeight(3, x, z);
}
}
System.out.println("Finished first map scan and render");
} }
private void setupRenderer(MapView view) private void setupRenderer(MapView view)
@ -256,10 +353,7 @@ public class ItemMapManager extends MiniPlugin
if (!(event.getRightClicked() instanceof ItemFrame)) if (!(event.getRightClicked() instanceof ItemFrame))
return; return;
ItemStack item = event.getPlayer().getItemInHand(); if (!isItemClansMap(event.getPlayer().getItemInHand()))
if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId
|| item.getDurability() > _mapId + 100)
return; return;
event.setCancelled(true); event.setCancelled(true);
@ -270,7 +364,7 @@ public class ItemMapManager extends MiniPlugin
*/ */
public int calcMapCenter(int zoom, int cord) public int calcMapCenter(int zoom, int cord)
{ {
int mapSize = _halfMapSize / zoom; // This is how large the map is in pixels int mapSize = HALF_WORLD_SIZE / zoom; // This is how large the map is in pixels
int mapCord = cord / zoom; // This is pixels from true center of map, not held map int mapCord = cord / zoom; // This is pixels from true center of map, not held map
@ -309,7 +403,7 @@ public class ItemMapManager extends MiniPlugin
Byte[][] map = _map.get(scale); Byte[][] map = _map.get(scale);
int zoom = getZoom(scale); int zoom = getZoom(scale);
for (int x = startingX; x < startingX + _blocksScan; x += zoom) for (int x = startingX; x < startingX + BLOCK_SCAN_INTERVAL; x += zoom)
{ {
double d0 = 0; double d0 = 0;
@ -319,10 +413,10 @@ public class ItemMapManager extends MiniPlugin
{ {
for (int addZ = 0; addZ < zoom; addZ++) for (int addZ = 0; addZ < zoom; addZ++)
{ {
int hX = x + addX + _halfMapSize; int hX = x + addX + HALF_WORLD_SIZE;
int hZ = (startingZ - zoom) + addZ + _halfMapSize; int hZ = (startingZ - zoom) + addZ + HALF_WORLD_SIZE;
if (hX >= _halfMapSize * 2 || hZ >= _halfMapSize * 2) if (hX >= HALF_WORLD_SIZE * 2 || hZ >= HALF_WORLD_SIZE * 2)
{ {
continue; continue;
} }
@ -331,7 +425,7 @@ public class ItemMapManager extends MiniPlugin
} }
} }
for (int z = startingZ; z < startingZ + _blocksScan; z += zoom) for (int z = startingZ; z < startingZ + BLOCK_SCAN_INTERVAL; z += zoom)
{ {
// Water depth colors not included // Water depth colors not included
double d1 = 0; double d1 = 0;
@ -340,10 +434,10 @@ public class ItemMapManager extends MiniPlugin
{ {
for (int addZ = 0; addZ < zoom; addZ++) for (int addZ = 0; addZ < zoom; addZ++)
{ {
int hX = x + addX + _halfMapSize; int hX = x + addX + HALF_WORLD_SIZE;
int hZ = z + addZ + _halfMapSize; int hZ = z + addZ + HALF_WORLD_SIZE;
if (hX >= _halfMapSize * 2 || hZ >= _halfMapSize * 2) if (hX >= HALF_WORLD_SIZE * 2 || hZ >= HALF_WORLD_SIZE * 2)
{ {
continue; continue;
} }
@ -370,7 +464,7 @@ public class ItemMapManager extends MiniPlugin
b0 = 0; b0 = 0;
} }
int origColor = map[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] - 1; int origColor = map[(x + HALF_WORLD_SIZE) / zoom][(z + HALF_WORLD_SIZE) / zoom] - 1;
/*if (color < 4) /*if (color < 4)
{ {
@ -388,7 +482,15 @@ public class ItemMapManager extends MiniPlugin
}*/ }*/
byte color = (byte) (origColor + b0); byte color = (byte) (origColor + b0);
map[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] = color; if((color <= -113 || color >= 0) && color <= 127)
{
map[(x + HALF_WORLD_SIZE) / zoom][(z + HALF_WORLD_SIZE) / zoom] = color;
}
else
{
// System.out.println(String.format("Tried to set color to %s in colorWorldHeight scale: %s, sx: %s, sz: %s, x: %s, z: %s, zoom: %s",
// color, scale, startingX, startingZ, x, z, zoom));
}
} }
} }
} }
@ -399,9 +501,9 @@ public class ItemMapManager extends MiniPlugin
Byte[][] second = _map.get(scale); Byte[][] second = _map.get(scale);
int zoom = getZoom(scale); int zoom = getZoom(scale);
for (int x = startingX; x < startingX + _blocksScan; x += zoom) for (int x = startingX; x < startingX + BLOCK_SCAN_INTERVAL; x += zoom)
{ {
for (int z = startingZ; z < startingZ + _blocksScan; z += zoom) for (int z = startingZ; z < startingZ + BLOCK_SCAN_INTERVAL; z += zoom)
{ {
HashMultiset<Byte> hashmultiset = HashMultiset.create(); HashMultiset<Byte> hashmultiset = HashMultiset.create();
@ -409,8 +511,8 @@ public class ItemMapManager extends MiniPlugin
{ {
for (int addZ = 0; addZ < zoom; addZ++) for (int addZ = 0; addZ < zoom; addZ++)
{ {
int pX = x + addX + _halfMapSize; int pX = x + addX + HALF_WORLD_SIZE;
int pZ = z + addZ + _halfMapSize; int pZ = z + addZ + HALF_WORLD_SIZE;
if (pX >= first.length || pZ >= first.length) if (pX >= first.length || pZ >= first.length)
{ {
@ -432,7 +534,7 @@ public class ItemMapManager extends MiniPlugin
{ {
color = (byte) 0; color = (byte) 0;
} }
second[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] = color; second[(x + HALF_WORLD_SIZE) / zoom][(z + HALF_WORLD_SIZE) / zoom] = color;
} }
} }
} }
@ -440,25 +542,16 @@ public class ItemMapManager extends MiniPlugin
@EventHandler @EventHandler
public void dropItem(ItemSpawnEvent event) public void dropItem(ItemSpawnEvent event)
{ {
ItemStack item = event.getEntity().getItemStack(); if (isItemClansMap(event.getEntity().getItemStack()))
if (item != null && item.getType() == Material.MAP && item.getDurability() >= _mapId
&& item.getDurability() <= _mapId + 100)
{
event.getEntity().remove(); event.getEntity().remove();
}
} }
public void removeMap(Player player) public void removeMap(Player player)
{ {
for (int slot = 0; slot < player.getInventory().getSize(); slot++) for (int slot = 0; slot < player.getInventory().getSize(); slot++)
{ {
ItemStack item = player.getInventory().getItem(slot); if (isItemClansMap(player.getInventory().getItem(slot)))
if (item != null && item.getType() == Material.MAP && item.getDurability() >= _mapId && item.getDurability() <= _mapId + 100)
{
player.getInventory().setItem(slot, null); player.getInventory().setItem(slot, null);
}
} }
} }
@ -477,7 +570,7 @@ public class ItemMapManager extends MiniPlugin
private double getDistance(Entry<Integer, Integer> entry, double x1, double z1) private double getDistance(Entry<Integer, Integer> entry, double x1, double z1)
{ {
return getDistance(x1, z1, entry.getKey() + (_blocksScan / 2), entry.getValue() + (_blocksScan / 2)); return getDistance(x1, z1, entry.getKey() + (BLOCK_SCAN_INTERVAL / 2), entry.getValue() + (BLOCK_SCAN_INTERVAL / 2));
} }
public Byte[][] getMap(int scale) public Byte[][] getMap(int scale)
@ -492,7 +585,7 @@ public class ItemMapManager extends MiniPlugin
public int getMapSize() public int getMapSize()
{ {
return _halfMapSize; return HALF_WORLD_SIZE;
} }
public int getZoom(int scale) public int getZoom(int scale)
@ -500,35 +593,7 @@ public class ItemMapManager extends MiniPlugin
return _scale.get(scale); return _scale.get(scale);
} }
@EventHandler //fixme So what appears to happen is that after you die, if your map is is the same then the map is frozen
public void preventMapMoveInventories(InventoryClickEvent event)
{
Inventory inv = event.getClickedInventory();
if (inv == null)
return;
// Yeah, the loop looks a little weird..
for (ItemStack item : new ItemStack[]
{
event.getCurrentItem(), event.getCursor()
})
{
if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId
|| item.getDurability() > _mapId + 100)
continue;
if (inv.getHolder() instanceof Player ? !event.isShiftClick() : Objects.equal(event.getCurrentItem(), item))
continue;
event.setCancelled(true);
UtilPlayer.message(event.getWhoClicked(),
F.main("Inventory", "You cannot move " + F.item("Clans Map") + " between inventories."));
return;
}
}
@EventHandler @EventHandler
public void onDeath(PlayerDeathEvent event) public void onDeath(PlayerDeathEvent event)
{ {
@ -542,14 +607,10 @@ public class ItemMapManager extends MiniPlugin
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack item = player.getInventory().getItem(event.getNewSlot()); if (!isItemClansMap(player.getInventory().getItem(event.getNewSlot())))
if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId
|| item.getDurability() > _mapId + 100)
return; return;
showZoom(player, getMap(player)); showZoom(player, getMap(player));
} }
@EventHandler @EventHandler
@ -558,10 +619,7 @@ public class ItemMapManager extends MiniPlugin
if (event.getAction() == Action.PHYSICAL) if (event.getAction() == Action.PHYSICAL)
return; return;
ItemStack item = event.getItem(); if (!isItemClansMap(event.getItem()))
if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId
|| item.getDurability() > _mapId + 100)
return; return;
event.setCancelled(true); event.setCancelled(true);
@ -666,36 +724,11 @@ public class ItemMapManager extends MiniPlugin
private void rebuildScan() private void rebuildScan()
{ {
for (int x = -_halfMapSize; x < _halfMapSize; x += _blocksScan) for (int x = -HALF_WORLD_SIZE; x < HALF_WORLD_SIZE; x += BLOCK_SCAN_INTERVAL)
{ {
for (int z = -_halfMapSize - 16; z < _halfMapSize; z += (z < -_halfMapSize ? 16 : _blocksScan)) for (int z = -HALF_WORLD_SIZE - 16; z < HALF_WORLD_SIZE; z += (z < -HALF_WORLD_SIZE ? 16 : BLOCK_SCAN_INTERVAL))
{ {
_scanList.add(new HashMap.SimpleEntry(x, z)); _scanList.add(new HashMap.SimpleEntry<>(x, z));
}
}
if (!_loadWorld)
{
Iterator<Entry<Integer, Integer>> itel = _scanList.iterator();
while (itel.hasNext())
{
Entry<Integer, Integer> entry = itel.next();
boolean removeEntry = true;
for (Player player : UtilServer.getPlayers())
{
if (Math.sqrt(getDistance(entry, player.getLocation().getX(), player.getLocation().getZ())) < 200)
{
removeEntry = false;
break;
}
}
if (removeEntry)
{
itel.remove();
}
} }
} }
@ -744,101 +777,117 @@ public class ItemMapManager extends MiniPlugin
if (event.getType() != UpdateType.FAST) if (event.getType() != UpdateType.FAST)
return; return;
if (_scanList.isEmpty()) if (_scanList.isEmpty() && UtilServer.getPlayers().length > 0)
{ {
if (_loadWorld)
{
for (int x = -_halfMapSize; x < _halfMapSize; x += _blocksScan)
{
for (int z = -_halfMapSize; z < _halfMapSize; z += _blocksScan)
{
drawWorldScale(3, x, z);
colorWorldHeight(3, x, z);
}
}
System.out.print("Finished first map scan and render");
}
_loadWorld = false;
if (UtilServer.getPlayers().length == 0)
return;
rebuildScan(); rebuildScan();
} }
else if (_scanList.size() % 20 == 0)
if (_scanList.size() % 20 == 0)
{ {
Collections.sort(_scanList, _comparator); Collections.sort(_scanList, _comparator);
} }
if (_scanList.isEmpty()) if (_scanList.isEmpty())
{
return; return;
}
Entry<Integer, Integer> entry = _scanList.remove(0); Entry<Integer, Integer> entry = _scanList.remove(0);
int startingX = entry.getKey(); int startingX = entry.getKey();
int startingZ = entry.getValue(); int startingZ = entry.getValue();
boolean outsideMap = startingZ < -_halfMapSize; boolean outsideMap = startingZ < -HALF_WORLD_SIZE;
scanWorldMap(startingX, startingZ, !outsideMap, false);
scanWorldMap(startingX, startingZ, !outsideMap);
if (outsideMap) if (outsideMap)
{
return; return;
}
for (int scale = 1; scale < _scale.size(); scale++) for (int scale = 1; scale < _scale.size(); scale++)
{ {
if (scale == 3 && _loadWorld) drawWorldScale(scale, startingX, startingZ);
continue;
if (!outsideMap)
{
drawWorldScale(scale, startingX, startingZ);
}
colorWorldHeight(scale, startingX, startingZ); colorWorldHeight(scale, startingX, startingZ);
} }
colorWorldHeight(0, startingX, startingZ); colorWorldHeight(0, startingX, startingZ);
} }
public void scanWorldMap(int startingX, int startingZ, boolean setColors)
// Let's not create hundreds of thousands of BlockPositions
// Single thread = should be thread safe
private BlockPosition.MutableBlockPosition _blockPosition = new BlockPosition.MutableBlockPosition();
// Maps the cached chunks which were loaded from disk to save IO operations
private LongObjectHashMap<Chunk> _chunkCache = new LongObjectHashMap<>();
/*
* Remove the cached chunks when the real chunks are loaded in
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void LoadChunk(ChunkLoadEvent event)
{
_chunkCache.remove(LongHash.toLong(event.getChunk().getX(), event.getChunk().getZ()));
}
/*
* Given a particular coordinate, this method will scan up to BLOCK_SCAN_INTERVAL and record the color of ever 16th block
* If a chunk has not been loaded, the following steps will be taken:
* * Attempt to load the chunk from disk.
* * If the chunk could not be loaded, generate it froms scratch
* Otherwise, the loaded chunk will be used
*/
public void scanWorldMap(int startingX, int startingZ, boolean setColors, boolean isFirstScan)
{ {
Byte[][] map = _map.get(0); Byte[][] map = _map.get(0);
for (int beginX = startingX; beginX < startingX + BLOCK_SCAN_INTERVAL; beginX += 16)
for (int beginX = startingX; beginX < startingX + _blocksScan; beginX += 16)
{ {
for (int beginZ = startingZ - (startingZ > -_halfMapSize ? 16 : 0); beginZ < startingZ for (int beginZ = startingZ - (startingZ > -HALF_WORLD_SIZE ? 16 : 0); beginZ < startingZ
+ (setColors ? _blocksScan : 16); beginZ += 16) + (setColors ? BLOCK_SCAN_INTERVAL : 16); beginZ += 16)
{ {
Chunk chunk = _world.getChunkAt(beginX / 16, beginZ / 16); int chunkX = beginX / 16;
boolean loaded = false; int chunkZ = beginZ / 16;
net.minecraft.server.v1_8_R3.Chunk nmsChunk = _chunkProviderServer.getChunkIfLoaded(chunkX, chunkZ);
if (!chunk.isLoaded()) if (nmsChunk == null)
{ {
if (_loadWorld) long key = LongHash.toLong(chunkX, chunkZ);
nmsChunk = _chunkCache.get(key);
if (nmsChunk == null)
{ {
loaded = chunk.load(); if (!isFirstScan)
} {
else continue;
{ }
continue; try
{
Object[] data = _chunkRegionLoader.loadChunk(_nmsWorld, chunkX, chunkZ);
if (data == null)
{
// Something is wrong with the chunk
System.out.println("Chunk is not generated or missing level/block data. Regenerating (" + chunkX + "," + chunkZ + ")");
nmsChunk = ((CraftChunk) _world.getChunkAt(chunkX, chunkZ)).getHandle();
}
else
{
nmsChunk = (net.minecraft.server.v1_8_R3.Chunk) data[0];
}
}
catch (IOException e)
{
throw new RuntimeException("Chunk is corrupt or not readable!", e);
}
_chunkCache.put(key, nmsChunk);
} }
} }
net.minecraft.server.v1_8_R3.Chunk nmsChunk = ((CraftChunk) chunk).getHandle(); if (!nmsChunk.isEmpty())
for (int x = beginX; x < beginX + 16; x++)
{ {
for (int z = beginZ; z < beginZ + 16; z++) for (int x = beginX; x < beginX + 16; x++)
{ {
int color = 0; for (int z = beginZ; z < beginZ + 16; z++)
if (!nmsChunk.isEmpty())
{ {
int color = 0;
int k3 = x & 0xF; int k3 = x & 0xF;
int l3 = z & 0xF; int l3 = z & 0xF;
@ -850,7 +899,8 @@ public class ItemMapManager extends MiniPlugin
do do
{ {
l4--; l4--;
iblockdata= nmsChunk.getBlockData(new BlockPosition(k3, l4, l3)); _blockPosition.c(k3, l4, l3);
iblockdata = nmsChunk.getBlockData(_blockPosition);
} }
while (iblockdata.getBlock().g(iblockdata) == MaterialMapColor.b && (l4 > 0)); while (iblockdata.getBlock().g(iblockdata) == MaterialMapColor.b && (l4 > 0));
@ -860,34 +910,31 @@ public class ItemMapManager extends MiniPlugin
Block block1; Block block1;
do do
{ {
block1 = nmsChunk.getType(new BlockPosition(k3, j5--, l3)); _blockPosition.c(k3, j5--, l3);
block1 = nmsChunk.getType(_blockPosition);
} }
while ((j5 > 0) && (block1.getMaterial().isLiquid())); while ((j5 > 0) && (block1.getMaterial().isLiquid()));
} }
} }
_heightMap[x + _halfMapSize + 16][z + _halfMapSize + 16] = l4; _heightMap[x + HALF_WORLD_SIZE + 16][z + HALF_WORLD_SIZE + 16] = l4;
if (setColors) if (setColors)
{ {
//color = block.f(i5).M; //color = block.f(i5).M;
IBlockData data = nmsChunk.getBlockData(new BlockPosition(k3, l4, l3)); _blockPosition.c(k3, l4, l3);
IBlockData data = nmsChunk.getBlockData(_blockPosition);
color = data.getBlock().g(data).M; color = data.getBlock().g(data).M;
color = (byte) ((color * 4) + 1); color = (byte) ((color * 4) + 1);
} }
}
if (setColors && beginZ >= startingZ) if (setColors && beginZ >= startingZ)
{ {
map[x + _halfMapSize][z + _halfMapSize] = (byte) color; map[x + HALF_WORLD_SIZE][z + HALF_WORLD_SIZE] = (byte) color;
}
} }
} }
if (loaded)
{
chunk.unload();
}
} }
} }
} }
@ -898,10 +945,10 @@ public class ItemMapManager extends MiniPlugin
PlayerGetMapEvent event = UtilServer.CallEvent(new PlayerGetMapEvent(player)); PlayerGetMapEvent event = UtilServer.CallEvent(new PlayerGetMapEvent(player));
if (event.isCancelled()) if (event.isCancelled())
return; return;
for (ItemStack item : UtilInv.getItems(player)) for (ItemStack item : UtilInv.getItems(player))
{ {
if (item.getType() == Material.MAP && (item.getDurability() >= _mapId && item.getDurability() <= _mapId + 100)) if (isItemClansMap(item))
{ {
return; return;
} }
@ -909,62 +956,38 @@ public class ItemMapManager extends MiniPlugin
ItemStack item = new ItemBuilder(Material.MAP, 1, (short) getMap(player).getMap()).setTitle("Clans Map").build(); ItemStack item = new ItemBuilder(Material.MAP, 1, (short) getMap(player).getMap()).setTitle("Clans Map").build();
int slot = player.getInventory().firstEmpty(); int slot = CLANS_MAP_SLOT;
ItemStack mapSlot = player.getInventory().getItem(slot);
if (mapSlot != null && mapSlot.getType() != Material.AIR)
{
slot = player.getInventory().firstEmpty();
}
if (slot >= 0) if (slot >= 0)
{ {
ItemStack mapSlot = player.getInventory().getItem(8);
if (mapSlot == null || mapSlot.getType() == Material.AIR)
{
slot = 8;
}
player.getInventory().setItem(slot, item); player.getInventory().setItem(slot, item);
} }
} }
/*
* Displays the action bar to a player given their zoom level. Implementation may change
*/
private void showZoom(Player player, MapInfo info) private void showZoom(Player player, MapInfo info)
{ {
String progressBar = C.cBlue + ""; UtilTextBottom.display(ZOOM_INFO[info.getScale()], player);
boolean colorChange = false;
for (int i = 2; i >= 0; i--)
{
if (!colorChange && i < info.getScale())
{
progressBar += C.cGray;
colorChange = true;
}
char c;
switch (i)
{
case 0:
c = '█';
break;
case 1:
c = '▆';
break;
default:
c = '▄';
break;
}
for (int a = 0; a < 4; a++)
{
progressBar += c;
}
if (i > 0)
{
progressBar += " ";
}
}
UtilTextBottom.display(progressBar, player);
} }
/*
* Check whether an {@link ItemStack} is also a Clans Map
*
* @param itemStack The {@link ItemStack} to check
* @returns Whether the {@link ItemStack} is also a Clans Map
*/
private boolean isItemClansMap(ItemStack itemStack)
{
return UtilItem.matchesMaterial(itemStack, Material.MAP)
&& itemStack.getDurability() >= _mapId
&& itemStack.getDurability() <= _mapId + 100;
}
} }

View File

@ -143,7 +143,7 @@ public class ItemMapRenderer extends MapRenderer
if (_manager.getClansUtility().relPT(player, chunk) == ClansUtility.ClanRelation.SAFE) if (_manager.getClansUtility().relPT(player, chunk) == ClansUtility.ClanRelation.SAFE)
clanColor2 = new Color(50, 150, 255); clanColor2 = new Color(50, 150, 255);
} }
else if (owningClan.getName().equals("Spawn")) else if (owningClan.getName().equals("Spawn"))
{ {
clanColor = Color.WHITE; clanColor = Color.WHITE;
clanColor2 = new Color(0, 255, 100); clanColor2 = new Color(0, 255, 100);
@ -184,74 +184,83 @@ public class ItemMapRenderer extends MapRenderer
if (clanColor != null) if (clanColor != null)
{ {
int chunkBX = blockX & 0xF; if(! ((color <= -113 || color >= 0) && color <= 127))
int chunkBZ = blockZ & 0xF;
int chunkX1 = (int) Math.floor(blockX / 16D);
int chunkZ1 = (int) Math.floor(blockZ / 16D);
//Border
if (colorAll ||
((chunkBX == 0 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + (chunkX1 - 1) + "," + chunkZ1))
|| ((chunkBZ == 0 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + chunkX1 + "," + (chunkZ1 - 1)))
|| ((chunkBX + zoom > 15 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + (chunkX1 + 1) + "," + chunkZ1))
|| ((chunkBZ + zoom > 15 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + chunkX1 + "," + (chunkZ1 + 1))))
{ {
Color cColor = MapPalette.getColor(color); color = (byte) 0;
double clans = colorAll ? 1 : 0.8;// 0.65; System.out.println(String.format("Tried to draw invalid color %s, player: %s, mapX: %s, mapZ: %s",
color, player.getName(), mapX, mapZ));
//Use clanColor2 no matter what for admins
Color drawColor = clanColor;
if (owningClan.isAdmin() && clanColor2 != null)
{
drawColor = clanColor2;
clans = 1;
}
double base = 1 - clans;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans));
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans));
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans));
color = MapPalette.matchColor(r, g, b);
} }
//Inside
else else
{ {
Color cColor = MapPalette.getColor(color); int chunkBX = blockX & 0xF;
int chunkBZ = blockZ & 0xF;
int chunkX1 = (int) Math.floor(blockX / 16D);
int chunkZ1 = (int) Math.floor(blockZ / 16D);
double clans = 0.065; //Border
if (colorAll ||
//Stripes ((chunkBX == 0 || zoom == 13) &&
boolean checker = (mapX + (mapZ % 4)) % 4 == 0;
Color drawColor = clanColor; owningClan != _manager.getClansUtility().getOwner("world," + (chunkX1 - 1) + "," + chunkZ1))
if (checker && owningClan.isAdmin() && clanColor2 != null)
|| ((chunkBZ == 0 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + chunkX1 + "," + (chunkZ1 - 1)))
|| ((chunkBX + zoom > 15 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + (chunkX1 + 1) + "," + chunkZ1))
|| ((chunkBZ + zoom > 15 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + chunkX1 + "," + (chunkZ1 + 1))))
{ {
drawColor = clanColor2; Color cColor = MapPalette.getColor(color);
clans = 1; double clans = colorAll ? 1 : 0.8;// 0.65;
//Use clanColor2 no matter what for admins
Color drawColor = clanColor;
if (owningClan.isAdmin() && clanColor2 != null)
{
drawColor = clanColor2;
clans = 1;
}
double base = 1 - clans;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans));
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans));
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans));
color = MapPalette.matchColor(r, g, b);
} }
double base = 1 - clans;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans)); //Inside
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans)); else
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans)); {
Color cColor = MapPalette.getColor(color);
color = MapPalette.matchColor(r, g, b); double clans = 0.065;
//Stripes
boolean checker = (mapX + (mapZ % 4)) % 4 == 0;
Color drawColor = clanColor;
if (checker && owningClan.isAdmin() && clanColor2 != null)
{
drawColor = clanColor2;
clans = 1;
}
double base = 1 - clans;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans));
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans));
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans));
color = MapPalette.matchColor(r, g, b);
}
} }
} }
} }

View File

@ -4,6 +4,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
/*
* This event is called when a Player is about to receive a Clans Map
*/
public class PlayerGetMapEvent extends Event public class PlayerGetMapEvent extends Event
{ {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();

View File

@ -197,18 +197,7 @@ public class ClansRegions extends MiniPlugin
{ {
int x = chunkX + xOffset; int x = chunkX + xOffset;
int z = chunkZ + zOffset; int z = chunkZ + zOffset;
Chunk chunk; String chunkStr = location.getWorld().getName() + "," + x + "," + z;
try
{ //Corrupted chunk will hold up whole server
chunk = location.getWorld().getChunkAt(x, z);
}
catch(Exception e)
{
System.out.println("UNABLE TO LOAD CHUNK AT " + x + " , " + z);
e.printStackTrace();
continue;
}
String chunkStr = UtilWorld.chunkToStr(chunk);
if (addNegative) if (addNegative)
{ {

View File

@ -332,35 +332,6 @@ public class Gameplay extends MiniPlugin
} }
} }
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (!_clansManager.getIncognitoManager().Get(event.getPlayer()).Status)
{
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
{
return;
}
if (event.getClickedBlock() == null)
{
return;
}
Material type = event.getClickedBlock().getType();
if (type != Material.CHEST && type != Material.TRAPPED_CHEST)
{
return;
}
Chest chest = (Chest) event.getClickedBlock().getState();
event.getPlayer().openInventory(chest.getInventory());
event.setCancelled(true);
}
/** /**
* Disable all Piston related events in Clans * Disable all Piston related events in Clans
* *

View File

@ -0,0 +1,55 @@
package mineplex.game.clans.gameplay;
import mineplex.core.common.util.UtilServer;
import mineplex.core.packethandler.PacketHandler;
import mineplex.game.clans.clans.ClansManager;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
import org.bukkit.craftbukkit.v1_8_R3.inventory.InventoryWrapper;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
public class HiddenChestManager implements Listener
{
private final ClansManager _clansManager;
public HiddenChestManager(ClansManager clansManager, PacketHandler packetHandler)
{
this._clansManager = clansManager;
UtilServer.RegisterEvents(this);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent event)
{
if (!_clansManager.getIncognitoManager().Get(event.getPlayer()).Status)
{
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
{
return;
}
if (event.getClickedBlock() == null)
{
return;
}
Material type = event.getClickedBlock().getType();
if (type != Material.CHEST && type != Material.TRAPPED_CHEST)
{
return;
}
Chest chest = (Chest) event.getClickedBlock().getState();
event.getPlayer().openInventory(new CraftInventory(new InventoryWrapper(chest.getInventory())));
event.setCancelled(true);
//fixme opened chest has name "container.chest" and that looks bad
}
}

View File

@ -31,41 +31,28 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
*/ */
public class CustomItem implements Listener public class CustomItem implements Listener
{ {
// Chat color used for item display name
private static final ChatColor TITLE_COLOR = ChatColor.GOLD; // Chat color private static final ChatColor TITLE_COLOR = ChatColor.GOLD;
// used for // Chat color used for attribute descriptions
// item private static final ChatColor ATTRIBUTE_COLOR = ChatColor.WHITE;
// display
// name protected transient String _displayName;
private static final ChatColor ATTRIBUTE_COLOR = ChatColor.WHITE; // Chat protected transient String[] _description;
// color protected transient Material _material;
// used
// for
// attribute
// descriptions
private AttributeContainer _attributes; private AttributeContainer _attributes;
public AttributeContainer getAttributes()
{
return _attributes;
}
protected String _displayName;
protected String[] _description;
protected Material _material;
protected String _uuid; protected String _uuid;
protected boolean _dullEnchantment; protected boolean _dullEnchantment;
public String OriginalOwner = null; public String OriginalOwner = null;
public String getUuid() public String getUuid()
{ {
return _uuid; return _uuid;
} }
public CustomItem(String displayName, String[] description, Material material) public CustomItem(String displayName, String[] description, Material material)
{ {
_displayName = displayName; _displayName = displayName;
@ -75,12 +62,12 @@ public class CustomItem implements Listener
_uuid = UUID.randomUUID().toString(); _uuid = UUID.randomUUID().toString();
UtilServer.RegisterEvents(this); UtilServer.RegisterEvents(this);
} }
public CustomItem(Material material) public CustomItem(Material material)
{ {
this(prettifyName(material), null, material); this(prettifyName(material), null, material);
} }
/** /**
* @return the name displayed to players for the item. * @return the name displayed to players for the item.
*/ */
@ -88,16 +75,16 @@ public class CustomItem implements Listener
{ {
return ChatColor.RESET.toString() + TITLE_COLOR + _attributes.formatItemName(_displayName); return ChatColor.RESET.toString() + TITLE_COLOR + _attributes.formatItemName(_displayName);
} }
public String[] getDescription() public String[] getDescription()
{ {
return _description; return _description;
} }
public List<String> getLore() public List<String> getLore()
{ {
List<String> lore = new ArrayList<String>(); List<String> lore = new ArrayList<String>();
if (getDescription() != null) if (getDescription() != null)
{ {
for (String desc : getDescription()) for (String desc : getDescription())
@ -105,49 +92,45 @@ public class CustomItem implements Listener
lore.add(ATTRIBUTE_COLOR + desc); lore.add(ATTRIBUTE_COLOR + desc);
} }
} }
// Display attribute descriptions and stats in lore // Display attribute descriptions and stats in lore
for (ItemAttribute attribute : _attributes.getAttributes()) for (ItemAttribute attribute : _attributes.getAttributes())
{ {
String attributeLine = ATTRIBUTE_COLOR + "" + attribute.getDescription(); String attributeLine = ATTRIBUTE_COLOR + "" + attribute.getDescription();
lore.add(attributeLine); lore.add(attributeLine);
} }
// Add encoded JSON form of this item, not seen by user.
String serialization = GearManager.getItemSerialization(this);
lore.add(serialization);
return lore; return lore;
} }
public ItemStack toItemStack(int amount) public ItemStack toItemStack(int amount)
{ {
ItemStack item = new ItemStack(_material, amount); ItemStack item = new ItemStack(_material, amount);
update(item); update(item);
if (_dullEnchantment) if (_dullEnchantment)
{ {
UtilInv.addDullEnchantment(item); UtilInv.addDullEnchantment(item);
} }
return item; return item;
} }
public ItemStack toItemStack() public ItemStack toItemStack()
{ {
return toItemStack(1); return toItemStack(1);
} }
public void addDullEnchantment() public void addDullEnchantment()
{ {
_dullEnchantment = true; _dullEnchantment = true;
} }
public void removeDullEnchantment() public void removeDullEnchantment()
{ {
_dullEnchantment = false; _dullEnchantment = false;
} }
public void onInteract(PlayerInteractEvent event) public void onInteract(PlayerInteractEvent event)
{ {
for (ItemAttribute attribute : _attributes.getAttributes()) for (ItemAttribute attribute : _attributes.getAttributes())
@ -155,7 +138,7 @@ public class CustomItem implements Listener
attribute.onInteract(event); attribute.onInteract(event);
} }
} }
public void onAttack(CustomDamageEvent event) public void onAttack(CustomDamageEvent event)
{ {
for (ItemAttribute attribute : _attributes.getAttributes()) for (ItemAttribute attribute : _attributes.getAttributes())
@ -163,7 +146,7 @@ public class CustomItem implements Listener
attribute.onAttack(event); attribute.onAttack(event);
} }
} }
public void onAttacked(CustomDamageEvent event) public void onAttacked(CustomDamageEvent event)
{ {
for (ItemAttribute attribute : _attributes.getAttributes()) for (ItemAttribute attribute : _attributes.getAttributes())
@ -171,7 +154,7 @@ public class CustomItem implements Listener
attribute.onAttacked(event); attribute.onAttacked(event);
} }
} }
/** /**
* @param item - the item to check for a matching link * @param item - the item to check for a matching link
* @return true, if {@code item} matches this CustomItem via UUID, false * @return true, if {@code item} matches this CustomItem via UUID, false
@ -181,38 +164,40 @@ public class CustomItem implements Listener
{ {
return item.getUuid().equals(_uuid); return item.getUuid().equals(_uuid);
} }
/** /**
* Update {@code item} with the proper meta properties suited for this * Update {@code item} with the proper meta properties suited for this
* {@link CustomItem}. * {@link CustomItem}.
* *
* @param item - the item whose meta properties are being updated to become * @param item - the item whose meta properties are being updated to become
* a version of this updated custom item. * a version of this updated custom item.
*/ */
public void update(ItemStack item) public void update(ItemStack item)
{ {
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
String displayName = getDisplayName(); String displayName = getDisplayName();
List<String> lore = getLore(); List<String> lore = getLore();
meta.setDisplayName(displayName); meta.setDisplayName(displayName);
meta.setLore(lore); meta.setLore(lore);
item.setItemMeta(meta); item.setItemMeta(meta);
GearManager.writeNBT(this, item);
} }
public static String prettifyName(Material material) public static String prettifyName(Material material)
{ {
String name = ""; String name = "";
String[] words = material.toString().split("_"); String[] words = material.toString().split("_");
for (String word : words) for (String word : words)
{ {
word = word.toLowerCase(); word = word.toLowerCase();
name += word.substring(0, 1).toUpperCase() + word.substring(1) + " "; name += word.substring(0, 1).toUpperCase() + word.substring(1) + " ";
} }
return name; return name;
} }
@ -220,4 +205,9 @@ public class CustomItem implements Listener
{ {
return _material; return _material;
} }
public AttributeContainer getAttributes()
{
return _attributes;
}
} }

View File

@ -1,24 +1,29 @@
package mineplex.game.clans.items; package mineplex.game.clans.items;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.google.gson.JsonSyntaxException;
import mineplex.core.account.CoreClient;
import mineplex.core.common.Rank;
import mineplex.game.clans.clans.ClansManager;
import net.minecraft.server.v1_8_R3.NBTBase;
import net.minecraft.server.v1_8_R3.NBTTagByte;
import net.minecraft.server.v1_8_R3.NBTTagString;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerQuitEvent;
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;
@ -29,8 +34,6 @@ import com.google.gson.GsonBuilder;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
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.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.weight.Weight; import mineplex.core.common.weight.Weight;
import mineplex.core.common.weight.WeightSet; import mineplex.core.common.weight.WeightSet;
@ -62,14 +65,12 @@ import mineplex.game.clans.items.attributes.weapon.SharpAttribute;
import mineplex.game.clans.items.commands.GearCommand; import mineplex.game.clans.items.commands.GearCommand;
import mineplex.game.clans.items.economy.GoldToken; import mineplex.game.clans.items.economy.GoldToken;
import mineplex.game.clans.items.legendaries.AlligatorsTooth; import mineplex.game.clans.items.legendaries.AlligatorsTooth;
import mineplex.game.clans.items.legendaries.EnergyCrossbow;
import mineplex.game.clans.items.legendaries.GiantsBroadsword; import mineplex.game.clans.items.legendaries.GiantsBroadsword;
import mineplex.game.clans.items.legendaries.HyperAxe; import mineplex.game.clans.items.legendaries.HyperAxe;
import mineplex.game.clans.items.legendaries.LegendaryItem; import mineplex.game.clans.items.legendaries.LegendaryItem;
import mineplex.game.clans.items.legendaries.MagneticMaul; import mineplex.game.clans.items.legendaries.MagneticMaul;
import mineplex.game.clans.items.legendaries.MeridianScepter; import mineplex.game.clans.items.legendaries.MeridianScepter;
import mineplex.game.clans.items.legendaries.WindBlade; import mineplex.game.clans.items.legendaries.WindBlade;
import mineplex.game.clans.items.rares.Crossbow;
import mineplex.game.clans.items.rares.RareItem; import mineplex.game.clans.items.rares.RareItem;
import mineplex.game.clans.items.rares.RunedPickaxe; import mineplex.game.clans.items.rares.RunedPickaxe;
import mineplex.game.clans.items.smelting.SmeltingListener; import mineplex.game.clans.items.smelting.SmeltingListener;
@ -81,164 +82,183 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutSetSlot;
import net.minecraft.server.v1_8_R3.PacketPlayOutWindowItems; import net.minecraft.server.v1_8_R3.PacketPlayOutWindowItems;
/** /**
* Manages creation and retrieval of associated {@link PlayerGear}s with online * Handles converting legendary itemstacks to their respective CustomItem objects
* players, as well as offering methods for parsing and handling
* {@link CustomItem}s.
*
* @author MrTwiggy
*
*/ */
public class GearManager extends MiniPlugin implements IPacketHandler, Runnable public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
{ {
private static final Field UNHANDLED_TAGS_FIELD;
static
{
try
{
UNHANDLED_TAGS_FIELD = Class.forName("org.bukkit.craftbukkit.v1_8_R3.inventory.CraftMetaItem").getDeclaredField("unhandledTags");
UNHANDLED_TAGS_FIELD.setAccessible(true);
}
catch (Throwable t)
{
throw new RuntimeException("Error getting unhandledTags field", t);
}
}
private static final String ITEM_SERIALIZATION_TAG = "-JSON-"; private static final String ITEM_SERIALIZATION_TAG = "-JSON-";
private static Gson _gson; private static final Gson GSON;
private static GearManager _instance; // Singleton instance
// Weightings for randomly selecting number of attributes (1, 2, 3)
private Map<String, PlayerGear> _playerGears; // Mapping of player names private static final WeightSet<Integer> ATTRIBUTE_WEIGHTS = new WeightSet<>(
// (key) to cached gear set new Weight<>(3, 3),
// (value). new Weight<>(20, 2),
private WeightSet<Integer> _attributeWeights; // Weightings for randomly new Weight<>(77, 1)
// selecting number of );
// attributes (1, 2, 3)
private WeightSet<ItemType> _typeWeights; // Weightings for randomly // Weightings for randomly selecting item type (legendary/weapon/armor/bow)
// selecting item type private static final WeightSet<ItemType> TYPE_WEIGHTS = new WeightSet<>(
// (legendary/weapon/armor/bow) new Weight<>(6, ItemType.LEGENDARY),
private Set<String> _creativePlayers; // Set of names for all players new Weight<>(9, ItemType.RARE),
// currently in Creative gamemode new Weight<>(46 - 9, ItemType.ARMOR),
new Weight<>(25, ItemType.WEAPON),
// Legendary generation new Weight<>(23, ItemType.BOW)
public WeightSet<Class<? extends LegendaryItem>> LegendaryWeights; );
// Rare generation private static final WeightSet<Class<? extends LegendaryItem>> LEGENDARY_WEIGHTS = new WeightSet<>(
public WeightSet<Class<? extends RareItem>> RareWeights; MeridianScepter.class,
AlligatorsTooth.class,
// Weapon generation WindBlade.class,
public WeightSet<Material> WeaponTypes; GiantsBroadsword.class,
HyperAxe.class,
// Armor generation MagneticMaul.class
public WeightSet<Material> ArmorTypes; );
// Attribute generation private static final WeightSet<Class<? extends RareItem>> RARE_WEIGHTS = new WeightSet<>(
public WeightSet<Class<? extends ItemAttribute>> WeaponAttributes; RunedPickaxe.class
public WeightSet<Class<? extends ItemAttribute>> ArmorAttributes; );
public WeightSet<Class<? extends ItemAttribute>> BowAttributes;
private static final WeightSet<Material> WEAPON_TYPES = new WeightSet<>(
Material.DIAMOND_SWORD,
Material.GOLD_SWORD,
Material.IRON_SWORD,
Material.DIAMOND_AXE,
Material.GOLD_AXE,
Material.IRON_AXE
);
private static final WeightSet<Material> ARMOR_TYPES = new WeightSet<>(
Material.DIAMOND_HELMET,
Material.DIAMOND_CHESTPLATE,
Material.DIAMOND_LEGGINGS,
Material.DIAMOND_BOOTS,
Material.IRON_HELMET,
Material.IRON_CHESTPLATE,
Material.IRON_LEGGINGS,
Material.IRON_BOOTS,
Material.GOLD_HELMET,
Material.GOLD_CHESTPLATE,
Material.GOLD_LEGGINGS,
Material.GOLD_BOOTS
);
private static final WeightSet<Class<? extends ItemAttribute>> WEAPON_ATTRIBUTES = new WeightSet<>(
FrostedAttribute.class,
SharpAttribute.class,
JaggedAttribute.class,
HasteAttribute.class,
FlamingAttribute.class,
ConqueringAttribute.class
);
private static final WeightSet<Class<? extends ItemAttribute>> ARMOR_ATTRIBUTES = new WeightSet<>(
SlantedAttribute.class,
ReinforcedAttribute.class,
ConqueringArmorAttribute.class,
PaddedAttribute.class,
LavaAttribute.class
);
private static final WeightSet<Class<? extends ItemAttribute>> BOW_ATTRIBUTES = new WeightSet<>(
HeavyArrowsAttribute.class,
HuntingAttribute.class,
InverseAttribute.class,
LeechingAttribute.class,
RecursiveAttribute.class,
ScorchingAttribute.class,
SlayingAttribute.class
);
// Attribute Masks // Attribute Masks
private EnumSet<Material> _maskAttributes; private static final EnumSet<Material> MASK_ATTRIBUTES = EnumSet.of(
Material.GOLD_RECORD,
private GearShop _shop; Material.GREEN_RECORD,
Material.RECORD_3,
public GearManager(JavaPlugin plugin, PacketHandler packetHandler, CoreClientManager clientManager, DonationManager donationManager) Material.RECORD_4,
Material.RECORD_5,
Material.RECORD_6,
Material.RECORD_7,
Material.RECORD_8,
Material.RECORD_9,
Material.RECORD_10,
Material.RECORD_11,
Material.RECORD_12
);
static
{ {
super("CustomGear", plugin);
_instance = this;
_shop = new GearShop(this, clientManager, donationManager);
_creativePlayers = new HashSet<String>();
_playerGears = new HashMap<String, PlayerGear>();
// TODO: Introduce configurable non-hardcoded values for generation
// weights?
_attributeWeights = new WeightSet<Integer>(new Weight<Integer>(3, 3), new Weight<Integer>(20, 2), new Weight<Integer>(77, 1));
_typeWeights = new WeightSet<ItemType>(new Weight<ItemType>(6, ItemType.LEGENDARY),
new Weight<ItemType>(9, ItemType.RARE),
new Weight<ItemType>(46 - 9, ItemType.ARMOR),
new Weight<ItemType>(25, ItemType.WEAPON),
new Weight<ItemType>(23, ItemType.BOW));
// Weapon-based attributes
WeaponAttributes = new WeightSet<Class<? extends ItemAttribute>>(FrostedAttribute.class, SharpAttribute.class, JaggedAttribute.class, HasteAttribute.class, FlamingAttribute.class, ConqueringAttribute.class);
// Armor-based attributes
ArmorAttributes = new WeightSet<Class<? extends ItemAttribute>>(SlantedAttribute.class, ReinforcedAttribute.class, ConqueringArmorAttribute.class, PaddedAttribute.class, LavaAttribute.class);
// Bow-based attributes
BowAttributes = new WeightSet<Class<? extends ItemAttribute>>(HeavyArrowsAttribute.class, HuntingAttribute.class, InverseAttribute.class, LeechingAttribute.class, RecursiveAttribute.class, ScorchingAttribute.class, SlayingAttribute.class);
// Weapon material types
WeaponTypes = new WeightSet<Material>(Material.DIAMOND_SWORD, Material.GOLD_SWORD, Material.IRON_SWORD, Material.DIAMOND_AXE, Material.GOLD_AXE, Material.IRON_AXE);
// Armor material types
ArmorTypes = new WeightSet<Material>(Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS, Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS, Material.GOLD_HELMET, Material.GOLD_CHESTPLATE, Material.GOLD_LEGGINGS, Material.GOLD_BOOTS);
// TODO: Initialize list of attributes and types
// Initialize various LegendaryItem types
LegendaryWeights = new WeightSet<Class<? extends LegendaryItem>>(MeridianScepter.class, AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperAxe.class, MagneticMaul.class);
RareWeights = new WeightSet<Class<? extends RareItem>>(RunedPickaxe.class);
// TODO: Add rest of legendaries, find better way?
// Register listeners
UtilServer.getServer().getPluginManager().registerEvents(new ItemListener(getPlugin()), getPlugin());
UtilServer.getServer().getPluginManager().registerEvents(new SmeltingListener(), getPlugin());
// Initialize attribute types factory for JSON handling of polymorphism. // Initialize attribute types factory for JSON handling of polymorphism.
RuntimeTypeAdapterFactory<ItemAttribute> attributeFactory = RuntimeTypeAdapterFactory.of(ItemAttribute.class); RuntimeTypeAdapterFactory<ItemAttribute> attributeFactory = RuntimeTypeAdapterFactory.of(ItemAttribute.class);
ARMOR_ATTRIBUTES.elements().forEach(attributeFactory::registerSubtype);
for (Class<? extends ItemAttribute> attributeType : ArmorAttributes.elements()) WEAPON_ATTRIBUTES.elements().forEach(attributeFactory::registerSubtype);
{ BOW_ATTRIBUTES.elements().forEach(attributeFactory::registerSubtype);
attributeFactory.registerSubtype(attributeType);
} // Initialize legendary item type factory for JSON handling of polymorphism.
for (Class<? extends ItemAttribute> attributeType : WeaponAttributes.elements())
{
attributeFactory.registerSubtype(attributeType);
}
for (Class<? extends ItemAttribute> attributeType : BowAttributes.elements())
{
attributeFactory.registerSubtype(attributeType);
}
// Initialize legendary item type factory for JSON handling of
// polymorphism.
RuntimeTypeAdapterFactory<CustomItem> customItemType = RuntimeTypeAdapterFactory.of(CustomItem.class); RuntimeTypeAdapterFactory<CustomItem> customItemType = RuntimeTypeAdapterFactory.of(CustomItem.class);
customItemType.registerSubtype(CustomItem.class); customItemType.registerSubtype(CustomItem.class);
customItemType.registerSubtype(LegendaryItem.class); customItemType.registerSubtype(LegendaryItem.class);
customItemType.registerSubtype(RareItem.class); customItemType.registerSubtype(RareItem.class);
customItemType.registerSubtype(GoldToken.class); customItemType.registerSubtype(GoldToken.class);
for (Class<? extends CustomItem> itemType : LegendaryWeights.elements()) LEGENDARY_WEIGHTS.elements().forEach(customItemType::registerSubtype);
{ RARE_WEIGHTS.elements().forEach(customItemType::registerSubtype);
customItemType.registerSubtype(itemType);
}
for (Class<? extends RareItem> itemType : RareWeights.elements())
{
customItemType.registerSubtype(itemType);
}
// Build GSON instance off factories for future serialization of items.
_gson = new GsonBuilder().registerTypeAdapterFactory(attributeFactory).registerTypeAdapterFactory(customItemType).create();
packetHandler.addPacketHandler(this, PacketPlayOutSetSlot.class, PacketPlayOutWindowItems.class);
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 1l, 1l);
_maskAttributes = EnumSet.of(Material.GOLD_RECORD, Material.GREEN_RECORD, Material.RECORD_3, Material.RECORD_4, Material.RECORD_5, Material.RECORD_6, // Build GSON instance off factories for future serialization of items.
Material.RECORD_7, Material.RECORD_8, Material.RECORD_9, Material.RECORD_10, Material.RECORD_11, Material.RECORD_12); GSON = new GsonBuilder().registerTypeAdapterFactory(attributeFactory).registerTypeAdapterFactory(customItemType).create();
} }
private static Map<UUID, CustomItem> _customItemCache = new HashMap<>();
private static GearManager _instance; // Singleton instance
// Mapping of player names (key) to cached gear set (value).
private Map<Player, PlayerGear> _playerGears = new HashMap<>();
private GearShop _shop;
public GearManager(JavaPlugin plugin, PacketHandler packetHandler, CoreClientManager clientManager, DonationManager donationManager)
{
super("CustomGear", plugin);
if (_instance != null)
{
throw new RuntimeException("GearManager is already initialized");
}
_instance = this;
_shop = new GearShop(this, clientManager, donationManager);
// Register listeners
UtilServer.getServer().getPluginManager().registerEvents(new ItemListener(getPlugin()), getPlugin());
UtilServer.getServer().getPluginManager().registerEvents(new SmeltingListener(), getPlugin());
packetHandler.addPacketHandler(this, PacketPlayOutSetSlot.class, PacketPlayOutWindowItems.class);
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 1L, 1L);
}
@Override @Override
public void addCommands() public void addCommands()
{ {
addCommand(new GearCommand(this)); addCommand(new GearCommand(this));
} }
public void addCreativePlayer(Player player)
{
_creativePlayers.add(player.getName());
player.updateInventory();
}
public void removeCreativePlayer(Player player)
{
_creativePlayers.remove(player.getName());
player.updateInventory();
}
/** /**
* Tick & update internal logic for {@link GearManager}. Called once per * Tick & update internal logic for {@link GearManager}. Called once per tick.
* tick.
*/ */
@Override @Override
public void run() public void run()
@ -247,71 +267,64 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
while (iterator.hasNext()) while (iterator.hasNext())
{ {
PlayerGear gear = iterator.next(); PlayerGear gear = iterator.next();
if (gear.isOnline()) if (gear.cleanup())
{
gear.update();
}
else
{ {
iterator.remove(); iterator.remove();
} }
else
{
gear.update();
}
} }
} }
/** /**
* @param player - the player whose {@link PlayerGear} set is to be fetched. * @param player - the player whose {@link PlayerGear} set is to be fetched.
* @return the cached or newly instantiated {@link PlayerGear} associated * @return the cached or newly instantiated {@link PlayerGear} associated
* with {@code player}. * with {@code player}.
*/ */
public PlayerGear getPlayerGear(Player player) public PlayerGear getPlayerGear(Player player)
{ {
String playerName = player.getName(); return _playerGears.computeIfAbsent(player, PlayerGear::new);
if (!_playerGears.containsKey(playerName))
{
PlayerGear gear = new PlayerGear(playerName);
_playerGears.put(playerName, gear);
}
return _playerGears.get(playerName);
} }
public CustomItem generateItem() public CustomItem generateItem()
{ {
int attributeCount = _attributeWeights.generateRandom(); int attributeCount = ATTRIBUTE_WEIGHTS.generateRandom();
ItemType itemType = _typeWeights.generateRandom(); ItemType itemType = TYPE_WEIGHTS.generateRandom();
RareItemFactory factory = RareItemFactory.begin(itemType); RareItemFactory factory = RareItemFactory.begin(itemType);
if (itemType == ItemType.RARE) if (itemType == ItemType.RARE)
{ {
factory.setRare(RareWeights.generateRandom()); factory.setRare(RARE_WEIGHTS.generateRandom());
} }
else if (itemType == ItemType.LEGENDARY) else if (itemType == ItemType.LEGENDARY)
{ {
factory.setLegendary(LegendaryWeights.generateRandom()); factory.setLegendary(LEGENDARY_WEIGHTS.generateRandom());
} }
else if (itemType == ItemType.ARMOR) else if (itemType == ItemType.ARMOR)
{ {
factory.setType(ArmorTypes.generateRandom()); factory.setType(ARMOR_TYPES.generateRandom());
} }
else if (itemType == ItemType.WEAPON) else if (itemType == ItemType.WEAPON)
{ {
factory.setType(WeaponTypes.generateRandom()); factory.setType(WEAPON_TYPES.generateRandom());
} }
else if (itemType == ItemType.BOW) else if (itemType == ItemType.BOW)
{ {
factory.setType(Material.BOW); factory.setType(Material.BOW);
} }
if (itemType != ItemType.LEGENDARY) // Only non-legendaries have if (itemType != ItemType.LEGENDARY) // Only non-legendaries have
// attributes // attributes
{ {
AttributeContainer attributes = new AttributeContainer(); AttributeContainer attributes = new AttributeContainer();
generateAttributes(attributes, itemType, attributeCount); generateAttributes(attributes, itemType, attributeCount);
System.out.println("Generating attributes..."); System.out.println("Generating attributes...");
System.out.println("Remaining size: " + attributes.getRemainingTypes().size()); System.out.println("Remaining size: " + attributes.getRemainingTypes().size());
if (attributes.getSuperPrefix() != null) if (attributes.getSuperPrefix() != null)
{ {
System.out.println("Set super prefix: " + attributes.getSuperPrefix().getClass()); System.out.println("Set super prefix: " + attributes.getSuperPrefix().getClass());
@ -328,10 +341,10 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
factory.setSuffix(attributes.getSuffix().getClass()); factory.setSuffix(attributes.getSuffix().getClass());
} }
} }
return factory.getWrapper(); return factory.getWrapper();
} }
private void generateAttributes(AttributeContainer container, ItemType type, int count) private void generateAttributes(AttributeContainer container, ItemType type, int count)
{ {
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@ -339,90 +352,166 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
int attempts = 0; int attempts = 0;
Set<AttributeType> remaining = container.getRemainingTypes(); Set<AttributeType> remaining = container.getRemainingTypes();
ItemAttribute attribute = null; ItemAttribute attribute = null;
while (remaining.size() > 0 && attempts < 10 && attribute == null) while (remaining.size() > 0 && attempts < 10 && attribute == null)
{ {
ItemAttribute sampleAttribute = null; ItemAttribute sampleAttribute = null;
switch (type) switch (type)
{ {
case ARMOR: case ARMOR:
sampleAttribute = instantiate(ArmorAttributes.generateRandom()); sampleAttribute = instantiate(ARMOR_ATTRIBUTES.generateRandom());
break; break;
case WEAPON: case WEAPON:
sampleAttribute = instantiate(WeaponAttributes.generateRandom()); sampleAttribute = instantiate(WEAPON_ATTRIBUTES.generateRandom());
break; break;
case BOW: case BOW:
sampleAttribute = instantiate(BowAttributes.generateRandom()); sampleAttribute = instantiate(BOW_ATTRIBUTES.generateRandom());
break; break;
default: default:
break; break;
} }
if (sampleAttribute != null && remaining.contains(sampleAttribute.getType())) if (sampleAttribute != null && remaining.contains(sampleAttribute.getType()))
{ {
attribute = sampleAttribute; // Select valid attribute to attribute = sampleAttribute; // Select valid attribute to add
// add
} }
attempts++; attempts++;
} }
container.addAttribute(attribute); container.addAttribute(attribute);
} }
} }
public void spawnItem(Location location) public void spawnItem(Location location)
{ {
CustomItem item = generateItem(); CustomItem item = generateItem();
location.getWorld().dropItem(location, item.toItemStack()); location.getWorld().dropItem(location, item.toItemStack());
} }
public static CustomItem parseItem(ItemStack item) public static CustomItem parseItem(ItemStack item)
{ {
String serialization = getItemSerialization(item); if (item == null)
if (serialization != null)
{ {
CustomItem customItem = null; return null;
}
Map<String, NBTBase> data = getUnhandledTags(item);
if (data == null)
{
return null;
}
if (data.containsKey("gearmanager.uuid"))
{
String strUUID = ((NBTTagString) data.get("gearmanager.uuid")).a_();
try try
{ {
customItem = deserialize(serialization); UUID uuid = UUID.fromString(strUUID);
CustomItem customItem = _customItemCache.get(uuid);
if (customItem == null)
{
String json = ((NBTTagString) data.get("gearmanager.json")).a_();
customItem = deserialize(json);
_customItemCache.put(uuid, customItem);
}
return customItem;
} }
// Not an UUID?
catch (IllegalArgumentException exception)
{
if (!data.containsKey("gearmanager.warnuuid"))
{
// Add to the lore that this item is corrupted
List<String> lore = item.getItemMeta().getLore();
lore.add("");
lore.add(C.cRedB + "Corrupted item (Error 1)");
data.put("gearmanager.warnuuid", new NBTTagByte((byte) 1));
exception.printStackTrace();
saveUnhandledTags(item, data);
}
return null;
}
// Failed to parse
catch (JsonSyntaxException exception)
{
if (!data.containsKey("gearmanager.warnsyntax"))
{
// Add to the lore that this item is corrupted
List<String> lore = item.getItemMeta().getLore();
lore.add("");
lore.add(C.cRedB + "Corrupted item (Error 2)");
data.put("gearmanager.warnsyntax", new NBTTagByte((byte) 1));
System.out.println(((NBTTagString) data.get("gearmanager.json")).a_());
exception.printStackTrace();
saveUnhandledTags(item, data);
}
return null;
}
// Other
catch (Exception exception) catch (Exception exception)
{ {
exception.printStackTrace(); if (!data.containsKey("gearmanager.warnother"))
System.out.println("=========="); {
System.out.println("GearManager parse problem :"); // Add to the lore that this item is corrupted
System.out.println(serialization); List<String> lore = item.getItemMeta().getLore();
System.out.println("=========="); lore.add("");
lore.add(C.cRedB + "Corrupted item (Error 3)");
data.put("gearmanager.warnother", new NBTTagByte((byte) 1));
exception.printStackTrace();
saveUnhandledTags(item, data);
}
return null;
} }
return customItem;
} }
else // This is stored in the old format
return null; // No serialization found in item's lore, not a custom {
// item! String serialization = getItemSerialization(item);
if (serialization == null)
{
return null;
}
try
{
CustomItem customItem = deserialize(serialization);
data.put("gearmanager.uuid", new NBTTagString(customItem._uuid));
data.put("gearmanager.json", new NBTTagString(serialization));
saveUnhandledTags(item, data);
_customItemCache.put(UUID.fromString(customItem._uuid), customItem);
return customItem;
}
catch (Exception e)
{
System.out.println(serialization);
e.printStackTrace();
}
return null;
}
} }
public static void writeNBT(CustomItem customItem, ItemStack item)
{
Map<String, NBTBase> data = getUnhandledTags(item);
data.put("gearmanager.uuid", new NBTTagString(customItem._uuid));
data.put("gearmanager.json", new NBTTagString(serialize(customItem)));
saveUnhandledTags(item, data);
}
public static boolean isCustomItem(ItemStack item) public static boolean isCustomItem(ItemStack item)
{ {
Map<String, NBTBase> data = getUnhandledTags(item);
if (data.containsKey("gearmanager.uuid") && data.containsKey("gearmanager.json"))
{
return true;
}
return getItemSerialization(item) != null; return getItemSerialization(item) != null;
} }
public static String getItemSerialization(CustomItem customItem)
{
String serialization = serialize(customItem);
return ITEM_SERIALIZATION_TAG + serialization;
}
/** /**
* @param type - the class-type of the object to be instantiated. (must have * @param type - the class-type of the object to be instantiated. (must have
* zero-argument constructor) * zero-argument constructor)
* @return a newly instantiated instance of {@code type} class-type. * @return a newly instantiated instance of {@code type} class-type.
* Instantied with zero argument constructor. * Instantied with zero argument constructor.
*/ */
private static <T> T instantiate(Class<T> type) private static <T> T instantiate(Class<T> type)
{ {
@ -435,49 +524,39 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
return null; return null;
} }
} }
@Deprecated
private static String getItemSerialization(ItemStack item) private static String getItemSerialization(ItemStack item)
{ {
if (item == null || item.getItemMeta() == null || item.getItemMeta().getLore() == null) return null; if (item == null || item.getItemMeta() == null || item.getItemMeta().getLore() == null) return null;
// fixme Each call to getItemMeta creates a new ItemMeta, a clone of an ArrayList, and a clone of a Hashmap
// Each call to getLore re-clones that ArrayList again
// Reflection may be too slow, but perhaps MethodHandles would be good?
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
for (String lore : meta.getLore()) for (String lore : meta.getLore())
{ {
if (lore.startsWith(ITEM_SERIALIZATION_TAG)) // Found serialization if (lore.startsWith(ITEM_SERIALIZATION_TAG))
// lore-line
{ {
int tagLength = ITEM_SERIALIZATION_TAG.length(); int tagLength = ITEM_SERIALIZATION_TAG.length();
String serialization = lore.substring(tagLength); return lore.substring(tagLength);
return serialization;
} }
} }
return null; // Unable to find any serialized lore lines, hence not a return null; // Unable to find any serialized lore lines, hence not a CustomItem.
// CustomItem.
} }
public static String serialize(CustomItem customItem) public static String serialize(CustomItem customItem)
{ {
return _gson.toJson(customItem, CustomItem.class); return GSON.toJson(customItem, CustomItem.class);
} }
public static String serialize(AttributeContainer attributes)
{
return _gson.toJson(attributes, AttributeContainer.class);
}
public static CustomItem deserialize(String serialization) public static CustomItem deserialize(String serialization)
{ {
return _gson.fromJson(serialization, CustomItem.class); return GSON.fromJson(serialization, CustomItem.class);
} }
public static <T> T deserialize(String serialization, Class<T> type)
{
return _gson.fromJson(serialization, type);
}
/** /**
* @return singleton instance of {@link GearManager}. * @return singleton instance of {@link GearManager}.
*/ */
@ -485,48 +564,41 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
{ {
return _instance; return _instance;
} }
public static void notify(Player player, String message)
{
UtilPlayer.message(player, F.main("Gear", message));
}
/** /**
* @param player - the player to see if they should have their out-going * @param player - the player to see if they should have their out-going
* packets masked on CustomGear items. * packets masked on CustomGear items.
* @return true, if the player should have their gear lore masked, false * @return true, if the player should have their gear lore masked, false
* otherwise. * otherwise.
*/ */
private boolean maskGearPacket(Player player) private boolean maskGearPacket(Player player)
{ {
return player.getGameMode() != GameMode.CREATIVE && !_creativePlayers.contains(player.getName()); return player.getGameMode() != GameMode.CREATIVE;
} }
public void handle(PacketInfo packetInfo) public void handle(PacketInfo packetInfo)
{ {
// Don't mask custom gear lore for creative players, as this will break // Don't mask custom gear lore for creative players, as this will break them.
// them. // To be precise, the lore is added more than once because the creative client spawns in new items with the existing lore
// fixme
if (!maskGearPacket(packetInfo.getPlayer())) return; if (!maskGearPacket(packetInfo.getPlayer())) return;
Packet<?> packet = packetInfo.getPacket(); Packet<?> packet = packetInfo.getPacket();
if (packet instanceof PacketPlayOutSetSlot) if (packet instanceof PacketPlayOutSetSlot)
{ {
PacketPlayOutSetSlot slotPacket = (PacketPlayOutSetSlot) packet; PacketPlayOutSetSlot slotPacket = (PacketPlayOutSetSlot) packet;
slotPacket.c = maskItem(slotPacket.c, packetInfo.getPlayer()); // Mask all out-going item slotPacket.c = maskItem(slotPacket.c, packetInfo.getPlayer()); // Mask all out-going item packets
// packets
} }
else if (packet instanceof PacketPlayOutWindowItems) else if (packet instanceof PacketPlayOutWindowItems)
{ {
PacketPlayOutWindowItems itemsPacket = (PacketPlayOutWindowItems) packet; PacketPlayOutWindowItems itemsPacket = (PacketPlayOutWindowItems) packet;
for (int i = 0; i < itemsPacket.b.length; i++) for (int i = 0; i < itemsPacket.b.length; i++)
{ {
itemsPacket.b[i] = maskItem(itemsPacket.b[i], packetInfo.getPlayer()); // Mask all itemsPacket.b[i] = maskItem(itemsPacket.b[i], packetInfo.getPlayer()); // Mask all out-going item packets
// out-going
// item packets
ItemStack item = CraftItemStack.asCraftMirror(itemsPacket.b[i]); ItemStack item = CraftItemStack.asCraftMirror(itemsPacket.b[i]);
if (item != null && _maskAttributes.contains(item.getType())) if (item != null && MASK_ATTRIBUTES.contains(item.getType()))
itemsPacket.b[i] = removeAttributes(itemsPacket.b[i]); itemsPacket.b[i] = removeAttributes(itemsPacket.b[i]);
} }
} }
@ -545,7 +617,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
return item; return item;
} }
private net.minecraft.server.v1_8_R3.ItemStack maskItem(net.minecraft.server.v1_8_R3.ItemStack item, Player player) private net.minecraft.server.v1_8_R3.ItemStack maskItem(net.minecraft.server.v1_8_R3.ItemStack item, Player player)
{ {
// Cannot mask a null item // Cannot mask a null item
@ -553,44 +625,145 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
{ {
return null; return null;
} }
CraftItemStack originalItem = CraftItemStack.asCraftMirror(item); CraftItemStack originalItem = CraftItemStack.asCraftMirror(item);
ItemMeta originalMeta = originalItem.getItemMeta(); ItemMeta originalMeta = originalItem.getItemMeta();
// No need to modify item packets with no lore // No need to modify item packets with no lore
if (originalMeta == null || originalMeta.getLore() == null) if (originalMeta == null || originalMeta.getLore() == null)
{ {
return item; return item;
} }
List<String> lore = new ArrayList<String>(); List<String> newLore = cleanseLore(originalMeta.getLore());
CustomItem ci = parseItem(originalItem); CustomItem ci = parseItem(originalItem);
for (String line : originalMeta.getLore()) if (ci != null && LEGENDARY_WEIGHTS.elements().contains(ci.getClass()))
{ {
if (!line.startsWith(ITEM_SERIALIZATION_TAG)) String originalOwner = null;
if (ci.OriginalOwner == null)
{ {
lore.add(line); originalOwner = "You";
} }
else
{
if (player.getUniqueId().toString().equals(ci.OriginalOwner))
{
originalOwner = "You";
}
else
{
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(ci.OriginalOwner));
originalOwner = offlinePlayer.getName();
}
}
newLore.add(" ");
newLore.add(C.cWhite + "Original Owner: " + C.cYellow + originalOwner);
} }
if (ci != null)
if (ci != null && LegendaryWeights.elements().contains(ci.getClass()))
{ {
lore.add(" "); newLore.add(" ");
lore.add(C.cWhite + "Original Owner: " + C.cYellow + (ci.OriginalOwner == null ? "You" : Bukkit.getOfflinePlayer(UUID.fromString(ci.OriginalOwner)).getName())); newLore.add(C.cWhite + "UUID: " + C.cYellow + ci._uuid);
} }
net.minecraft.server.v1_8_R3.ItemStack newItem = CraftItemStack.asNMSCopy(originalItem); net.minecraft.server.v1_8_R3.ItemStack newItem = CraftItemStack.asNMSCopy(originalItem);
CraftItemStack newCopy = CraftItemStack.asCraftMirror(newItem); CraftItemStack newCopy = CraftItemStack.asCraftMirror(newItem);
ItemMeta newMeta = newCopy.getItemMeta(); ItemMeta newMeta = newCopy.getItemMeta();
newMeta.setLore(lore); newMeta.setLore(newLore);
newCopy.setItemMeta(newMeta); newCopy.setItemMeta(newMeta);
return newItem; return newItem;
} }
private List<String> cleanseLore(List<String> input)
{
List<String> cleansed = new ArrayList<>();
for (String s : input)
{
if (!s.startsWith(ITEM_SERIALIZATION_TAG))
{
cleansed.add(s);
}
}
return cleansed;
}
public void openShop(Player player) public void openShop(Player player)
{ {
_shop.attemptShopOpen(player); _shop.attemptShopOpen(player);
} }
// WARNING
// This will not be persistent if the ItemStack is a block and placed then picked up
private static Map<String, NBTBase> getUnhandledTags(ItemStack itemStack)
{
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null)
{
return null;
}
try
{
return (Map<String, NBTBase>) UNHANDLED_TAGS_FIELD.get(itemMeta);
}
catch (IllegalAccessException e)
{
System.out.println("Could not get unhandledTags");
e.printStackTrace();
}
return null;
}
private static void saveUnhandledTags(ItemStack itemStack, Map<String, NBTBase> map)
{
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null)
{
return;
}
try
{
UNHANDLED_TAGS_FIELD.set(itemMeta, map);
}
catch (IllegalAccessException e)
{
System.out.println("Could not get unhandledTags");
e.printStackTrace();
}
itemStack.setItemMeta(itemMeta);
}
public static void save(ItemStack itemStack, boolean remove)
{
CustomItem item = parseItem(itemStack);
if (item != null)
{
Map<String, NBTBase> data = getUnhandledTags(itemStack);
data.put("gearmanager.json", new NBTTagString(serialize(item)));
saveUnhandledTags(itemStack, data);
if (remove)
{
_customItemCache.remove(item);
}
}
}
public static void cleanup()
{
Iterator<CustomItem> it = _customItemCache.values().iterator();
while (it.hasNext())
{
CustomItem item = it.next();
if (item.OriginalOwner != null)
{
UUID uuid = UUID.fromString(item.OriginalOwner);
Player player = Bukkit.getPlayer(uuid);
if (player == null || !player.isOnline())
{
UtilServer.Unregister(item);
it.remove();
}
}
}
}
} }

View File

@ -1,5 +1,10 @@
package mineplex.game.clans.items; package mineplex.game.clans.items;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilOfflinePlayer;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import net.minecraft.server.v1_8_R3.PlayerInventory;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -14,6 +19,8 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -23,100 +30,75 @@ import mineplex.game.clans.items.attributes.ItemAttribute;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
/** /**
* Listens for item-related trigger events and accordingly triggers appropriate * Listens for item-related trigger events and accordingly triggers appropriate
* {@link PlayerGear} events for {@link CustomItem} abilities and attributes. * {@link PlayerGear} events for {@link CustomItem} abilities and attributes.
* @author MrTwiggy
* *
* @author MrTwiggy
*/ */
public class ItemListener implements Listener public class ItemListener implements Listener, Runnable
{ {
private static final String PROJECTILE_META_TAG = "[CustomGearProj]";
public static final String PROJECTILE_META_TAG = "[CustomGearProj]";
private JavaPlugin _plugin; private JavaPlugin _plugin;
public ItemListener(JavaPlugin plugin) public ItemListener(JavaPlugin plugin)
{ {
_plugin = plugin; _plugin = plugin;
_plugin.getServer().getScheduler().runTaskTimer(_plugin, this, 20 * 60 * 5, 0);
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) @Override
public void onGamemodeChange(PlayerGameModeChangeEvent event) public void run()
{ {
if (event.getNewGameMode() == GameMode.CREATIVE) // Entering creative mode for (Player player : UtilServer.getPlayersCollection())
{ {
GearManager.getInstance().addCreativePlayer(event.getPlayer()); save(player, false);
} }
else if (event.getPlayer().getGameMode() == GameMode.CREATIVE) // Exiting creative mode GearManager.cleanup();
}
@EventHandler(priority = EventPriority.LOWEST)
public void on(PlayerQuitEvent event)
{
save(event.getPlayer(), true);
}
private void save(Player player, boolean remove)
{
for (ItemStack item : UtilInv.getItems(player))
{ {
GearManager.getInstance().removeCreativePlayer(event.getPlayer()); GearManager.save(item, remove);
// Update/refresh the players inventory in 5 ticks once they're in survival mode again
final Player player = event.getPlayer();
Bukkit.getScheduler().runTaskLater(_plugin, new Runnable()
{
@Override
public void run()
{
player.updateInventory();
}
}, 5l);
} }
} }
/**
* Handle players shuffling CustomItems around by properly updating
* and managing their movement.
* @param event
*/
@EventHandler
public void onInventoryClick(InventoryClickEvent event)
{
// TODO: Update any custom-items that are selected/moved to save proper stats if they
// TODO: are active. (IE: PlayerGear possesses it as armor slot or weapon)
}
/**
* Handle updated CustomItem stats and lore upon player
* switching items.
* @param event
*/
@EventHandler
public void onItemHeldChanged(PlayerItemHeldEvent event)
{
Player player = event.getPlayer();
PlayerGear gear = getGear(player);
gear.onItemHeldChanged(event);
}
/** /**
* Handle the trigger of custom gear related effects and abilities. * Handle the trigger of custom gear related effects and abilities.
*
* @param event * @param event
*/ */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerAttack(CustomDamageEvent event) public void onPlayerAttack(CustomDamageEvent event)
{ {
if (event.IsCancelled()) return; // Checks for Pre-Cancelled event and stops if (event.IsCancelled()) return; // Checks for Pre-Cancelled event and stops
Player damager = event.GetDamagerPlayer(false); // For non-ranged attacks Player damager = event.GetDamagerPlayer(false); // For non-ranged attacks
Player damagee = event.GetDamageePlayer(); Player damagee = event.GetDamageePlayer();
Projectile projectile = event.GetProjectile(); Projectile projectile = event.GetProjectile();
// Trigger custom gear effects for attacker melee weapons // Trigger custom gear effects for attacker melee weapons
if (damager != null && event.GetCause() == DamageCause.ENTITY_ATTACK) if (damager != null && event.GetCause() == DamageCause.ENTITY_ATTACK)
{ {
PlayerGear attackerGear = getGear(damager); PlayerGear attackerGear = getGear(damager);
attackerGear.onAttack(event); attackerGear.onAttack(event);
} }
// Trigger custom gear effects for defender armor // Trigger custom gear effects for defender armor
if (damagee != null) if (damagee != null)
{ {
PlayerGear defenderGear = getGear(damagee); PlayerGear defenderGear = getGear(damagee);
defenderGear.onAttacked(event); defenderGear.onAttacked(event);
} }
// Trigger bow-related attribute effects properly // Trigger bow-related attribute effects properly
if (projectile != null) if (projectile != null)
{ {
@ -124,9 +106,8 @@ public class ItemListener implements Listener
{ {
for (MetadataValue data : projectile.getMetadata(PROJECTILE_META_TAG)) for (MetadataValue data : projectile.getMetadata(PROJECTILE_META_TAG))
{ {
String serialization = data.asString(); AttributeContainer container = (AttributeContainer) data.value();
AttributeContainer container = GearManager.deserialize(serialization, AttributeContainer.class);
for (ItemAttribute attribute : container.getAttributes()) for (ItemAttribute attribute : container.getAttributes())
{ {
attribute.onAttack(event); attribute.onAttack(event);
@ -135,9 +116,10 @@ public class ItemListener implements Listener
} }
} }
} }
/** /**
* Properly marks projectiles shot from a custom-gear bow so that it will properly trigger events. * Properly marks projectiles shot from a custom-gear bow so that it will properly trigger events.
*
* @param event * @param event
*/ */
@EventHandler @EventHandler
@ -147,24 +129,24 @@ public class ItemListener implements Listener
{ {
Player player = (Player) event.getEntity(); Player player = (Player) event.getEntity();
PlayerGear gear = getGear(player); PlayerGear gear = getGear(player);
CustomItem weapon = gear.getWeapon(); CustomItem weapon = gear.getWeapon();
if (weapon != null) if (weapon != null)
{ {
// Copy weapon attributes onto projectile for later processing // Copy weapon attributes onto projectile for later processing
AttributeContainer attributes = weapon.getAttributes(); AttributeContainer attributes = weapon.getAttributes();
String serialization = GearManager.serialize(attributes);
Entity projectile = event.getProjectile(); Entity projectile = event.getProjectile();
projectile.setMetadata(PROJECTILE_META_TAG, new FixedMetadataValue(_plugin, serialization)); projectile.setMetadata(PROJECTILE_META_TAG, new FixedMetadataValue(_plugin, attributes));
} }
} }
} }
/** /**
* Handle weapon ability activation of custom gear. * Handle weapon ability activation of custom gear.
*
* @param event * @param event
*/ */
@EventHandler @EventHandler
@ -174,7 +156,7 @@ public class ItemListener implements Listener
PlayerGear playerGear = getGear(event.getPlayer()); PlayerGear playerGear = getGear(event.getPlayer());
playerGear.onInteract(event); playerGear.onInteract(event);
} }
/** /**
* @param player - the player whose gear is to be fetched * @param player - the player whose gear is to be fetched
* @return the {@link PlayerGear} associated with {@code player}. * @return the {@link PlayerGear} associated with {@code player}.

View File

@ -2,6 +2,7 @@ package mineplex.game.clans.items;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -27,23 +28,13 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
*/ */
public class PlayerGear public class PlayerGear
{ {
private String _playerName; // Name of player who owns the gear private boolean _cleanedUp = false;
// Cached custom item information for player's gear private Player _owner;
private CustomItem _weapon;
private CustomItem _helmet; public PlayerGear(Player owner)
private CustomItem _chestplate;
private CustomItem _leggings;
private CustomItem _boots;
/**
* Class constructor
*
* @param playerName
*/
public PlayerGear(String playerName)
{ {
_playerName = playerName; this._owner = owner;
} }
/** /**
@ -52,7 +43,7 @@ public class PlayerGear
*/ */
public void update() public void update()
{ {
if (isOnline()) if (_owner.isOnline())
{ {
CustomItem item = getWeapon(); CustomItem item = getWeapon();
@ -65,38 +56,22 @@ public class PlayerGear
if (legendary.OriginalOwner == null) if (legendary.OriginalOwner == null)
{ {
legendary.OriginalOwner = getPlayer().getUniqueId().toString(); legendary.OriginalOwner = getPlayer().getUniqueId().toString();
getPlayer().setItemInHand(legendary.toItemStack());
} }
} }
} }
} }
public boolean isOnline()
{
Player player = getPlayer();
return player != null && player.isOnline();
}
/** /**
* @return the {@link Player} that owns this gear set. * @return the {@link Player} that owns this gear set.
*/ */
public Player getPlayer() public Player getPlayer()
{ {
return Bukkit.getPlayer(_playerName); return this._owner;
}
/**
* @return the {@link PlayerInventory} associated with the owner of this
* {@link PlayerGear}.
*/
public PlayerInventory getInventory()
{
return getPlayer().getInventory();
} }
public String getPlayerName() public String getPlayerName()
{ {
return _playerName; return getPlayer().getName();
} }
/** /**
@ -107,11 +82,9 @@ public class PlayerGear
*/ */
public void onInteract(PlayerInteractEvent event) public void onInteract(PlayerInteractEvent event)
{ {
for (CustomItem item : getGear()) forEachGear(item -> item.onInteract(event));
{
item.onInteract(event);
}
} }
/** /**
* Trigger on-attack events for the set of equipped {@link CustomItem}s in * Trigger on-attack events for the set of equipped {@link CustomItem}s in
@ -121,10 +94,7 @@ public class PlayerGear
*/ */
public void onAttack(CustomDamageEvent event) public void onAttack(CustomDamageEvent event)
{ {
for (CustomItem item : getGear()) forEachGear(item -> item.onAttack(event));
{
item.onAttack(event);
}
} }
/** /**
@ -135,118 +105,68 @@ public class PlayerGear
*/ */
public void onAttacked(CustomDamageEvent event) public void onAttacked(CustomDamageEvent event)
{ {
for (CustomItem item : getGear()) forEachGear(item -> item.onAttacked(event));
{
item.onAttacked(event);
}
} }
/** private void forEachGear(Consumer<CustomItem> itemConsumer)
* Update appropriate gear status and item lores.
*
* @param event - the triggering item held change event.
*/
public void onItemHeldChanged(PlayerItemHeldEvent event)
{ {
ItemStack item = getPlayer().getItemInHand();
CustomItem weapon = getWeapon(); CustomItem weapon = getWeapon();
if (weapon != null) if (weapon != null)
{ {
weapon.update(item); // Update held-item's stats. itemConsumer.accept(weapon);
}
CustomItem helmet = getHelmet();
if (helmet != null)
{
itemConsumer.accept(helmet);
}
CustomItem chestplate = getChestplate();
if (chestplate != null)
{
itemConsumer.accept(chestplate);
}
CustomItem leggings = getLeggings();
if (leggings != null)
{
itemConsumer.accept(leggings);
}
CustomItem boots = getBoots();
if (boots != null)
{
itemConsumer.accept(boots);
} }
} }
public CustomItem getWeapon() public CustomItem getWeapon()
{ {
ItemStack weaponItem = getPlayer().getInventory().getItemInHand(); return GearManager.parseItem(getPlayer().getInventory().getItemInHand());
if (!itemsMatch(_weapon, weaponItem))
{
_weapon = parseItem(weaponItem);
}
return _weapon;
} }
public CustomItem getHelmet() public CustomItem getHelmet()
{ {
ItemStack helmetItem = getPlayer().getInventory().getHelmet(); return GearManager.parseItem(getPlayer().getInventory().getHelmet());
if (!itemsMatch(_helmet, helmetItem))
{
_helmet = parseItem(helmetItem);
}
return _helmet;
} }
public CustomItem getChestplate() public CustomItem getChestplate()
{ {
ItemStack chestplateItem = getPlayer().getInventory().getChestplate(); return GearManager.parseItem(getPlayer().getInventory().getChestplate());
if (!itemsMatch(_chestplate, chestplateItem))
{
_chestplate = parseItem(chestplateItem);
}
return _chestplate;
} }
public CustomItem getLeggings() public CustomItem getLeggings()
{ {
ItemStack leggingsItem = getPlayer().getInventory().getLeggings(); return GearManager.parseItem(getPlayer().getInventory().getLeggings());
if (!itemsMatch(_leggings, leggingsItem))
{
_leggings = parseItem(leggingsItem);
}
return _leggings;
} }
public CustomItem getBoots() public CustomItem getBoots()
{ {
ItemStack bootsItem = getPlayer().getInventory().getBoots(); return GearManager.parseItem(getPlayer().getInventory().getBoots());
if (!itemsMatch(_boots, bootsItem))
{
_boots = parseItem(bootsItem);
}
return _boots;
} }
/** /*
* @return set of currently equipped {@link CustomItem}s in the gear set. * Perform cleanup if necessary. If cleanup was performed, return true. Otherwise return false
*/ */
public Set<CustomItem> getGear() public boolean cleanup()
{ {
Set<CustomItem> items = new HashSet<CustomItem>(); return !getPlayer().isOnline();
if (getWeapon() != null) items.add(getWeapon());
if (getHelmet() != null) items.add(getHelmet());
if (getChestplate() != null) items.add(getChestplate());
if (getLeggings() != null) items.add(getLeggings());
if (getBoots() != null) items.add(getBoots());
return items;
}
private boolean itemsMatch(CustomItem customItem, ItemStack item)
{
if (customItem == null || item == null) return false;
if (GearManager.isCustomItem(item))
{
CustomItem customItem2 = GearManager.parseItem(item);
return customItem2.matches(customItem);
}
return false;
}
private CustomItem parseItem(ItemStack item)
{
return GearManager.parseItem(item);
} }
} }

View File

@ -7,7 +7,7 @@ import mineplex.game.clans.items.CustomItem;;
public class GoldToken extends CustomItem public class GoldToken extends CustomItem
{ {
private int _goldValue; private int _goldValue;
public GoldToken() public GoldToken()
{ {
this(0); this(0);

View File

@ -1,13 +1,9 @@
package mineplex.game.clans.items.legendaries; package mineplex.game.clans.items.legendaries;
import java.util.Arrays; import mineplex.core.common.util.UtilAction;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -18,12 +14,11 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class AlligatorsTooth extends LegendaryItem public class AlligatorsTooth extends LegendaryItem
{ {
private static ValueDistribution boostGen = generateDistribution(0.8d, 1.4d); private static ValueDistribution BOOST_GEN = generateDistribution(0.8d, 1.4d);
private static double LAND_DAMAGE_BONUS = 7;
private double _landDamageBonus = 7; private static double WATER_DAMAGE_BONUS = 11;
private double _waterDamageBonus = 11;
private double _swimSpeed; private double _swimSpeed;
private int _soundUpdateCounter; private int _soundUpdateCounter;
public AlligatorsTooth() public AlligatorsTooth()
@ -38,7 +33,7 @@ public class AlligatorsTooth extends LegendaryItem
C.cYellow + "Right-Click" + C.cWhite + " to use" + C.cGreen + " Swim", C.cYellow + "Right-Click" + C.cWhite + " to use" + C.cGreen + " Swim",
}, Material.RECORD_4); }, Material.RECORD_4);
_swimSpeed = boostGen.generateValue(); _swimSpeed = BOOST_GEN.generateValue();
} }
@Override @Override
@ -46,8 +41,7 @@ public class AlligatorsTooth extends LegendaryItem
{ {
if (isInWater(wielder)) if (isInWater(wielder))
{ {
// Player gain water breathing while under water with legendary // Player gain water breathing while under water with legendary equipped
// equipped
grantPotionEffect(wielder, PotionEffectType.WATER_BREATHING, 0, 50); grantPotionEffect(wielder, PotionEffectType.WATER_BREATHING, 0, 50);
if (isHoldingRightClick()) if (isHoldingRightClick())
@ -56,7 +50,6 @@ public class AlligatorsTooth extends LegendaryItem
if (++_soundUpdateCounter % 3 == 0) if (++_soundUpdateCounter % 3 == 0)
{ {
wielder.playSound(wielder.getLocation(), Sound.SPLASH2, .5f, 1.25f); wielder.playSound(wielder.getLocation(), Sound.SPLASH2, .5f, 1.25f);
wielder.getLocation().getWorld().playEffect(wielder.getLocation(), Effect.STEP_SOUND, Material.LAPIS_BLOCK.getId()); wielder.getLocation().getWorld().playEffect(wielder.getLocation(), Effect.STEP_SOUND, Material.LAPIS_BLOCK.getId());
} }
} }
@ -68,12 +61,12 @@ public class AlligatorsTooth extends LegendaryItem
{ {
if (isInWater(wielder)) if (isInWater(wielder))
{ {
event.AddMod("Alligators Tooth", _waterDamageBonus); event.AddMod("Alligators Tooth Water Bonus", WATER_DAMAGE_BONUS);
event.AddKnockback("Alligators Tooth", 0.5d); event.AddKnockback("Alligators Tooth Water Bonus", 0.5d);
} }
else else
{ {
event.AddMod("Alligators Tooth", _landDamageBonus); event.AddMod("Alligators Tooth Land Bonus", LAND_DAMAGE_BONUS);
} }
} }
@ -87,6 +80,7 @@ public class AlligatorsTooth extends LegendaryItem
private boolean isInWater(Player player) private boolean isInWater(Player player)
{ {
return player.getLocation().getBlock().getType() == Material.WATER || player.getLocation().getBlock().getType() == Material.STATIONARY_WATER; Material type = player.getLocation().getBlock().getType();
return type == Material.WATER || type == Material.STATIONARY_WATER;
} }
} }

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.items.legendaries; package mineplex.game.clans.items.legendaries;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -35,32 +36,31 @@ import mineplex.core.recharge.Recharge;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
/*
@deprecated Code probably doesn't work and needs a rewrite
*/
@Deprecated
public class EnergyCrossbow extends LegendaryItem public class EnergyCrossbow extends LegendaryItem
{ {
private long _lastFire = System.currentTimeMillis(); private static final List<Vector> PRE_CALCULATED_SPHERE = Collections.unmodifiableList(
UtilTrig.GetSpherePoints(new Vector(0, 0, 0), 1.8d, 1.8d, true, .4d)
);
private long _interactWait; private long _interactWait;
private static List<Vector> _preCalculatedSphere;
{
ClansManager.getInstance().runAsync(() ->
_preCalculatedSphere = UtilTrig.GetSpherePoints(new Vector(0, 0, 0), 1.8d, 1.8d, true, .4d)
);
}
public EnergyCrossbow() public EnergyCrossbow()
{ {
super("Energy Crossbow", UtilText.splitLinesToArray(new String[] { super("Energy Crossbow", UtilText.splitLinesToArray(new String[] {
C.cWhite + "Legend says " C.cWhite + "Legend says "
+ " ", + " ",
"#" + C.cYellow + "Right-Click" + C.cWhite + " to fire Crossbow." "#" + C.cYellow + "Right-Click" + C.cWhite + " to fire Crossbow."
}, LineFormat.LORE), Material.RECORD_6); }, LineFormat.LORE), Material.RECORD_6);
} }
@Override @Override
public void update(Player wielder) public void update(Player wielder)
{ {
if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) if (timeSinceLastBlock() < 98 && (System.currentTimeMillis() - _interactWait) >= 98)
{ {
if (Recharge.Instance.use(wielder, "Crossbow", 6500, true, true)) if (Recharge.Instance.use(wielder, "Crossbow", 6500, true, true))
{ {
@ -82,6 +82,7 @@ public class EnergyCrossbow extends LegendaryItem
private RGBData[] colors = { UtilColor.RgbLightRed, UtilColor.RgbLightRed.Lighten(), UtilColor.RgbLightRed.Darken() }; private RGBData[] colors = { UtilColor.RgbLightRed, UtilColor.RgbLightRed.Lighten(), UtilColor.RgbLightRed.Darken() };
{ {
// Pretty sure this won't work
_player = player; _player = player;
Arrow arrow = _player.shootArrow(); Arrow arrow = _player.shootArrow();
@ -125,7 +126,7 @@ public class EnergyCrossbow extends LegendaryItem
{ {
HandlerList.unregisterAll(this); HandlerList.unregisterAll(this);
for (Vector vector : _preCalculatedSphere) for (Vector vector : PRE_CALCULATED_SPHERE)
{ {
UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, _arrow.getLocation().add(vector), UtilColor.RgbLightRed.ToVector(), 1.0f, 0, ViewDist.MAX); UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, _arrow.getLocation().add(vector), UtilColor.RgbLightRed.ToVector(), 1.0f, 0, ViewDist.MAX);
} }
@ -182,7 +183,5 @@ public class EnergyCrossbow extends LegendaryItem
} }
}); });
_lastFire = System.currentTimeMillis();
} }
} }

View File

@ -14,8 +14,8 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class GiantsBroadsword extends LegendaryItem public class GiantsBroadsword extends LegendaryItem
{ {
public static final int SLOW_AMPLIFIER = 43; private static final int SLOW_AMPLIFIER = 43;
public static final int REGEN_AMPLIFIER = 1; private static final int REGEN_AMPLIFIER = 1;
public GiantsBroadsword() public GiantsBroadsword()
{ {
@ -33,7 +33,8 @@ public class GiantsBroadsword extends LegendaryItem
@Override @Override
public void update(Player wielder) public void update(Player wielder)
{ {
if (isHoldingRightClick()) { if (isHoldingRightClick())
{
buffPlayer(wielder); buffPlayer(wielder);
UtilParticle.PlayParticle(ParticleType.HEART, wielder.getEyeLocation().add(0, 0.25, 0), -.5f + (float) Math.random(), -.5f + (float) Math.random(), -.5f + (float) Math.random(), .2f, 1, ViewDist.NORMAL); UtilParticle.PlayParticle(ParticleType.HEART, wielder.getEyeLocation().add(0, 0.25, 0), -.5f + (float) Math.random(), -.5f + (float) Math.random(), -.5f + (float) Math.random(), .2f, 1, ViewDist.NORMAL);
@ -56,8 +57,7 @@ public class GiantsBroadsword extends LegendaryItem
event.AddMod("Giants Bonus", 9); event.AddMod("Giants Bonus", 9);
event.AddKnockback("Giants Sword", 0.5d); event.AddKnockback("Giants Sword", 0.5d);
} }
private void buffPlayer(Player player) private void buffPlayer(Player player)
{ {
grantPotionEffect(player, PotionEffectType.SLOW, 40, SLOW_AMPLIFIER); grantPotionEffect(player, PotionEffectType.SLOW, 40, SLOW_AMPLIFIER);

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.items.legendaries; package mineplex.game.clans.items.legendaries;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -12,9 +12,9 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class HyperAxe extends LegendaryItem public class HyperAxe extends LegendaryItem
{ {
public static final long ATTACK_RATE_DURATION = 1000 / 10; private static final long ATTACK_RATE_DURATION = 1000 / 10;
private static ValueDistribution amountGen = generateDistribution(0, 3); // [1, 4] speed amount private static ValueDistribution AMOUNT_GEN = generateDistribution(0, 3); // [1, 4] speed amount
private static ValueDistribution durationGen = generateDistribution(80, 320); // [4, 16] seconds speed duration private static ValueDistribution DURATION_GEN = generateDistribution(80, 320); // [4, 16] seconds speed duration
private int _speedAmount; private int _speedAmount;
private int _speedDuration; private int _speedDuration;
@ -34,15 +34,15 @@ public class HyperAxe extends LegendaryItem
C.cWhite + "Deals " + C.cYellow + "3 Damage" + C.cWhite + " with attack", C.cWhite + "Deals " + C.cYellow + "3 Damage" + C.cWhite + " with attack",
C.cYellow + "Right-Click" + C.cWhite + " to use " + C.cGreen + "Dash", C.cYellow + "Right-Click" + C.cWhite + " to use " + C.cGreen + "Dash",
}, Material.RECORD_3); }, Material.RECORD_3);
_speedAmount = amountGen.generateIntValue(); _speedAmount = AMOUNT_GEN.generateIntValue();
_speedDuration = durationGen.generateIntValue(); _speedDuration = DURATION_GEN.generateIntValue();
_lastAttack = 0; _lastAttack = 0;
} }
@Override @Override
public void update(Player wielder) public void update(Player wielder)
{ {
if (isHoldingRightClick() && canBuff(wielder)) if (isHoldingRightClick())
{ {
buffPlayer(wielder); buffPlayer(wielder);
} }
@ -64,22 +64,18 @@ public class HyperAxe extends LegendaryItem
} }
} }
public long timeSinceLastAttack() private long timeSinceLastAttack()
{ {
return System.currentTimeMillis() - _lastAttack; return System.currentTimeMillis() - _lastAttack;
} }
private void buffPlayer(Player wielder) private void buffPlayer(Player wielder)
{ {
Recharge.Instance.use(wielder, "Hyper Rush", 16000, true, false); if (Recharge.Instance.usable(wielder, "Hyper Rush", true))
{
// Give player speed buff Recharge.Instance.use(wielder, "Hyper Rush", 16000, true, false);
wielder.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, _speedDuration, _speedAmount)); // Give player speed buff
log("Buffing"); wielder.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, _speedDuration, _speedAmount));
} }
private boolean canBuff(Player wielder)
{
return Recharge.Instance.usable(wielder, "Hyper Rush", true);
} }
} }

View File

@ -13,16 +13,15 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class LegendaryItem extends CustomItem public class LegendaryItem extends CustomItem
{ {
public final long BLOCK_COOLDOWN = 200l; // Right clicking activates right click for 200ms private final long BLOCK_COOLDOWN = 200L; // Right clicking activates right click for 200ms
protected long _lastBlock; // Timestamp of last block from wielder protected long _lastBlock; // Timestamp of last block from wielder
public long timeSinceLastBlock() { return System.currentTimeMillis() - _lastBlock; }
public LegendaryItem(String name, String[] description, Material material) public LegendaryItem(String name, String[] description, Material material)
{ {
super(name, description, material); super(name, description, material);
_lastBlock = 0l; _lastBlock = 0L;
} }
public void update(Player wielder) public void update(Player wielder)
@ -66,6 +65,11 @@ public class LegendaryItem extends CustomItem
{ {
return timeSinceLastBlock() <= BLOCK_COOLDOWN; return timeSinceLastBlock() <= BLOCK_COOLDOWN;
} }
public long timeSinceLastBlock()
{
return System.currentTimeMillis() - _lastBlock;
}
protected void log(String message) protected void log(String message)
{ {
@ -92,7 +96,6 @@ public class LegendaryItem extends CustomItem
*/ */
public static void grantPotionEffect(Player player, PotionEffectType type, int tickDuration, int amplifier) public static void grantPotionEffect(Player player, PotionEffectType type, int tickDuration, int amplifier)
{ {
player.removePotionEffect(type); player.addPotionEffect(new PotionEffect(type, amplifier, tickDuration), true);
player.addPotionEffect(new PotionEffect(type, amplifier, tickDuration));
} }
} }

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.items.legendaries; package mineplex.game.clans.items.legendaries;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
@ -8,9 +9,11 @@ import mineplex.core.common.util.UtilParticle;
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.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTextBottom; import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Location; import org.bukkit.Location;
@ -21,30 +24,28 @@ import org.bukkit.util.Vector;
public class MagneticMaul extends LegendaryItem public class MagneticMaul extends LegendaryItem
{ {
public static final double PULL_RANGE = 10d; private static final double PULL_RANGE = 10d;
private double _power; private double _power;
private double _heat; private double _heat;
public MagneticMaul() public MagneticMaul()
{ {
super("Magnetic Maul", new String[] { super("Magnetic Maul", UtilText.splitLinesToArray(new String[] {
C.cWhite + "This brutal weapon allows you to pull your enemies towards you with magnetic force!" C.cWhite + "This brutal weapon allows you to pull your enemies towards you with magnetic force!",
+ " ", " ",
C.cYellow + "Right-Click" + C.cWhite + " to use Maul." C.cYellow + "Right-Click" + C.cWhite + " to use Maul."
}, Material.RECORD_5); }, LineFormat.LORE), Material.RECORD_5);
} }
@Override @Override
public void update(Player wielder) public void update(Player wielder)
{ {
Location loc = wielder.getLocation(); Location loc = wielder.getLocation();
if (ClansManager.getInstance().getClaimMap().containsKey(UtilWorld.chunkToStr(loc.getChunk()))) ClanTerritory territory = ClansManager.getInstance().getClaimMap().get(UtilWorld.chunkToStr(loc));
if (territory != null && territory.isSafe(loc))
{ {
if (ClansManager.getInstance().getClaimMap().get(UtilWorld.chunkToStr(loc.getChunk())).isSafe(wielder.getLocation())) return;
{
return;
}
} }
if (isHoldingRightClick() && canPull()) if (isHoldingRightClick() && canPull())
@ -94,9 +95,9 @@ public class MagneticMaul extends LegendaryItem
if (otherTargetDistance < targetDistance && otherDistance <= PULL_RANGE) if (otherTargetDistance < targetDistance && otherDistance <= PULL_RANGE)
{ {
// If entity is in safe zone, don't allow pulling of that entity. // If entity is in safe zone, don't allow pulling of that entity.
if (ClansManager.getInstance().getClaimMap().containsKey(UtilWorld.chunkToStr(entity.getLocation().getChunk()))) if (ClansManager.getInstance().getClaimMap().containsKey(UtilWorld.chunkToStr(entity.getLocation())))
{ {
if (ClansManager.getInstance().getClaimMap().get(UtilWorld.chunkToStr(entity.getLocation().getChunk())).isSafe(entity.getLocation())) if (ClansManager.getInstance().getClaimMap().get(UtilWorld.chunkToStr(entity.getLocation())).isSafe(entity.getLocation()))
{ {
continue; continue;
} }
@ -107,23 +108,23 @@ public class MagneticMaul extends LegendaryItem
} }
// Do Particles // Do Particles
for (int i=0 ; i<6 ; i++) for (int i = 0; i < 6; i++)
{ {
Vector random = new Vector(Math.random() * 4 - 2, Math.random() * 4 - 2, Math.random() * 4 - 2); Vector random = new Vector(Math.random() * 4 - 2, Math.random() * 4 - 2, Math.random() * 4 - 2);
Location origin = player.getLocation().add(0, 1.3, 0); Location origin = player.getLocation().add(0, 1.3, 0);
origin.add(player.getLocation().getDirection().multiply(10)); origin.add(player.getLocation().getDirection().multiply(10));
origin.add(random); origin.add(random);
Vector vel = UtilAlg.getTrajectory(origin, player.getLocation().add(0, 1.3, 0)); Vector vel = UtilAlg.getTrajectory(origin, player.getLocation().add(0, 1.3, 0));
vel.multiply(7); vel.multiply(7);
UtilParticle.PlayParticle(ParticleType.MAGIC_CRIT, UtilParticle.PlayParticle(ParticleType.MAGIC_CRIT,
origin, origin,
(float)vel.getX(), (float)vel.getX(),
(float)vel.getY(), (float)vel.getY(),
(float)vel.getZ(), (float)vel.getZ(),
1, 0, ViewDist.LONG, UtilServer.getPlayers()); 1, 0, ViewDist.LONG, UtilServer.getPlayers());
} }
removePower(1.75); removePower(1.75);

View File

@ -35,10 +35,10 @@ import org.bukkit.util.Vector;
public class MeridianScepter extends LegendaryItem public class MeridianScepter extends LegendaryItem
{ {
private static final RGBData[] COLORS = { UtilColor.RgbPurple, UtilColor.RgbPurple.Lighten(), UtilColor.RgbPurple.Darken() };
private long _interactWait; private long _interactWait;
private RGBData[] colors = { UtilColor.RgbPurple, UtilColor.RgbPurple.Lighten(), UtilColor.RgbPurple.Darken() };
private transient HashMap<AttackAnimation, Integer> _animations = new HashMap<AttackAnimation, Integer>(); private transient HashMap<AttackAnimation, Integer> _animations = new HashMap<AttackAnimation, Integer>();
public MeridianScepter() public MeridianScepter()
@ -53,7 +53,7 @@ public class MeridianScepter extends LegendaryItem
@Override @Override
public void update(Player wielder) public void update(Player wielder)
{ {
if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) if (timeSinceLastBlock() < 98 && (System.currentTimeMillis() - _interactWait) >= 98)
{ {
if (ClansManager.getInstance().hasTimer(wielder)) if (ClansManager.getInstance().hasTimer(wielder))
{ {
@ -248,7 +248,7 @@ public class MeridianScepter extends LegendaryItem
{ {
for (Location loc : UtilShapes.getLinesDistancedPoints(start, end, 0.06)) for (Location loc : UtilShapes.getLinesDistancedPoints(start, end, 0.06))
{ {
UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, loc, UtilCollections.random(colors).ToVector(), 1f, 0, ViewDist.LONG); UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, loc, UtilCollections.random(COLORS).ToVector(), 1f, 0, ViewDist.LONG);
} }
} }

View File

@ -44,7 +44,7 @@ public class WindBlade extends LegendaryItem
} }
} }
public static final double FLIGHT_VELOCITY = 0.75d; private static final double FLIGHT_VELOCITY = 0.75d;
private double _power; private double _power;
private double _burnoutThreshold; private double _burnoutThreshold;

View File

@ -74,6 +74,11 @@ public abstract class Tutorial implements Listener, ObjectiveListener
public void start(Player player) public void start(Player player)
{ {
if (!canStart(player))
{
return;
}
System.out.println(String.format("Tutorial> [%s] started tutorial [%s]", player.getName(), getName())); System.out.println(String.format("Tutorial> [%s] started tutorial [%s]", player.getName(), getName()));
TutorialSession session = new TutorialSession(); TutorialSession session = new TutorialSession();
@ -223,6 +228,8 @@ public abstract class Tutorial implements Listener, ObjectiveListener
*/ */
protected abstract void onQuit(Player player); protected abstract void onQuit(Player player);
protected abstract boolean canStart(Player player);
public void unregisterAll() public void unregisterAll()
{ {
HandlerList.unregisterAll(this); HandlerList.unregisterAll(this);

View File

@ -2,6 +2,7 @@ package mineplex.game.clans.tutorial;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList;
import java.util.Stack; import java.util.Stack;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -25,7 +26,7 @@ public class TutorialWorldManager extends MiniPlugin
private final World _tutorialWorld; private final World _tutorialWorld;
private final Schematic _schematic; private final Schematic _schematic;
private Stack<TutorialRegion> _regionStack; private LinkedList<TutorialRegion> _regionStack;
private TutorialRegion _centerRegion; private TutorialRegion _centerRegion;
public TutorialWorldManager(JavaPlugin plugin, String worldName, String schematicName) throws IOException public TutorialWorldManager(JavaPlugin plugin, String worldName, String schematicName) throws IOException
@ -56,7 +57,7 @@ public class TutorialWorldManager extends MiniPlugin
private void populateRegionStack() private void populateRegionStack()
{ {
_regionStack = new Stack<>(); _regionStack = new LinkedList<>();
// Populate the stack with 100 available tutorial regions // Populate the stack with 100 available tutorial regions
for (int x = 0; x < 10; x++) for (int x = 0; x < 10; x++)

View File

@ -171,6 +171,18 @@ public class ClansMainTutorial extends Tutorial
*/ */
} }
@Override
protected boolean canStart(Player player)
{
ClanInfo clan = ClansManager.getInstance().getClan(player);
if (clan != null)
{
UtilPlayer.message(player, F.main("Clans", "You are part of a clan - please leave or disband the clan before doing the tutorial"));
return false;
}
return true;
}
@Override @Override
protected void onStart(Player player) protected void onStart(Player player)
{ {
@ -205,12 +217,6 @@ public class ClansMainTutorial extends Tutorial
addHologram(player, addHologram(player,
getPoint(region, ClansMainTutorial.Point.SPAWN).add(0, 1.5, -23), getPoint(region, ClansMainTutorial.Point.SPAWN).add(0, 1.5, -23),
"Jump Off!"); "Jump Off!");
ClanInfo clan = ClansManager.getInstance().getClan(player);
if (clan != null)
{
ClansManager.getInstance().getClanDataAccess().delete(clan, null);
}
} }
@Override @Override
@ -465,7 +471,15 @@ public class ClansMainTutorial extends Tutorial
if (!_taskManager.hasCompletedTask(event.getPlayer(), getTaskIdentifier())) if (!_taskManager.hasCompletedTask(event.getPlayer(), getTaskIdentifier()))
{ {
start(event.getPlayer()); ClanInfo clan = ClansManager.getInstance().getClan(event.getPlayer());
if (clan == null)
{
start(event.getPlayer());
}
else
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "It seems you already have a clan here, so we can skip the tutorial"));
}
} }
else if (!event.getPlayer().hasPlayedBefore() || !event.getPlayer().getLocation().getWorld().equals(Spawn.getSpawnWorld())) else if (!event.getPlayer().hasPlayedBefore() || !event.getPlayer().getLocation().getWorld().equals(Spawn.getSpawnWorld()))
{ {

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan; package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.game.clans.clans.event.ClanCreatedEvent;
import mineplex.game.clans.clans.gui.events.ClansButtonClickEvent; import mineplex.game.clans.clans.gui.events.ClansButtonClickEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;

View File

@ -47,6 +47,7 @@ public class DisbandClanGoal extends ObjectiveGoal<FinalObjective>
{ {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
UtilPlayer.message(event.getDisbander(), F.main("Clans", "You have disbanded your Tutorial Clan.")); UtilPlayer.message(event.getDisbander(), F.main("Clans", "You have disbanded your Tutorial Clan."));

View File

@ -88,6 +88,10 @@ public class Recall extends Skill
return; return;
Factory.runSync(() -> { Factory.runSync(() -> {
if (player.isDead())
{
return;
}
//Heal //Heal
double newHealth = Math.min(health.getLast(), player.getHealth() + 3 + level); double newHealth = Math.min(health.getLast(), player.getHealth() + 3 + level);
player.setHealth(newHealth); player.setHealth(newHealth);

View File

@ -258,7 +258,7 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
@EventHandler @EventHandler
public void onChunkUnload(ChunkUnloadEvent event) public void onChunkUnload(ChunkUnloadEvent event)
{ {
if (_entity.getLocation().getChunk().equals(event.getChunk())) if (_entity != null && _entity.getLocation().getChunk().equals(event.getChunk()))
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -1,9 +1,5 @@
package nautilus.game.arcade; package nautilus.game.arcade;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager; import mineplex.core.achievement.AchievementManager;
@ -12,13 +8,7 @@ import mineplex.core.blood.Blood;
import mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.BonusManager;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.*;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.creature.Creature; import mineplex.core.creature.Creature;
import mineplex.core.customdata.CustomDataManager; import mineplex.core.customdata.CustomDataManager;
@ -45,6 +35,7 @@ import mineplex.core.pet.PetManager;
import mineplex.core.poll.PollManager; import mineplex.core.poll.PollManager;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager; import mineplex.core.preferences.PreferencesManager;
import mineplex.core.progression.KitProgressionManager;
import mineplex.core.projectile.ProjectileManager; import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish; import mineplex.core.punish.Punish;
import mineplex.core.resourcepack.ResourcePackManager; import mineplex.core.resourcepack.ResourcePackManager;
@ -73,46 +64,22 @@ import mineplex.minecraft.game.core.fire.Fire;
import nautilus.game.arcade.addons.SoupAddon; import nautilus.game.arcade.addons.SoupAddon;
import nautilus.game.arcade.addons.TeamArmorAddon; import nautilus.game.arcade.addons.TeamArmorAddon;
import nautilus.game.arcade.addons.compass.CompassAddon; import nautilus.game.arcade.addons.compass.CompassAddon;
import nautilus.game.arcade.command.DisguiseCommand; import nautilus.game.arcade.command.*;
import nautilus.game.arcade.command.GameCmdModeCommand;
import nautilus.game.arcade.command.GameCommand;
import nautilus.game.arcade.command.KitUnlockCommand;
import nautilus.game.arcade.command.RequiredRankCommand;
import nautilus.game.arcade.command.WriteCommand;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.GameServerConfig; import nautilus.game.arcade.game.GameServerConfig;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.event.EventModule; import nautilus.game.arcade.game.games.event.EventModule;
import nautilus.game.arcade.game.games.uhc.UHC; import nautilus.game.arcade.game.games.uhc.UHC;
import nautilus.game.arcade.managers.GameAchievementManager; import nautilus.game.arcade.managers.*;
import nautilus.game.arcade.managers.GameCreationManager;
import nautilus.game.arcade.managers.GameFlagManager;
import nautilus.game.arcade.managers.GameGemManager;
import nautilus.game.arcade.managers.GameHostManager;
import nautilus.game.arcade.managers.GameLobbyManager;
import nautilus.game.arcade.managers.GameLootManager;
import nautilus.game.arcade.managers.GameManager;
import nautilus.game.arcade.managers.GamePlayerManager;
import nautilus.game.arcade.managers.GameSpectatorManager;
import nautilus.game.arcade.managers.GameStatManager;
import nautilus.game.arcade.managers.GameTestingManager;
import nautilus.game.arcade.managers.GameTournamentManager;
import nautilus.game.arcade.managers.GameWorldManager;
import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.MiscManager;
import nautilus.game.arcade.managers.chat.GameChatManager; import nautilus.game.arcade.managers.chat.GameChatManager;
import nautilus.game.arcade.player.ArcadePlayer; import nautilus.game.arcade.player.ArcadePlayer;
import nautilus.game.arcade.shop.ArcadeShop; import nautilus.game.arcade.shop.ArcadeShop;
import net.minecraft.server.v1_8_R3.EntityLiving; import net.minecraft.server.v1_8_R3.EntityLiving;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -136,6 +103,10 @@ import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
public class ArcadeManager extends MiniPlugin implements IRelation public class ArcadeManager extends MiniPlugin implements IRelation
{ {
// Modules // Modules
@ -192,6 +163,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private Punish _punishmentManager; private Punish _punishmentManager;
private BrandingManager _brandingManager; private BrandingManager _brandingManager;
private BonusManager _bonusManager; private BonusManager _bonusManager;
private KitProgressionManager _kitProgressionManager;
private ProgressingKitManager _progressionKitManager;
private IncognitoManager _incognitoManager; private IncognitoManager _incognitoManager;
@ -344,6 +317,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_punishmentManager = punish; _punishmentManager = punish;
_kitProgressionManager = new KitProgressionManager(getPlugin(), clientManager);
_progressionKitManager = new ProgressingKitManager(this);
if (GetHost() != null && !GetHost().isEmpty()) if (GetHost() != null && !GetHost().isEmpty())
{ {
Bukkit.getScheduler().runTaskLater(plugin, () -> Portal.transferPlayer(GetHost(), _serverStatusManager.getCurrentServerName()), 80L); Bukkit.getScheduler().runTaskLater(plugin, () -> Portal.transferPlayer(GetHost(), _serverStatusManager.getCurrentServerName()), 80L);
@ -1703,4 +1679,14 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return true; return true;
} }
public ProgressingKitManager getProgressionKitManager()
{
return _progressionKitManager;
}
public KitProgressionManager getKitProgressionManager()
{
return _kitProgressionManager;
}
} }

View File

@ -218,7 +218,7 @@ public enum GameType
Pair<MinecraftVersion, String>[] _resourcePacks; Pair<MinecraftVersion, String>[] _resourcePacks;
Class<? extends Game> _gameClass; Class<? extends Game> _gameClass;
GameMode[] _gameModes; private GameMode[] _gameModes;
private boolean _gameMaps; private boolean _gameMaps;
private int _gameId; // Unique identifying id for this gamemode (used for statistics) private int _gameId; // Unique identifying id for this gamemode (used for statistics)
@ -322,16 +322,15 @@ public enum GameType
return _display.getGameCategory(); return _display.getGameCategory();
} }
public String GetKitGameName() public String GetKitGameName(Game game)
{ {
if (hasGamemodes())
{
return getModeGameType(game.getClass())._display.getKitGameName();
}
return _display.getKitGameName(); return _display.getKitGameName();
} }
public boolean isUsingGameModes()
{
return _gameMaps;
}
public GameType getModeGameType(Class<? extends Game> game) public GameType getModeGameType(Class<? extends Game> game)
{ {
for (GameMode mode : getGameModes()) for (GameMode mode : getGameModes())
@ -343,4 +342,14 @@ public enum GameType
} }
return null; return null;
} }
public boolean isUsingGameModesMaps()
{
return _gameMaps;
}
public boolean hasGamemodes()
{
return _gameModes.length != 0;
}
} }

View File

@ -1,20 +1,41 @@
package nautilus.game.arcade.game; package nautilus.game.arcade.game;
import java.util.ArrayList; import com.google.common.collect.Lists;
import java.util.Collection; import com.mojang.authlib.GameProfile;
import java.util.HashMap; import mineplex.core.common.util.*;
import java.util.HashSet; import mineplex.core.disguise.disguises.DisguisePlayer;
import java.util.Iterator; import mineplex.core.elo.EloPlayer;
import java.util.List; import mineplex.core.elo.EloTeam;
import java.util.Map.Entry; import mineplex.core.itemstack.ItemBuilder;
import java.util.Set; import mineplex.core.packethandler.IPacketHandler;
import java.util.UUID; import mineplex.core.packethandler.PacketInfo;
import mineplex.core.recharge.Recharge;
import org.bukkit.Bukkit; import mineplex.core.updater.UpdateType;
import org.bukkit.ChatColor; import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Location; import mineplex.minecraft.game.classcombat.event.ClassCombatCreatureAllowSpawnEvent;
import org.bukkit.Material; import mineplex.minecraft.game.core.combat.DeathMessageType;
import org.bukkit.Sound; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.managers.GameLobbyManager;
import nautilus.game.arcade.managers.chat.ChatStatData;
import nautilus.game.arcade.scoreboard.GameScoreboard;
import nautilus.game.arcade.stats.*;
import nautilus.game.arcade.wineffect.WinEffectManager;
import nautilus.game.arcade.world.WorldData;
import net.minecraft.server.v1_8_R3.EntityItem;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
import net.minecraft.server.v1_8_R3.WorldServer;
import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
@ -45,57 +66,8 @@ import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.mojang.authlib.GameProfile; import java.util.*;
import java.util.Map.Entry;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTabTitle;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.elo.EloPlayer;
import mineplex.core.elo.EloTeam;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.classcombat.event.ClassCombatCreatureAllowSpawnEvent;
import mineplex.minecraft.game.core.combat.DeathMessageType;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.managers.GameLobbyManager;
import nautilus.game.arcade.managers.chat.ChatStatData;
import nautilus.game.arcade.scoreboard.GameScoreboard;
import nautilus.game.arcade.stats.AssistsStatTracker;
import nautilus.game.arcade.stats.DamageDealtStatTracker;
import nautilus.game.arcade.stats.DamageTakenStatTracker;
import nautilus.game.arcade.stats.DeathsStatTracker;
import nautilus.game.arcade.stats.ExperienceStatTracker;
import nautilus.game.arcade.stats.GamesPlayedStatTracker;
import nautilus.game.arcade.stats.KillsStatTracker;
import nautilus.game.arcade.stats.LoseStatTracker;
import nautilus.game.arcade.stats.StatTracker;
import nautilus.game.arcade.stats.WinStatTracker;
import nautilus.game.arcade.wineffect.WinEffectManager;
import nautilus.game.arcade.world.WorldData;
import net.minecraft.server.v1_8_R3.EntityItem;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
import net.minecraft.server.v1_8_R3.WorldServer;
public abstract class Game implements Listener public abstract class Game implements Listener
{ {
@ -490,7 +462,7 @@ public abstract class Game implements Listener
} }
} }
if (GetType().isUsingGameModes()) if (GetType().isUsingGameModesMaps())
{ {
GameType mode = GetType().getModeGameType(getClass()); GameType mode = GetType().getModeGameType(getClass());
@ -687,6 +659,10 @@ public abstract class Game implements Listener
{ {
for (Kit kit : _kits) for (Kit kit : _kits)
{ {
if(kit == null)
{
continue;
}
UtilServer.getServer().getPluginManager().registerEvents(kit, Manager.getPlugin()); UtilServer.getServer().getPluginManager().registerEvents(kit, Manager.getPlugin());
for (Perk perk : kit.GetPerks()) for (Perk perk : kit.GetPerks())
@ -701,6 +677,11 @@ public abstract class Game implements Listener
{ {
for (Kit kit : _kits) for (Kit kit : _kits)
{ {
if(kit == null)
{
continue;
}
HandlerList.unregisterAll(kit); HandlerList.unregisterAll(kit);
for (Perk perk : kit.GetPerks()) for (Perk perk : kit.GetPerks())
@ -728,9 +709,6 @@ public abstract class Game implements Listener
team.AddPlayer(player, in); team.AddPlayer(player, in);
// Ensure Valid Kit
ValidateKit(player, team);
// Game Scoreboard // Game Scoreboard
Scoreboard.SetPlayerTeam(player, team.GetName().toUpperCase()); Scoreboard.SetPlayerTeam(player, team.GetName().toUpperCase());
@ -739,6 +717,9 @@ public abstract class Game implements Listener
// Save Tournament Team // Save Tournament Team
Manager.GetGameTournamentManager().setTournamentTeam(player, team); Manager.GetGameTournamentManager().setTournamentTeam(player, team);
// Ensure Valid Kit
ValidateKit(player, team);
} }
public GameTeam ChooseTeam(Player player) public GameTeam ChooseTeam(Player player)
@ -819,13 +800,48 @@ public abstract class Game implements Listener
public void ValidateKit(Player player, GameTeam team) public void ValidateKit(Player player, GameTeam team)
{ {
// Kit if (GetKit(player) != null)
{
//Make sure their current kit can be used, if not, tell them.
Kit kit = GetKit(player);
if (team.KitAllowed(kit))
{
return;
}
player.sendMessage(F.main("Kit", "Your current kit is not applicable with your team. Please select a different kit"));
Optional<Kit> newKit = Lists.newArrayList(GetKits())
.stream().filter(team::KitAllowed).findFirst();
if (newKit.isPresent())
{
SetKit(player, newKit.get(), false);
return;
}
return;
}
//This IN THEORY shouldn't ever be used, but oh well.
if (GetKit(player) == null || !team.KitAllowed(GetKit(player))) if (GetKit(player) == null || !team.KitAllowed(GetKit(player)))
{ {
for (Kit kit : _kits) for (Kit kit : _kits)
{ {
if (kit.GetAvailability() == KitAvailability.Hide || kit.GetAvailability() == KitAvailability.Null) if (kit.GetAvailability() == KitAvailability.Hide || kit.GetAvailability() == KitAvailability.Null)
{
continue; continue;
}
//Set the default kit (if they have one selected)
if (kit instanceof ProgressingKit)
{
ProgressingKit progressingKit = (ProgressingKit) kit;
if (team.KitAllowed(progressingKit))
{
if (progressingKit.isDefault(player.getUniqueId()))
{
SetKit(player, progressingKit, true);
break;
}
}
}
if (team.KitAllowed(kit)) if (team.KitAllowed(kit))
{ {
@ -845,9 +861,9 @@ public abstract class Game implements Listener
{ {
player.playSound(player.getLocation(), Sound.NOTE_BASS, 2f, 0.5f); player.playSound(player.getLocation(), Sound.NOTE_BASS, 2f, 0.5f);
UtilPlayer.message( UtilPlayer.message(
player, player,
F.main("Kit", F.elem(team.GetFormattedName()) + " cannot use " + F.elem(kit.GetFormattedName() + " Kit") F.main("Kit", F.elem(team.GetFormattedName()) + " cannot use " + F.elem(kit.GetFormattedName() + " Kit")
+ ".")); + "."));
return; return;
} }
} }
@ -868,7 +884,13 @@ public abstract class Game implements Listener
} }
if (InProgress()) if (InProgress())
{
kit.ApplyKit(player); kit.ApplyKit(player);
}
else
{
player.closeInventory();
}
} }
public Kit GetKit(Player player) public Kit GetKit(Player player)

View File

@ -48,7 +48,7 @@ public class AbsorptionFix implements Listener
{ {
player.removePotionEffect(PotionEffectType.ABSORPTION); player.removePotionEffect(PotionEffectType.ABSORPTION);
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles())); player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()));
player.setHealth(player.getMaxHealth()); player.setHealth(player.getHealth() + 4);
} }
} }
} }

View File

@ -1,5 +1,17 @@
package nautilus.game.arcade.game.games.baconbrawl.kits; package nautilus.game.arcade.game.games.baconbrawl.kits;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.disguise.disguises.DisguisePig;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkBaconBlast;
import nautilus.game.arcade.kit.perks.PerkSpeed;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -10,50 +22,38 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C; public class KitMamaPig extends ProgressingKit
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.disguise.disguises.DisguisePig;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkBaconBlast;
import nautilus.game.arcade.kit.perks.PerkSpeed;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
public class KitMamaPig extends Kit
{ {
private static final String[] DESCRIPTION = {
"Mama & Baby Piggles fight together",
"",
click(false, C.cWhite + "Axe to use " + C.cGreen + "Bacon Blast"),
};
private static final ItemStack IN_HAND = new ItemStack(Material.PORK);
private static final Perk[] PERKS = {
new PerkBaconBlast(),
new PerkSpeed(1)
};
public KitMamaPig(ArcadeManager manager) public KitMamaPig(ArcadeManager manager)
{ {
super(manager, "Mama Piggles", KitAvailability.Gem, super(manager, "Mama Piggles", "mamapiggles", KitAvailability.Gem, DESCRIPTION, PERKS, EntityType.PIG, IN_HAND);
new String[]
{
"Mama & Baby Piggles fight together!"
},
new Perk[]
{
new PerkBaconBlast(),
new PerkSpeed(1),
},
EntityType.PIG,
new ItemStack(Material.PORK));
} }
@Override @Override
public void GiveItems(final Player player) public void GiveItems(final Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_AXE)); player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_AXE));
//Disguise //Disguise
DisguisePig disguise = new DisguisePig(player); DisguisePig disguise = new DisguisePig(player);
disguise.setName(C.cYellow + player.getName()); disguise.setName(C.cYellow + player.getName());
disguise.setCustomNameVisible(false); disguise.setCustomNameVisible(false);
Manager.GetDisguise().disguise(disguise); Manager.GetDisguise().disguise(disguise);
Manager.GetGame().CreatureAllowOverride = true; Manager.GetGame().CreatureAllowOverride = true;
final Pig pig = player.getWorld().spawn(player.getEyeLocation(), Pig.class); final Pig pig = player.getWorld().spawn(player.getEyeLocation(), Pig.class);
pig.setBaby(); pig.setBaby();
@ -61,33 +61,32 @@ public class KitMamaPig extends Kit
pig.setCustomName(C.cYellow + player.getName()); pig.setCustomName(C.cYellow + player.getName());
pig.setCustomNameVisible(false); pig.setCustomNameVisible(false);
Manager.GetGame().CreatureAllowOverride = false; Manager.GetGame().CreatureAllowOverride = false;
player.setPassenger(pig); player.setPassenger(pig);
Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), new Runnable() Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), () -> UtilPlayer.sendPacket(player, new PacketPlayOutEntityDestroy(new int[]{pig.getEntityId()})), 2);
{
@Override
public void run()
{
UtilPlayer.sendPacket(player, new PacketPlayOutEntityDestroy(new int[] { pig.getEntityId() }));
}
}, 2);
} }
@EventHandler(priority=EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void damageTransfer(CustomDamageEvent event) public void damageTransfer(CustomDamageEvent event)
{ {
if (event.IsCancelled()) if (event.IsCancelled())
{
return; return;
}
if (!(event.GetDamageeEntity() instanceof Pig)) if (!(event.GetDamageeEntity() instanceof Pig))
{
return; return;
}
Pig pig = (Pig)event.GetDamageeEntity();
Pig pig = (Pig) event.GetDamageeEntity();
if (pig.getVehicle() == null || !(pig.getVehicle() instanceof LivingEntity)) if (pig.getVehicle() == null || !(pig.getVehicle() instanceof LivingEntity))
{
return; return;
}
event.setDamagee((LivingEntity)pig.getVehicle());
event.setDamagee((LivingEntity) pig.getVehicle());
} }
} }

View File

@ -1,37 +1,36 @@
package nautilus.game.arcade.game.games.baconbrawl.kits; package nautilus.game.arcade.game.games.baconbrawl.kits;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.disguise.disguises.DisguisePig; import mineplex.core.disguise.disguises.DisguisePig;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkBodySlam; import nautilus.game.arcade.kit.perks.PerkBodySlam;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class KitPig extends Kit public class KitPig extends ProgressingKit
{ {
private static final String[] DESCRIPTION = {
"Such a fat pig. Oink",
"",
click(false, "Axe to " + C.cGreen + "Body Slam"),
};
private static final Perk[] PERKS = {
new PerkBodySlam(6, 2),
};
private static final ItemStack IN_HAND = new ItemStack(Material.PORK);
public KitPig(ArcadeManager manager) public KitPig(ArcadeManager manager)
{ {
super(manager, "El Muchacho Pigo", KitAvailability.Free, super(manager, "El Muchacho Pigo", "elmuchachopigo", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.PIG, IN_HAND);
new String[]
{
"Such a fat pig. Oink."
},
new Perk[]
{
new PerkBodySlam(6, 2),
//new PerkJump(1), MAC
},
EntityType.PIG,
new ItemStack(Material.PORK));
} }
@Override @Override

View File

@ -1,48 +1,45 @@
package nautilus.game.arcade.game.games.baconbrawl.kits; package nautilus.game.arcade.game.games.baconbrawl.kits;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEnt;
import mineplex.core.disguise.disguises.DisguiseSheep; import mineplex.core.disguise.disguises.DisguiseSheep;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkBackstabKnockback; import nautilus.game.arcade.kit.perks.PerkBackstabKnockback;
import nautilus.game.arcade.kit.perks.PerkPigCloak; import nautilus.game.arcade.kit.perks.PerkPigCloak;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
public class KitSheepPig extends Kit public class KitSheepPig extends ProgressingKit
{ {
private static final String[] DESCRIPTION = {
"\"...Oink?\"",
"",
click(false, "Axe to " + C.cGreen + "Cloak"),
"Deal " + C.cGreen + "+250%" + C.cWhite + " Knockback from behind opponents."
};
private static final Perk[] PERKS = {
new PerkPigCloak(),
new PerkBackstabKnockback()
};
private static final ItemStack IN_HAND = new ItemStack(Material.WOOL, 1, DyeColor.PINK.getWoolData());
public KitSheepPig(ArcadeManager manager) public KitSheepPig(ArcadeManager manager)
{ {
super(manager, "Pig", KitAvailability.Gem, 5000, super(manager, "Pig", "wolfpig", KitAvailability.Gem, 5000, DESCRIPTION, PERKS, EntityType.SHEEP, IN_HAND);
new String[]
{
"\"...Oink?\""
},
new Perk[]
{
new PerkPigCloak(),
new PerkBackstabKnockback()
},
EntityType.SHEEP,
new ItemStack(Material.WOOL));
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_AXE)); player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_AXE));
@ -53,13 +50,15 @@ public class KitSheepPig extends Kit
disguise.setColor(DyeColor.PINK); disguise.setColor(DyeColor.PINK);
Manager.GetDisguise().disguise(disguise); Manager.GetDisguise().disguise(disguise);
} }
@Override @Override
public Entity SpawnEntity(Location loc) public Entity SpawnEntity(Location loc)
{ {
EntityType type = _entityType; EntityType type = _entityType;
if (type == EntityType.PLAYER) if (type == EntityType.PLAYER)
{
type = EntityType.ZOMBIE; type = EntityType.ZOMBIE;
}
LivingEntity entity = (LivingEntity) Manager.GetCreature().SpawnEntity(loc, type); LivingEntity entity = (LivingEntity) Manager.GetCreature().SpawnEntity(loc, type);
@ -70,13 +69,13 @@ public class KitSheepPig extends Kit
if (type == EntityType.SHEEP) if (type == EntityType.SHEEP)
{ {
Sheep sheep = (Sheep)entity; Sheep sheep = (Sheep) entity;
sheep.setColor(DyeColor.PINK); sheep.setColor(DyeColor.PINK);
} }
UtilEnt.Vegetate(entity); UtilEnt.Vegetate(entity);
SpawnCustom(entity); SpawnCustom(entity);
return entity; return entity;
} }

View File

@ -1,50 +1,56 @@
package nautilus.game.arcade.game.games.barbarians.kits; package nautilus.game.arcade.game.games.barbarians.kits;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkFletcher;
import nautilus.game.arcade.kit.perks.PerkRopedArrow;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.itemstack.ItemStackFactory; public class KitArcher extends ProgressingKit
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkFletcher;
import nautilus.game.arcade.kit.perks.PerkRopedArrow;
public class KitArcher extends Kit
{ {
private static final String[] DESCRIPTION = {
"Uses some kind of less barbaric ranged weapon"
};
private static final Perk[] PERKS = {
new PerkRopedArrow("Roped Arrow", 1, 6000),
new PerkFletcher(2, 2, true)
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.IRON_AXE),
ItemStackFactory.Instance.CreateStack(Material.BOW),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP)
};
private static final ItemStack[] ARMOR = {
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_HELMET),
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_CHESTPLATE),
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_LEGGINGS),
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_BOOTS)
};
private static final ItemStack IN_HAND = new ItemStack(Material.BOW);
public KitArcher(ArcadeManager manager) public KitArcher(ArcadeManager manager)
{ {
super(manager, "Barbarian Archer", KitAvailability.Gem, super(manager, "Barbarian Archer", "barbarianarcher", KitAvailability.Gem, DESCRIPTION, PERKS, EntityType.PLAYER, IN_HAND);
new String[]
{
"Uses some kind of less barbaric ranged weapon..."
},
new Perk[]
{
new PerkRopedArrow("Roped Arrow", 1, 6000),
new PerkFletcher(2, 2, true),
},
EntityType.PLAYER,
new ItemStack(Material.BOW));
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_AXE)); player.getInventory().addItem(PLAYER_ITEMS);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW)); player.getInventory().setArmorContents(ARMOR);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().setHelmet(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_HELMET));
player.getInventory().setChestplate(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_CHESTPLATE));
player.getInventory().setLeggings(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_LEGGINGS));
player.getInventory().setBoots(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_BOOTS));
} }
@Override @Override

View File

@ -1,56 +1,61 @@
package nautilus.game.arcade.game.games.barbarians.kits; package nautilus.game.arcade.game.games.barbarians.kits;
import mineplex.core.common.util.F;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkBomber;
import nautilus.game.arcade.kit.perks.PerkLeap;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.F; public class KitBomber extends ProgressingKit
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.*;
public class KitBomber extends Kit
{ {
private static final String[] DESCRIPTION = {
"Crazy bomb throwing barbarian. BOOM!"
};
private static final Perk[] PERKS = {
new PerkBomber(8, 2, -1),
new PerkLeap("Leap", 1, 1, 8000)
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.IRON_AXE),
ItemStackFactory.Instance.CreateStack(Material.TNT, (byte) 0, 1, F.item("Throwing TNT")),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP)
};
private static final ItemStack[] ARMOR = {
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_HELMET),
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_CHESTPLATE),
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_LEGGINGS),
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_BOOTS)
};
private static final ItemStack IN_HAND = new ItemStack(Material.TNT);
public KitBomber(ArcadeManager manager) public KitBomber(ArcadeManager manager)
{ {
super(manager, "Bomber", KitAvailability.Gem, 5000, super(manager, "Bomber", "barbarianbomber", KitAvailability.Gem, 5000, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Crazy bomb throwing barbarian. BOOM!"
},
new Perk[]
{
new PerkBomber(8, 2, -1),
new PerkLeap("Leap", 1, 1, 8000)
},
EntityType.ZOMBIE,
new ItemStack(Material.TNT));
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_AXE)); player.getInventory().addItem(PLAYER_ITEMS);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.TNT, (byte)0, 1, F.item("Throwing TNT"))); player.getInventory().setArmorContents(ARMOR);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().setHelmet(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_HELMET));
player.getInventory().setChestplate(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_CHESTPLATE));
player.getInventory().setLeggings(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_LEGGINGS));
player.getInventory().setBoots(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_BOOTS));
} }
@Override @Override
public void SpawnCustom(LivingEntity ent) public void SpawnCustom(LivingEntity ent)
{ {
ent.getEquipment().setHelmet(new ItemStack(Material.CHAINMAIL_HELMET)); ent.getEquipment().setHelmet(new ItemStack(Material.CHAINMAIL_HELMET));
ent.getEquipment().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE)); ent.getEquipment().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));

View File

@ -1,50 +1,56 @@
package nautilus.game.arcade.game.games.barbarians.kits; package nautilus.game.arcade.game.games.barbarians.kits;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkBodySlam;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.itemstack.ItemStackFactory; public class KitBrute extends ProgressingKit
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkBodySlam;
public class KitBrute extends Kit
{ {
private static final String[] DESCRIPTION = {
"A true barbarian, loves to kill people!"
};
private static final Perk[] PERKS = {
new PerkBodySlam(8, 2)
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.IRON_AXE),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP)
};
private static final ItemStack[] ARMOR = {
ItemStackFactory.Instance.CreateStack(Material.IRON_HELMET),
ItemStackFactory.Instance.CreateStack(Material.IRON_CHESTPLATE),
ItemStackFactory.Instance.CreateStack(Material.IRON_LEGGINGS),
ItemStackFactory.Instance.CreateStack(Material.IRON_BOOTS)
};
private static final ItemStack IN_HAND = new ItemStack(Material.IRON_AXE);
public KitBrute(ArcadeManager manager) public KitBrute(ArcadeManager manager)
{ {
super(manager, "Barbarian Brute", KitAvailability.Free, super(manager, "Barbarian Brute", "barbarianbrute", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.PLAYER, IN_HAND);
new String[]
{
"A true barbarian, loves to kill people!"
},
new Perk[]
{
new PerkBodySlam(8, 2)
},
EntityType.PLAYER,
new ItemStack(Material.IRON_AXE));
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_AXE)); player.getInventory().addItem(PLAYER_ITEMS);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP)); player.getInventory().setArmorContents(ARMOR);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().setHelmet(ItemStackFactory.Instance.CreateStack(Material.IRON_HELMET));
player.getInventory().setChestplate(ItemStackFactory.Instance.CreateStack(Material.IRON_CHESTPLATE));
player.getInventory().setLeggings(ItemStackFactory.Instance.CreateStack(Material.IRON_LEGGINGS));
player.getInventory().setBoots(ItemStackFactory.Instance.CreateStack(Material.IRON_BOOTS));
} }
@Override @Override
public void SpawnCustom(LivingEntity ent) public void SpawnCustom(LivingEntity ent)
{ {

View File

@ -1,75 +1,10 @@
package nautilus.game.arcade.game.games.bridge; package nautilus.game.arcade.game.games.bridge;
import java.util.ArrayList; import com.google.common.collect.Lists;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.craftbukkit.v1_8_R3.block.CraftBlock;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.*;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.explosion.ExplosionEvent; import mineplex.core.explosion.ExplosionEvent;
import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
@ -82,21 +17,34 @@ import nautilus.game.arcade.events.PlayerDeathOutEvent;
import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.TeamGame; import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.games.bridge.kits.KitApple; import nautilus.game.arcade.game.games.bridge.kits.*;
import nautilus.game.arcade.game.games.bridge.kits.KitArcher;
import nautilus.game.arcade.game.games.bridge.kits.KitBeserker;
import nautilus.game.arcade.game.games.bridge.kits.KitBomber;
import nautilus.game.arcade.game.games.bridge.kits.KitDestructor;
import nautilus.game.arcade.game.games.bridge.kits.KitMammoth;
import nautilus.game.arcade.game.games.bridge.kits.KitMiner;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.ore.OreHider; import nautilus.game.arcade.ore.OreHider;
import nautilus.game.arcade.ore.OreObsfucation; import nautilus.game.arcade.ore.OreObsfucation;
import nautilus.game.arcade.stats.BridgesSniperStatTracker; import nautilus.game.arcade.stats.*;
import nautilus.game.arcade.stats.DeathBomberStatTracker; import org.bukkit.*;
import nautilus.game.arcade.stats.FoodForTheMassesStatTracker; import org.bukkit.block.Block;
import nautilus.game.arcade.stats.KillFastStatTracker; import org.bukkit.block.BlockFace;
import nautilus.game.arcade.stats.TntMinerStatTracker; import org.bukkit.block.Chest;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.*;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
import java.util.*;
public class Bridge extends TeamGame implements OreObsfucation public class Bridge extends TeamGame implements OreObsfucation
{ {
@ -186,7 +134,8 @@ public class Bridge extends TeamGame implements OreObsfucation
new Kit[] new Kit[]
{ {
new KitApple(manager), new KitApple(manager),
new KitBeserker(manager), new KitBerserker(manager),
new KitBrawler(manager),
new KitMammoth(manager), new KitMammoth(manager),
new KitArcher(manager), new KitArcher(manager),
new KitMiner(manager), new KitMiner(manager),
@ -201,6 +150,28 @@ public class Bridge extends TeamGame implements OreObsfucation
"The last team alive wins!" "The last team alive wins!"
}); });
List<Kit> kits = Lists.newArrayList(GetKits());
List<Kit> finalKits = Lists.newArrayList(kits);
boolean foundBrawler = false;
for(int i = 0; i < kits.size(); i++)
{
Kit kit = kits.get(i);
if(kit.GetName().equalsIgnoreCase("Brawler"))
{
if(!foundBrawler)
{
foundBrawler = true;
}
else
{
finalKits.remove(i);
}
}
}
setKits(finalKits.toArray(new Kit[finalKits.size()]));
_ore = new OreHider(); _ore = new OreHider();
// Flags // Flags
@ -258,28 +229,6 @@ public class Bridge extends TeamGame implements OreObsfucation
_tournament = Manager.IsTournamentServer(); _tournament = Manager.IsTournamentServer();
} }
@EventHandler
public void blockTntDupe(InventoryClickEvent event)
{
Player player = (Player) event.getWhoClicked();
ItemStack itemStack = event.getCurrentItem();
InventoryView view = player.getOpenInventory();
if(view.getTopInventory() == null || itemStack == null || itemStack.getType() != Material.TNT)
{
return;
}
if(event.getClickedInventory() == null)
{
return;
}
if(event.getClickedInventory().getType() == InventoryType.PLAYER)
{
return;
}
event.setCancelled(true);
}
@EventHandler @EventHandler
public void PlayerOut(final PlayerDeathOutEvent event) public void PlayerOut(final PlayerDeathOutEvent event)
{ {

View File

@ -1,39 +1,39 @@
package nautilus.game.arcade.game.games.bridge.kits; package nautilus.game.arcade.game.games.bridge.kits;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkApple;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import nautilus.game.arcade.ArcadeManager; public class KitApple extends ProgressingKit
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.*;
public class KitApple extends Kit
{ {
private static final String[] DESCRIPTION = {
"Possess the rare skill of finding apples frequently!",
"",
receiveItem("apple", 1, 10, 0),
click(true, "the apple to throw it")
};
private static final Perk[] PERKS = {
new PerkApple()
};
private static final ItemStack IN_HAND = new ItemStack(Material.APPLE);
public KitApple(ArcadeManager manager) public KitApple(ArcadeManager manager)
{ {
super(manager, "Apple", KitAvailability.Free, super(manager, "Apple", "bridgeapple", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Possess the rare skill of finding apples frequently!"
},
new Perk[]
{
new PerkApple(manager)
},
EntityType.ZOMBIE,
new ItemStack(Material.APPLE));
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
} }
} }

View File

@ -1,37 +1,45 @@
package nautilus.game.arcade.game.games.bridge.kits; package nautilus.game.arcade.game.games.bridge.kits;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.bridge.Bridge; import nautilus.game.arcade.game.games.bridge.Bridge;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkBarrage; import nautilus.game.arcade.kit.perks.PerkBarrage;
import nautilus.game.arcade.kit.perks.PerkFletcher; import nautilus.game.arcade.kit.perks.PerkFletcher;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class KitArcher extends Kit public class KitArcher extends ProgressingKit
{ {
private static final String[] DESCRIPTION = {
"Highly trained with a bow, probably an elf or something...",
" ",
"Begin the game with a Bow",
receiveArrowString(1, 20, 3),
"Charge Bow to use " + C.cGreen + "Barrage"
};
private static final Perk[] PERKS = {
new PerkFletcher(20, 3, true),
new PerkBarrage(5, 250, true, false),
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.BOW)
};
private static final ItemStack IN_HAND = new ItemStack(Material.BOW);
public KitArcher(ArcadeManager manager) public KitArcher(ArcadeManager manager)
{ {
super(manager, "Archer", KitAvailability.Gem, super(manager, "Archer", "bridgearcher", KitAvailability.Gem, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Highly trained with a bow, probably an elf or something..."
},
new Perk[]
{
new PerkFletcher(20, 3, true),
new PerkBarrage(5, 250, true, false),
},
EntityType.ZOMBIE,
new ItemStack(Material.BOW));
} }
@ -42,7 +50,7 @@ public class KitArcher extends Kit
{ {
return; return;
} }
Bridge bridge = (Bridge) Manager.GetGame(); Bridge bridge = (Bridge) Manager.GetGame();
if(!bridge.hasUsedRevive(player)) if(!bridge.hasUsedRevive(player))
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW)); player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW));

View File

@ -0,0 +1,49 @@
package nautilus.game.arcade.game.games.bridge.kits;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkAxeman;
import nautilus.game.arcade.kit.perks.PerkLeap;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class KitBerserker extends ProgressingKit
{
private static final String[] DESCRIPTION = {
"Agile warrior trained in the ways of axe combat.",
" ",
"Begin with a Stone Axe",
"Deal " + C.cGreen + "+1" + C.cWhite + " damage using axes",
click(false, " with your axe to use " + C.cGreen + "Berserker Leap")
};
private static final Perk[] PERKS = {
new PerkLeap("Beserker Leap", 1.2, 1.2, 8000),
new PerkAxeman(),
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.STONE_AXE)
};
private static final ItemStack IN_HAND = new ItemStack(Material.STONE_AXE);
public KitBerserker(ArcadeManager manager)
{
super(manager, "Berserker", "bridgeberserker", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
}
@Override
public void GiveItems(Player player)
{
player.getInventory().addItem(PLAYER_ITEMS);
}
}

View File

@ -1,49 +0,0 @@
package nautilus.game.arcade.game.games.bridge.kits;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.bridge.Bridge;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.*;
public class KitBeserker extends Kit
{
public KitBeserker(ArcadeManager manager)
{
super(manager, "Beserker", KitAvailability.Free,
new String[]
{
"Agile warrior trained in the ways of axe combat."
},
new Perk[]
{
new PerkLeap("Beserker Leap", 1.2, 1.2, 8000),
new PerkAxeman(),
},
EntityType.ZOMBIE,
new ItemStack(Material.STONE_AXE));
}
@Override
public void GiveItems(Player player)
{
if(!(Manager.GetGame() instanceof Bridge))
{
return;
}
Bridge bridge = (Bridge) Manager.GetGame();
if(!bridge.hasUsedRevive(player))
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.STONE_AXE));
}
}

View File

@ -1,39 +1,40 @@
package nautilus.game.arcade.game.games.bridge.kits; package nautilus.game.arcade.game.games.bridge.kits;
import mineplex.core.common.util.C;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkBomber;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import nautilus.game.arcade.ArcadeManager; public class KitBomber extends ProgressingKit
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.*;
public class KitBomber extends Kit
{ {
private static final String[] DESCRIPTION = {
"Crazy bomb throwing guy.",
" ",
receiveItem("TNT", 1, 30, 2),
C.cYellow + "Click" + C.cWhite + " to throw TNT"
};
private static final Perk[] PERKS = {
new PerkBomber(30, 2, -1)
};
private static final ItemStack IN_HAND = new ItemStack(Material.TNT);
public KitBomber(ArcadeManager manager) public KitBomber(ArcadeManager manager)
{ {
super(manager, "Bomber", KitAvailability.Gem, 5000, super(manager, "Bomber", "bridgebomber", KitAvailability.Gem, 5000, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Crazy bomb throwing guy."
},
new Perk[]
{
new PerkBomber(30, 2, -1)
},
EntityType.ZOMBIE,
new ItemStack(Material.TNT));
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
} }
} }

View File

@ -0,0 +1,50 @@
package nautilus.game.arcade.game.games.bridge.kits;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkIronSkin;
import nautilus.game.arcade.kit.perks.PerkMammoth;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class KitBrawler extends ProgressingKit
{
private static final String[] DESCRIPTION = {
"Giant and muscular, easily smacks others around.",
" ",
"Begin with an Iron Sword",
"Take " + C.cGreen + "75%" + C.cWhite + " knockback",
"Deal " + C.cGreen + "125%" + C.cWhite + " knockback",
"Take " + C.cGreen + "-1" + C.cWhite + " damage from all attacks"
};
private static final Perk[] PERKS = {
new PerkMammoth(),
new PerkIronSkin(1)
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.IRON_SWORD)
};
private static final ItemStack IN_HAND = new ItemStack(Material.IRON_SWORD);
public KitBrawler(ArcadeManager manager)
{
super(manager, "Brawler", "bridgebrawler", KitAvailability.Gem, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
}
@Override
public void GiveItems(Player player)
{
player.getInventory().addItem(PLAYER_ITEMS);
}
}

View File

@ -1,44 +1,50 @@
package nautilus.game.arcade.game.games.bridge.kits; package nautilus.game.arcade.game.games.bridge.kits;
import mineplex.core.achievement.Achievement;
import mineplex.core.common.util.C;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkDestructor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.achievement.Achievement; public class KitDestructor extends ProgressingKit
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.*;
public class KitDestructor extends Kit
{ {
private static final String[] DESCRIPTION = {
"Has the ability to make the world crumble!",
" ",
receiveItem("Seismic Charge", 1, 40, 2),
C.cYellow + "Right-Click" + C.cWhite + " with Seismic Charge to " + C.cGreen + "Throw Seismic Charge",
"",
C.cRed + "Seismic Charges begin after bridges drop"
};
private static final Perk[] PERKS = {
new PerkDestructor(40, 2, 400, false)
};
private static final Achievement[] ACHIEVEMENTS = {
Achievement.BRIDGES_DEATH_BOMBER,
Achievement.BRIDGES_FOOD,
Achievement.BRIDGES_FORTUNE_BOMBER,
Achievement.BRIDGES_RAMPAGE,
Achievement.BRIDGES_SNIPER,
Achievement.BRIDGES_WINS
};
private static final ItemStack IN_HAND = new ItemStack(Material.ENDER_PEARL);
public KitDestructor(ArcadeManager manager) public KitDestructor(ArcadeManager manager)
{ {
super(manager, "Destructor", KitAvailability.Achievement, 99999, super(manager, "Destructor", "bridgedesctructor", KitAvailability.Achievement, 99999, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[] this.setAchievementRequirements(ACHIEVEMENTS);
{
"Has the ability to make the world crumble!"
},
new Perk[]
{
new PerkDestructor(40, 2, 400, false)
},
EntityType.ZOMBIE,
new ItemStack(Material.ENDER_PEARL));
this.setAchievementRequirements(new Achievement[]
{
Achievement.BRIDGES_DEATH_BOMBER,
Achievement.BRIDGES_FOOD,
Achievement.BRIDGES_FORTUNE_BOMBER,
Achievement.BRIDGES_RAMPAGE,
Achievement.BRIDGES_SNIPER,
Achievement.BRIDGES_WINS
});
} }
@Override @Override

View File

@ -1,36 +1,45 @@
package nautilus.game.arcade.game.games.bridge.kits; package nautilus.game.arcade.game.games.bridge.kits;
import org.bukkit.Material; import mineplex.core.common.util.C;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.bridge.Bridge; import nautilus.game.arcade.game.games.bridge.Bridge;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.*; import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.perks.PerkDigger;
import nautilus.game.arcade.kit.perks.PerkOreFinder;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class KitMiner extends Kit public class KitMiner extends ProgressingKit
{ {
private static final String[] DESCRIPTION = {
"Master of ore prospecting and digging quickly.",
" ",
"Begin with a Stone Pickaxe",
"Receive " + C.cGreen + "Haste 2",
click(false, "your pickaxe to " + C.cGreen + "find ores"),
};
private static final Perk[] PERKS = {
new PerkOreFinder(),
new PerkDigger(),
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.STONE_PICKAXE)
};
private static final ItemStack IN_HAND = new ItemStack(Material.STONE_PICKAXE);
public KitMiner(ArcadeManager manager) public KitMiner(ArcadeManager manager)
{ {
super(manager, "Miner", KitAvailability.Gem, 5000, super(manager, "Miner", "bridgeminer", KitAvailability.Gem, 5000, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Master of ore prospecting and digging quickly."
},
new Perk[]
{
new PerkOreFinder(),
new PerkDigger(),
},
EntityType.ZOMBIE,
new ItemStack(Material.STONE_PICKAXE));
} }
@ -41,7 +50,7 @@ public class KitMiner extends Kit
{ {
return; return;
} }
Bridge bridge = (Bridge) Manager.GetGame(); Bridge bridge = (Bridge) Manager.GetGame();
if(!bridge.hasUsedRevive(player)) if(!bridge.hasUsedRevive(player))
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.STONE_PICKAXE)); player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.STONE_PICKAXE));

View File

@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -21,6 +22,7 @@ import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
@ -49,6 +51,8 @@ public class OverpoweredBridge extends Bridge
WorldBoundaryKill = true; WorldBoundaryKill = true;
Manager.GetDamage().SetEnabled(false);
new AbsorptionFix(this); new AbsorptionFix(this);
} }
@ -128,6 +132,10 @@ public class OverpoweredBridge extends Bridge
public void supplyChest(PlayerPrepareTeleportEvent event) public void supplyChest(PlayerPrepareTeleportEvent event)
{ {
Location chestLoc = event.GetPlayer().getLocation().clone().add(0, 0, 1); Location chestLoc = event.GetPlayer().getLocation().clone().add(0, 0, 1);
while (chestLoc.getBlock().getType() == Material.CHEST)
chestLoc.add(2, 0, 0);
_starterChests.put(event.GetPlayer(), chestLoc); _starterChests.put(event.GetPlayer(), chestLoc);
Block block = chestLoc.getBlock(); Block block = chestLoc.getBlock();
@ -136,8 +144,9 @@ public class OverpoweredBridge extends Bridge
Chest chest = (Chest) block.getState(); Chest chest = (Chest) block.getState();
event.GetPlayer().getLocation().getBlock().setType(Material.WALL_SIGN); Block signBlock = chestLoc.clone().add(0, 0, -1).getBlock();
Sign sign = (Sign) event.GetPlayer().getLocation().getBlock().getState(); signBlock.setType(Material.WALL_SIGN);
Sign sign = (Sign) signBlock.getState();
sign.setLine(0, "§b============="); sign.setLine(0, "§b=============");
sign.setLine(1, "§4§l" + event.GetPlayer().getName() + ChatColor.RESET + "§4's"); sign.setLine(1, "§4§l" + event.GetPlayer().getName() + ChatColor.RESET + "§4's");
sign.setLine(2, "§4Supply Chest"); sign.setLine(2, "§4Supply Chest");
@ -182,20 +191,20 @@ public class OverpoweredBridge extends Bridge
if (event.getClickedBlock().getType() != Material.CHEST) if (event.getClickedBlock().getType() != Material.CHEST)
return; return;
for (Player player : _starterChests.keySet()) if (disallow(event.getPlayer(), event.getClickedBlock()))
{ event.setCancelled(true);
if (player == event.getPlayer())
continue;
if (_starterChests.get(player).getBlock().getLocation()
.equals(event.getClickedBlock().getLocation()))
{
event.setCancelled(true);
break;
}
}
} }
} }
@EventHandler
public void placeChest(BlockPlaceEvent event)
{
if (event.getBlockPlaced().getType() != Material.CHEST)
return;
if (disallow(event.getPlayer(), event.getBlock()))
event.setCancelled(true);
}
@EventHandler @EventHandler
public void CheatChestBreak(BlockBreakEvent event) public void CheatChestBreak(BlockBreakEvent event)
@ -219,6 +228,32 @@ public class OverpoweredBridge extends Bridge
} }
} }
} }
private boolean disallow(Player clicker, Block block)
{
for (Player player : _starterChests.keySet())
{
System.out.println("test4");
if (player == clicker)
continue;
System.out.println("test2");
Location chest = _starterChests.get(player);
if (chest.getBlock().getLocation().equals(block.getLocation()))
{
System.out.println("test1");
return true;
}
for (Block surround : UtilBlock.getSurrounding(block, false))
{
if(chest.getBlock().getLocation().equals(surround.getLocation()))
return true;
}
}
return false;
}
@Override @Override
public void ParseOre(ArrayList<Location> teamOre) public void ParseOre(ArrayList<Location> teamOre)

View File

@ -9,14 +9,6 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.games.bridge.Bridge; import nautilus.game.arcade.game.games.bridge.Bridge;
import nautilus.game.arcade.game.games.bridge.kits.KitApple;
import nautilus.game.arcade.game.games.bridge.kits.KitArcher;
import nautilus.game.arcade.game.games.bridge.kits.KitBeserker;
import nautilus.game.arcade.game.games.bridge.kits.KitBomber;
import nautilus.game.arcade.game.games.bridge.kits.KitDestructor;
import nautilus.game.arcade.game.games.bridge.kits.KitMammoth;
import nautilus.game.arcade.game.games.bridge.kits.KitMiner;
import nautilus.game.arcade.kit.Kit;
/** /**
* SpeedBridges gamemode for Bridges * SpeedBridges gamemode for Bridges

View File

@ -1,31 +1,28 @@
package nautilus.game.arcade.game.games.build.kits; package nautilus.game.arcade.game.games.build.kits;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import nautilus.game.arcade.ArcadeManager; public class KitBuilder extends ProgressingKit
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public class KitBuilder extends Kit
{ {
private static final String[] DESCRIPTION = {
"Can I build it!? Yes I can!"
};
private static final Perk[] PERKS = {};
private static final ItemStack IN_HAND = new ItemStack(Material.WOOD);
public KitBuilder(ArcadeManager manager) public KitBuilder(ArcadeManager manager)
{ {
super(manager, "Builder", KitAvailability.Free, super(manager, "Builder", "buildbuilder", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.SKELETON, IN_HAND);
new String[]
{
"Can I build it!? Yes I can!"
},
new Perk[]
{
},
EntityType.SKELETON,
new ItemStack(Material.WOOD));
} }

View File

@ -1,22 +1,18 @@
package nautilus.game.arcade.game.games.castlesiege.kits; package nautilus.game.arcade.game.games.castlesiege.kits;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import nautilus.game.arcade.ArcadeManager; public abstract class KitHuman extends ProgressingKit
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public abstract class KitHuman extends Kit
{ {
public KitHuman(ArcadeManager manager, String name, KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand) public KitHuman(ArcadeManager manager, String name, KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{ {
super(manager, name, kitAvailability, kitDesc, kitPerks, entityType, itemInHand); super(manager, name, name.toLowerCase().replace(" ", ""), kitAvailability, kitDesc, kitPerks, entityType, itemInHand);
} }
public KitHuman(ArcadeManager manager, String name, KitAvailability kitAvailability, int cost, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{
super(manager, name, kitAvailability, cost, kitDesc, kitPerks, entityType, itemInHand);
}
} }

View File

@ -1,81 +0,0 @@
package nautilus.game.arcade.game.games.castlesiege.kits;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkFletcher;
import nautilus.game.arcade.kit.perks.PerkLeap;
import nautilus.game.arcade.kit.perks.PerkPowershot;
import nautilus.game.arcade.kit.perks.PerkRegeneration;
public class KitHumanAssassin extends KitHuman
{
public KitHumanAssassin(ArcadeManager manager)
{
super(manager, "Castle Assassin", KitAvailability.Gem, 5000,
new String[]
{
"Able to kill with a single shot!"
},
new Perk[]
{
new PerkFletcher(2, 4, false),
new PerkLeap("Leap", 1.2, 1, 8000),
new PerkPowershot(5, 400),
new PerkRegeneration(0),
},
EntityType.ZOMBIE,
new ItemStack(Material.BOW));
}
@EventHandler
public void FireItemResist(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
if (Manager.GetGame() == null)
return;
for (Player player : Manager.GetGame().GetPlayers(true))
{
if (!HasKit(player))
continue;
Manager.GetCondition().Factory().FireItemImmunity(GetName(), player, player, 1.9, false);
}
}
@Override
public void GiveItems(Player player)
{
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.DIAMOND_AXE));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW));
player.getInventory().setHelmet(ItemStackFactory.Instance.CreateStack(Material.LEATHER_HELMET));
player.getInventory().setChestplate(ItemStackFactory.Instance.CreateStack(Material.LEATHER_CHESTPLATE));
player.getInventory().setLeggings(ItemStackFactory.Instance.CreateStack(Material.LEATHER_LEGGINGS));
player.getInventory().setBoots(ItemStackFactory.Instance.CreateStack(Material.LEATHER_BOOTS));
}
@Override
public void SpawnCustom(LivingEntity ent)
{
ent.getEquipment().setHelmet(new ItemStack(Material.LEATHER_HELMET));
ent.getEquipment().setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE));
ent.getEquipment().setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
ent.getEquipment().setBoots(new ItemStack(Material.LEATHER_BOOTS));
}
}

View File

@ -1,82 +0,0 @@
package nautilus.game.arcade.game.games.castlesiege.kits;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkCleave;
import nautilus.game.arcade.kit.perks.PerkKnockbackGive;
import nautilus.game.arcade.kit.perks.PerkSeismicSlamCS;
public class KitHumanBrawler extends KitHuman
{
public KitHumanBrawler(ArcadeManager manager)
{
super(manager, "Castle Brawler", KitAvailability.Gem, 5000,
new String[]
{
"Extremely tanky, can smash the undead around."
},
new Perk[]
{
new PerkSeismicSlamCS(),
new PerkCleave(0.75, true),
},
EntityType.ZOMBIE, new ItemStack(Material.IRON_AXE));
}
@EventHandler
public void FireItemResist(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
if (Manager.GetGame() == null)
return;
for (Player player : Manager.GetGame().GetPlayers(true))
{
if (!HasKit(player))
continue;
Manager.GetCondition().Factory().FireItemImmunity(GetName(), player, player, 1.9, false);
}
}
@Override
public void GiveItems(Player player)
{
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_AXE));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.ARROW, 16));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().setHelmet(ItemStackFactory.Instance.CreateStack(Material.DIAMOND_HELMET));
player.getInventory().setChestplate(ItemStackFactory.Instance.CreateStack(Material.DIAMOND_CHESTPLATE));
player.getInventory().setLeggings(ItemStackFactory.Instance.CreateStack(Material.DIAMOND_LEGGINGS));
player.getInventory().setBoots(ItemStackFactory.Instance.CreateStack(Material.DIAMOND_BOOTS));
}
@Override
public void SpawnCustom(LivingEntity ent)
{
ent.getEquipment().setHelmet(new ItemStack(Material.DIAMOND_HELMET));
ent.getEquipment().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
ent.getEquipment().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS));
ent.getEquipment().setBoots(new ItemStack(Material.DIAMOND_BOOTS));
}
}

View File

@ -1,5 +1,15 @@
package nautilus.game.arcade.game.games.castlesiege.kits; package nautilus.game.arcade.game.games.castlesiege.kits;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkConstructor;
import nautilus.game.arcade.kit.perks.PerkMammoth;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -7,35 +17,45 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.F;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.*;
public class KitHumanKnight extends KitHuman public class KitHumanKnight extends KitHuman
{ {
private static final String[] DESCRIPTION = {
"Robust knight, also able to construct defenses.",
" ",
receiveItem("oak fence", 1, 40, 2),
"Take " + C.cGreen + "75%" + C.cWhite + " knockback",
"Deal " + C.cGreen + "125%" + C.cWhite + " knockback",
};
private static final Perk[] PERKS = {
new PerkMammoth(),
new PerkConstructor("Constructor", 40, 2, Material.FENCE, "Castle Barricade", true)
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.IRON_SWORD),
ItemStackFactory.Instance.CreateStack(Material.BOW),
ItemStackFactory.Instance.CreateStack(Material.ARROW, 64),
ItemStackFactory.Instance.CreateStack(Material.FENCE, (byte) 0, 2, F.item("Castle Barricade")),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP)
};
private static final ItemStack[] ARMOR = {
ItemStackFactory.Instance.CreateStack(Material.IRON_HELMET),
ItemStackFactory.Instance.CreateStack(Material.IRON_CHESTPLATE),
ItemStackFactory.Instance.CreateStack(Material.IRON_LEGGINGS),
ItemStackFactory.Instance.CreateStack(Material.IRON_BOOTS)
};
public static final ItemStack IN_HAND = new ItemStack(Material.IRON_SWORD);
public KitHumanKnight(ArcadeManager manager) public KitHumanKnight(ArcadeManager manager)
{ {
super(manager, "Castle Knight", KitAvailability.Gem, super(manager, "Castle Knight", KitAvailability.Gem, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Robust knight, also able to construct defenses."
},
new Perk[]
{
new PerkMammoth(),
new PerkConstructor("Constructor", 40, 2, Material.FENCE, "Castle Barricade", true)
},
EntityType.ZOMBIE, new ItemStack(Material.IRON_SWORD));
} }
@EventHandler @EventHandler
@ -59,23 +79,10 @@ public class KitHumanKnight extends KitHuman
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_SWORD)); player.getInventory().addItem(PLAYER_ITEMS);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW)); player.getInventory().setArmorContents(ARMOR);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.ARROW, 64));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.FENCE, (byte)0, 2, F.item("Castle Barricade")));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().setHelmet(ItemStackFactory.Instance.CreateStack(Material.IRON_HELMET));
player.getInventory().setChestplate(ItemStackFactory.Instance.CreateStack(Material.IRON_CHESTPLATE));
player.getInventory().setLeggings(ItemStackFactory.Instance.CreateStack(Material.IRON_LEGGINGS));
player.getInventory().setBoots(ItemStackFactory.Instance.CreateStack(Material.IRON_BOOTS));
} }
@Override @Override
public void SpawnCustom(LivingEntity ent) public void SpawnCustom(LivingEntity ent)
{ {

View File

@ -1,5 +1,14 @@
package nautilus.game.arcade.game.games.castlesiege.kits; package nautilus.game.arcade.game.games.castlesiege.kits;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkBarrage;
import nautilus.game.arcade.kit.perks.PerkFletcher;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -7,70 +16,76 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkBarrage;
import nautilus.game.arcade.kit.perks.PerkFletcher;
public class KitHumanMarksman extends KitHuman public class KitHumanMarksman extends KitHuman
{ {
private static final String[] DESCRIPTION = {
"Skilled human marksman, can fletch arrows.",
" ",
receiveArrowString(1, 2, 4),
"Charge your Bow to use " + C.cGreen + "Barrage"
};
private static final Perk[] PERKS = {
new PerkBarrage(5, 250, true, false),
new PerkFletcher(2, 4, false),
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.STONE_SWORD),
ItemStackFactory.Instance.CreateStack(Material.BOW),
ItemStackFactory.Instance.CreateStack(Material.ARROW, 32),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP),
ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP)
};
private static final ItemStack[] ARMOR = {
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_HELMET),
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_CHESTPLATE),
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_LEGGINGS),
ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_BOOTS)
};
public static final ItemStack IN_HAND = new ItemStack(Material.BOW);
public KitHumanMarksman(ArcadeManager manager) public KitHumanMarksman(ArcadeManager manager)
{ {
super(manager, "Castle Marksman", KitAvailability.Free, super(manager, "Castle Marksman", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Skilled human marksman, can fletch arrows."
},
new Perk[]
{
new PerkBarrage(5, 250, true, false),
new PerkFletcher(2, 4, false),
},
EntityType.ZOMBIE,
new ItemStack(Material.BOW));
} }
@EventHandler @EventHandler
public void FireItemResist(UpdateEvent event) public void FireItemResist(UpdateEvent event)
{ {
if (event.getType() != UpdateType.FAST) if (event.getType() != UpdateType.FAST)
{
return; return;
}
if (Manager.GetGame() == null) if (Manager.GetGame() == null)
{
return; return;
}
for (Player player : Manager.GetGame().GetPlayers(true)) for (Player player : Manager.GetGame().GetPlayers(true))
{ {
if (!HasKit(player)) if (!HasKit(player))
{
continue; continue;
}
Manager.GetCondition().Factory().FireItemImmunity(GetName(), player, player, 1.9, false); Manager.GetCondition().Factory().FireItemImmunity(GetName(), player, player, 1.9, false);
} }
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.STONE_SWORD)); player.getInventory().addItem(PLAYER_ITEMS);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW)); player.getInventory().setArmorContents(ARMOR);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.ARROW, 32));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP));
player.getInventory().setHelmet(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_HELMET));
player.getInventory().setChestplate(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_CHESTPLATE));
player.getInventory().setLeggings(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_LEGGINGS));
player.getInventory().setBoots(ItemStackFactory.Instance.CreateStack(Material.CHAINMAIL_BOOTS));
} }
@Override @Override
public void SpawnCustom(LivingEntity ent) public void SpawnCustom(LivingEntity ent)
{ {
ent.getEquipment().setHelmet(new ItemStack(Material.CHAINMAIL_HELMET)); ent.getEquipment().setHelmet(new ItemStack(Material.CHAINMAIL_HELMET));
ent.getEquipment().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE)); ent.getEquipment().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));

View File

@ -1,70 +1,74 @@
package nautilus.game.arcade.game.games.castlesiege.kits; package nautilus.game.arcade.game.games.castlesiege.kits;
import mineplex.core.disguise.disguises.DisguiseWolf;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkKnockbackGive;
import nautilus.game.arcade.kit.perks.PerkStrength;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.disguise.disguises.DisguisePig;
import mineplex.core.disguise.disguises.DisguisePigZombie;
import mineplex.core.disguise.disguises.DisguiseWolf;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkKnockbackGive;
import nautilus.game.arcade.kit.perks.PerkStrength;
public class KitHumanPeasant extends KitHuman public class KitHumanPeasant extends KitHuman
{ {
private static final String[] DESCRIPTION = {
"OINK! OINK!"
};
private static final Perk[] PERKS = {
new PerkStrength(1),
new PerkKnockbackGive(2)
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.BONE, (byte) 0, 0, "Wolf Bite")
};
public static final ItemStack IN_HAND = new ItemStack(Material.IRON_HOE);
public KitHumanPeasant(ArcadeManager manager) public KitHumanPeasant(ArcadeManager manager)
{ {
super(manager, "Castle Wolf", KitAvailability.Hide, super(manager, "Castle Wolf", KitAvailability.Hide, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"OINK! OINK!"
},
new Perk[]
{
new PerkStrength(1),
new PerkKnockbackGive(2)
},
EntityType.ZOMBIE, new ItemStack(Material.IRON_HOE));
} }
@EventHandler @EventHandler
public void FireItemResist(UpdateEvent event) public void FireItemResist(UpdateEvent event)
{ {
if (event.getType() != UpdateType.FAST) if (event.getType() != UpdateType.FAST)
{
return; return;
}
if (Manager.GetGame() == null) if (Manager.GetGame() == null)
{
return; return;
}
for (Player player : Manager.GetGame().GetPlayers(true)) for (Player player : Manager.GetGame().GetPlayers(true))
{ {
if (!HasKit(player)) if (!HasKit(player))
{
continue; continue;
}
Manager.GetCondition().Factory().FireItemImmunity(GetName(), player, player, 1.9, false); Manager.GetCondition().Factory().FireItemImmunity(GetName(), player, player, 1.9, false);
} }
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BONE, (byte)0, 0, "Wolf Bite")); player.getInventory().addItem(PLAYER_ITEMS);
player.setHealth(4); player.setHealth(4);
DisguiseWolf disguise = new DisguiseWolf(player); DisguiseWolf disguise = new DisguiseWolf(player);
disguise.setName(Manager.GetGame().GetTeam(player).GetColor() + player.getName()); disguise.setName(Manager.GetGame().GetTeam(player).GetColor() + player.getName());
disguise.setCustomNameVisible(true); disguise.setCustomNameVisible(true);

View File

@ -1,22 +1,21 @@
package nautilus.game.arcade.game.games.castlesiege.kits; package nautilus.game.arcade.game.games.castlesiege.kits;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import nautilus.game.arcade.ArcadeManager; public abstract class KitUndead extends ProgressingKit
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public abstract class KitUndead extends Kit
{ {
public KitUndead(ArcadeManager manager, String name, KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand) public KitUndead(ArcadeManager manager, String name, KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{ {
super(manager, name, kitAvailability, kitDesc, kitPerks, entityType, itemInHand); super(manager, name, name.toLowerCase().replace(" ", ""), kitAvailability, kitDesc, kitPerks, entityType, itemInHand);
} }
public KitUndead(ArcadeManager manager, String name, KitAvailability kitAvailability, int cost, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand) public KitUndead(ArcadeManager manager, String name, KitAvailability kitAvailability, int cost, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{ {
super(manager, name, kitAvailability, cost, kitDesc, kitPerks, entityType, itemInHand); super(manager, name, name.toLowerCase().replace(" ", ""), kitAvailability, cost, kitDesc, kitPerks, entityType, itemInHand);
} }
} }

View File

@ -1,5 +1,13 @@
package nautilus.game.arcade.game.games.castlesiege.kits; package nautilus.game.arcade.game.games.castlesiege.kits;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv;
import mineplex.core.disguise.disguises.DisguiseSkeleton;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkIronSkin;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -8,63 +16,59 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilInv;
import mineplex.core.disguise.disguises.DisguiseSkeleton;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkIronSkin;
public class KitUndeadArcher extends KitUndead public class KitUndeadArcher extends KitUndead
{ {
private static final String[] DESCRIPTION = {
"Makes use of arrows scavenged from human archers.",
" ",
"Take " + C.cGreen + "-1" + C.cWhite + " damage from attacks"
};
private static final Perk[] PERKS = {
new PerkIronSkin(1)
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.STONE_AXE),
ItemStackFactory.Instance.CreateStack(Material.BOW)
};
public static final ItemStack IN_HAND = new ItemStack(Material.BOW);
public KitUndeadArcher(ArcadeManager manager) public KitUndeadArcher(ArcadeManager manager)
{ {
super(manager, "Undead Archer", KitAvailability.Gem, super(manager, "Undead Archer", KitAvailability.Gem, DESCRIPTION, PERKS, EntityType.SKELETON, IN_HAND);
new String[]
{
"Makes use of arrows scavenged from human archers."
},
new Perk[]
{
new PerkIronSkin(1)
},
EntityType.SKELETON,
new ItemStack(Material.BOW));
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.STONE_AXE)); player.getInventory().addItem(PLAYER_ITEMS);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW));
DisguiseSkeleton disguise = new DisguiseSkeleton(player); DisguiseSkeleton disguise = new DisguiseSkeleton(player);
disguise.setName(Manager.GetGame().GetTeam(player).GetColor() + player.getName()); disguise.setName(Manager.GetGame().GetTeam(player).GetColor() + player.getName());
disguise.setCustomNameVisible(true); disguise.setCustomNameVisible(true);
Manager.GetDisguise().disguise(disguise); Manager.GetDisguise().disguise(disguise);
} }
@EventHandler @EventHandler
public void ArrowPickup(PlayerPickupItemEvent event) public void ArrowPickup(PlayerPickupItemEvent event)
{ {
if (event.getItem().getItemStack().getType() != Material.ARROW) if (event.getItem().getItemStack().getType() != Material.ARROW)
return; return;
if (!HasKit(event.getPlayer())) if (!HasKit(event.getPlayer()))
return; return;
if (UtilInv.contains(event.getPlayer(), Material.ARROW, (byte)0, 4)) if (UtilInv.contains(event.getPlayer(), Material.ARROW, (byte)0, 4))
return; return;
event.getItem().remove(); event.getItem().remove();
event.getPlayer().getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.ARROW)); event.getPlayer().getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.ARROW));
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ITEM_PICKUP, 1f, 1f); event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ITEM_PICKUP, 1f, 1f);
} }
} }

View File

@ -1,5 +1,13 @@
package nautilus.game.arcade.game.games.castlesiege.kits; package nautilus.game.arcade.game.games.castlesiege.kits;
import mineplex.core.common.util.C;
import mineplex.core.disguise.disguises.DisguisePigZombie;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkLeap;
import nautilus.game.arcade.kit.perks.PerkSpeed;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -7,39 +15,36 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.disguise.disguises.DisguisePigZombie;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.*;
public class KitUndeadGhoul extends KitUndead public class KitUndeadGhoul extends KitUndead
{ {
private static final String[] DESCRIPTION = {
"Weak, but able to jump around with ease.",
" ",
click(false, "your axe to use " + C.cGreen + "Ghoul Leap"),
};
private static final Perk[] PERKS = {
new PerkLeap("Ghoul Leap", 1.2, 0.8, 8000),
new PerkSpeed(0)
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.STONE_AXE),
};
public static final ItemStack IN_HAND = new ItemStack(Material.STONE_AXE);
public KitUndeadGhoul(ArcadeManager manager) public KitUndeadGhoul(ArcadeManager manager)
{ {
super(manager, "Undead Ghoul", KitAvailability.Free, super(manager, "Undead Ghoul", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.PIG_ZOMBIE, IN_HAND);
new String[]
{
"Weak, but able to jump around with ease."
},
new Perk[]
{
new PerkLeap("Ghoul Leap", 1.2, 0.8, 8000),
new PerkSpeed(0)
},
EntityType.PIG_ZOMBIE,
new ItemStack(Material.STONE_AXE));
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.STONE_AXE)); player.getInventory().addItem(PLAYER_ITEMS);
DisguisePigZombie disguise = new DisguisePigZombie(player); DisguisePigZombie disguise = new DisguisePigZombie(player);
disguise.setName(Manager.GetGame().GetTeam(player).GetColor() + player.getName()); disguise.setName(Manager.GetGame().GetTeam(player).GetColor() + player.getName());
disguise.setCustomNameVisible(true); disguise.setCustomNameVisible(true);
@ -50,9 +55,13 @@ public class KitUndeadGhoul extends KitUndead
public void PickupArrow(PlayerPickupItemEvent event) public void PickupArrow(PlayerPickupItemEvent event)
{ {
if (!HasKit(event.getPlayer())) if (!HasKit(event.getPlayer()))
{
return; return;
}
if (event.getItem().getItemStack().getType() == Material.ARROW) if (event.getItem().getItemStack().getType() == Material.ARROW)
{
event.setCancelled(true); event.setCancelled(true);
}
} }
} }

View File

@ -1,5 +1,12 @@
package nautilus.game.arcade.game.games.castlesiege.kits; package nautilus.game.arcade.game.games.castlesiege.kits;
import mineplex.core.common.util.C;
import mineplex.core.disguise.disguises.DisguiseZombie;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkRegeneration;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -7,39 +14,36 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.disguise.disguises.DisguiseZombie;
import mineplex.core.itemstack.ItemStackFactory;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.*;
public class KitUndeadZombie extends KitUndead public class KitUndeadZombie extends KitUndead
{ {
private static final String[] DESCRIPTION = {
"Regenerates rapidly",
" ",
"Receive " + C.cGreen + "Regeneration III"
};
private static final Perk[] PERKS = {
new PerkRegeneration(2)
};
private static final ItemStack[] PLAYER_ITEMS = {
ItemStackFactory.Instance.CreateStack(Material.STONE_AXE),
};
public static final ItemStack IN_HAND = new ItemStack(Material.STONE_AXE);
public KitUndeadZombie(ArcadeManager manager) public KitUndeadZombie(ArcadeManager manager)
{ {
super(manager, "Undead Zombie", KitAvailability.Gem, 5000, super(manager, "Undead Zombie", KitAvailability.Gem, 5000, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Regenerates rapidly"
},
new Perk[]
{
new PerkRegeneration(2)
},
EntityType.ZOMBIE,
new ItemStack(Material.STONE_AXE));
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.STONE_AXE)); player.getInventory().addItem(PLAYER_ITEMS);
DisguiseZombie disguise = new DisguiseZombie(player); DisguiseZombie disguise = new DisguiseZombie(player);
if (Manager.GetGame().GetTeam(player) != null) if (Manager.GetGame().GetTeam(player) != null)

View File

@ -1,88 +1,87 @@
package nautilus.game.arcade.game.games.champions.kits; package nautilus.game.arcade.game.games.champions.kits;
import java.util.HashMap; import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.ChampionsKit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.minecraft.game.classcombat.Class.ClientClass; import java.util.HashMap;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public class KitAssassin extends Kit public class KitAssassin extends ChampionsKit
{ {
private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>(); private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>();
private static final String[] DESCRIPTION = {
"Extremely agile warrior, trained in",
"the mystic arts of assassination.",
"",
"Attack Damage increased by 1",
"Fall Damage reduced by 1",
"Permanent Speed 2",
};
private static final Perk[] PERKS = {};
private static final ItemStack IN_HAND = new ItemStack(Material.IRON_SWORD);
public KitAssassin(ArcadeManager manager) public KitAssassin(ArcadeManager manager)
{ {
super(manager, "Assassin", KitAvailability.Free, super(manager, "Assassin", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Extremely agile warrior, trained in",
"the mystic arts of assassination.",
"",
"Attack Damage increased by 1",
"Fall Damage reduced by 1",
"Permanent Speed 2",
},
new Perk[]
{
},
EntityType.ZOMBIE,
new ItemStack(Material.IRON_SWORD));
} }
@Override @Override
public void Deselected(Player player) public void Deselected(Player player)
{ {
_class.remove(player); _class.remove(player);
} }
@Override @Override
public void Selected(Player player) public void Selected(Player player)
{ {
Manager.Clear(player); Manager.Clear(player);
_class.put(player, Manager.getClassManager().Get(player)); _class.put(player, Manager.getClassManager().Get(player));
ClientClass clientClass = _class.get(player); ClientClass clientClass = _class.get(player);
IPvpClass pvpClass = Manager.getClassManager().GetClass("Assassin"); IPvpClass pvpClass = Manager.getClassManager().GetClass("Assassin");
clientClass.SetGameClass(pvpClass); clientClass.SetGameClass(pvpClass);
pvpClass.ApplyArmor(player); pvpClass.ApplyArmor(player);
clientClass.ClearDefaults(); clientClass.ClearDefaults();
clientClass.EquipCustomBuild(clientClass.GetCustomBuilds(pvpClass).get(0)); clientClass.EquipCustomBuild(clientClass.GetCustomBuilds(pvpClass).get(0));
if (!Manager.GetGame().InProgress()) if (!Manager.GetGame().InProgress())
{
clientClass.SetActiveCustomBuild(pvpClass, pvpClass.getDefaultBuild()); clientClass.SetActiveCustomBuild(pvpClass, pvpClass.getDefaultBuild());
}
Manager.openClassShop(player); Manager.openClassShop(player);
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
_class.get(player).ResetToDefaults(true, true); _class.get(player).ResetToDefaults(true, true);
} }
@Override @Override
public void SpawnCustom(LivingEntity ent) public void SpawnCustom(LivingEntity ent)
{ {
ent.getEquipment().setHelmet(new ItemStack(Material.LEATHER_HELMET)); ent.getEquipment().setHelmet(new ItemStack(Material.LEATHER_HELMET));
ent.getEquipment().setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE)); ent.getEquipment().setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE));
ent.getEquipment().setLeggings(new ItemStack(Material.LEATHER_LEGGINGS)); ent.getEquipment().setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
ent.getEquipment().setBoots(new ItemStack(Material.LEATHER_BOOTS)); ent.getEquipment().setBoots(new ItemStack(Material.LEATHER_BOOTS));
} }
@Override @Override
public void DisplayDesc(Player player) public void DisplayDesc(Player player)
{ {
} }

View File

@ -1,42 +1,38 @@
package nautilus.game.arcade.game.games.champions.kits; package nautilus.game.arcade.game.games.champions.kits;
import java.util.HashMap; import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.ChampionsKit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.minecraft.game.classcombat.Class.ClientClass; import java.util.HashMap;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public class KitBrute extends Kit public class KitBrute extends ChampionsKit
{ {
private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>(); private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>();
private static final String[] DESCRIPTION = {
"A giant of a man, able to smash and",
"destroy anything in his path.",
"",
"Takes additional damage to counter",
"the strength of Diamond Armor."
};
private static final Perk[] PERKS = {};
private static final ItemStack IN_HAND = new ItemStack(Material.IRON_SWORD);
public KitBrute(ArcadeManager manager) public KitBrute(ArcadeManager manager)
{ {
super(manager, "Brute", KitAvailability.Free, super(manager, "Brute", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"A giant of a man, able to smash and",
"destroy anything in his path.",
"",
"Takes additional damage to counter",
"the strength of Diamond Armor."
},
new Perk[]
{
},
EntityType.ZOMBIE,
new ItemStack(Material.IRON_SWORD));
} }
@Override @Override

View File

@ -1,89 +1,88 @@
package nautilus.game.arcade.game.games.champions.kits; package nautilus.game.arcade.game.games.champions.kits;
import java.util.HashMap; import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.ChampionsKit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.minecraft.game.classcombat.Class.ClientClass; import java.util.HashMap;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public class KitKnight extends Kit public class KitKnight extends ChampionsKit
{ {
private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>(); private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>();
private static final String[] DESCRIPTION = {
"Knight of the realm, extremely good at",
"defending and surviving.",
};
private static final Perk[] PERKS = {};
private static final ItemStack IN_HAND = new ItemStack(Material.IRON_SWORD);
public KitKnight(ArcadeManager manager) public KitKnight(ArcadeManager manager)
{ {
super(manager, "Knight", KitAvailability.Free, super(manager, "Knight", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Knight of the realm, extremely good at",
"defending and surviving.",
},
new Perk[]
{
},
EntityType.ZOMBIE,
new ItemStack(Material.IRON_SWORD));
} }
@Override @Override
public void Deselected(Player player) public void Deselected(Player player)
{ {
_class.remove(player); _class.remove(player);
} }
@Override @Override
public void Selected(Player player) public void Selected(Player player)
{ {
Manager.Clear(player); Manager.Clear(player);
AddPlayer(player); AddPlayer(player);
Manager.openClassShop(player); Manager.openClassShop(player);
} }
public void AddPlayer(Player player) public void AddPlayer(Player player)
{ {
_class.put(player, Manager.getClassManager().Get(player)); _class.put(player, Manager.getClassManager().Get(player));
ClientClass clientClass = _class.get(player); ClientClass clientClass = _class.get(player);
IPvpClass pvpClass = Manager.getClassManager().GetClass("Knight"); IPvpClass pvpClass = Manager.getClassManager().GetClass("Knight");
clientClass.SetGameClass(pvpClass); clientClass.SetGameClass(pvpClass);
pvpClass.ApplyArmor(player); pvpClass.ApplyArmor(player);
clientClass.ClearDefaults(); clientClass.ClearDefaults();
clientClass.EquipCustomBuild(clientClass.GetCustomBuilds(pvpClass).get(0)); clientClass.EquipCustomBuild(clientClass.GetCustomBuilds(pvpClass).get(0));
if (!Manager.GetGame().InProgress()) if (!Manager.GetGame().InProgress())
{
clientClass.SetActiveCustomBuild(pvpClass, pvpClass.getDefaultBuild()); clientClass.SetActiveCustomBuild(pvpClass, pvpClass.getDefaultBuild());
}
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
_class.get(player).ResetToDefaults(true, true); _class.get(player).ResetToDefaults(true, true);
} }
@Override @Override
public void SpawnCustom(LivingEntity ent) public void SpawnCustom(LivingEntity ent)
{ {
ent.getEquipment().setHelmet(new ItemStack(Material.IRON_HELMET)); ent.getEquipment().setHelmet(new ItemStack(Material.IRON_HELMET));
ent.getEquipment().setChestplate(new ItemStack(Material.IRON_CHESTPLATE)); ent.getEquipment().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
ent.getEquipment().setLeggings(new ItemStack(Material.IRON_LEGGINGS)); ent.getEquipment().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
ent.getEquipment().setBoots(new ItemStack(Material.IRON_BOOTS)); ent.getEquipment().setBoots(new ItemStack(Material.IRON_BOOTS));
} }
@Override @Override
public void DisplayDesc(Player player) public void DisplayDesc(Player player)
{ {
} }

View File

@ -1,39 +1,35 @@
package nautilus.game.arcade.game.games.champions.kits; package nautilus.game.arcade.game.games.champions.kits;
import java.util.HashMap; import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.ChampionsKit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.minecraft.game.classcombat.Class.ClientClass; import java.util.HashMap;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public class KitMage extends Kit public class KitMage extends ChampionsKit
{ {
private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>(); private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>();
private static final String[] DESCRIPTION = {
"Trained in the ways of magic, the mage",
"can unleash hell upon his opponents.",
};
private static final Perk[] PERKS = {};
private static final ItemStack IN_HAND = new ItemStack(Material.IRON_SWORD);
public KitMage(ArcadeManager manager) public KitMage(ArcadeManager manager)
{ {
super(manager, "Mage", KitAvailability.Free, super(manager, "Mage", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Trained in the ways of magic, the mage",
"can unleash hell upon his opponents.",
},
new Perk[]
{
},
EntityType.ZOMBIE,
new ItemStack(Material.IRON_SWORD));
} }
@Override @Override

View File

@ -1,52 +1,48 @@
package nautilus.game.arcade.game.games.champions.kits; package nautilus.game.arcade.game.games.champions.kits;
import java.util.HashMap; import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.ChampionsKit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.minecraft.game.classcombat.Class.ClientClass; import java.util.HashMap;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public class KitRanger extends Kit public class KitRanger extends ChampionsKit
{ {
private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>(); private HashMap<Player, ClientClass> _class = new HashMap<Player, ClientClass>();
private static final String[] DESCRIPTION = {
"Uses mastery of archery and kinship with",
"nature to defeat opponents."
};
private static final Perk[] PERKS = {};
private static final ItemStack IN_HAND = new ItemStack(Material.IRON_SWORD);
public KitRanger(ArcadeManager manager) public KitRanger(ArcadeManager manager)
{ {
super(manager, "Ranger", KitAvailability.Free, super(manager, "Ranger", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND);
new String[]
{
"Uses mastery of archery and kinship with",
"nature to defeat opponents."
},
new Perk[]
{
},
EntityType.ZOMBIE,
new ItemStack(Material.IRON_SWORD));
} }
@Override @Override
public void Deselected(Player player) public void Deselected(Player player)
{ {
_class.remove(player); _class.remove(player);
} }
@Override @Override
public void Selected(Player player) public void Selected(Player player)
{ {
Manager.Clear(player); Manager.Clear(player);
_class.put(player, Manager.getClassManager().Get(player)); _class.put(player, Manager.getClassManager().Get(player));
ClientClass clientClass = _class.get(player); ClientClass clientClass = _class.get(player);
IPvpClass pvpClass = Manager.getClassManager().GetClass("Ranger"); IPvpClass pvpClass = Manager.getClassManager().GetClass("Ranger");
@ -55,30 +51,32 @@ public class KitRanger extends Kit
pvpClass.ApplyArmor(player); pvpClass.ApplyArmor(player);
clientClass.ClearDefaults(); clientClass.ClearDefaults();
clientClass.EquipCustomBuild(clientClass.GetCustomBuilds(pvpClass).get(0)); clientClass.EquipCustomBuild(clientClass.GetCustomBuilds(pvpClass).get(0));
if (!Manager.GetGame().InProgress()) if (!Manager.GetGame().InProgress())
{
clientClass.SetActiveCustomBuild(pvpClass, pvpClass.getDefaultBuild()); clientClass.SetActiveCustomBuild(pvpClass, pvpClass.getDefaultBuild());
}
Manager.openClassShop(player); Manager.openClassShop(player);
} }
@Override @Override
public void GiveItems(Player player) public void GiveItems(Player player)
{ {
_class.get(player).ResetToDefaults(true, true); _class.get(player).ResetToDefaults(true, true);
} }
@Override @Override
public void SpawnCustom(LivingEntity ent) public void SpawnCustom(LivingEntity ent)
{ {
ent.getEquipment().setHelmet(new ItemStack(Material.CHAINMAIL_HELMET)); ent.getEquipment().setHelmet(new ItemStack(Material.CHAINMAIL_HELMET));
ent.getEquipment().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE)); ent.getEquipment().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));
ent.getEquipment().setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS)); ent.getEquipment().setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));
ent.getEquipment().setBoots(new ItemStack(Material.CHAINMAIL_BOOTS)); ent.getEquipment().setBoots(new ItemStack(Material.CHAINMAIL_BOOTS));
} }
@Override @Override
public void DisplayDesc(Player player) public void DisplayDesc(Player player)
{ {
} }

View File

@ -1,22 +1,17 @@
package nautilus.game.arcade.game.games.deathtag.kits; package nautilus.game.arcade.game.games.deathtag.kits;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import nautilus.game.arcade.ArcadeManager; public abstract class AbstractKitChaser extends ProgressingKit
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public abstract class AbstractKitChaser extends Kit
{ {
public AbstractKitChaser(ArcadeManager manager, String name, KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand) public AbstractKitChaser(ArcadeManager manager, String name, KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{ {
super(manager, name, kitAvailability, kitDesc, kitPerks, entityType, itemInHand); super(manager, name, name.toLowerCase().replace(" ", ""), kitAvailability, kitDesc, kitPerks, entityType, itemInHand);
} }
public AbstractKitChaser(ArcadeManager manager, String name, KitAvailability kitAvailability, int cost, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{
super(manager, name, kitAvailability, cost, kitDesc, kitPerks, entityType, itemInHand);
}
} }

View File

@ -1,22 +1,21 @@
package nautilus.game.arcade.game.games.deathtag.kits; package nautilus.game.arcade.game.games.deathtag.kits;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import nautilus.game.arcade.ArcadeManager; public abstract class AbstractKitRunner extends ProgressingKit
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public abstract class AbstractKitRunner extends Kit
{ {
public AbstractKitRunner(ArcadeManager manager, String name, KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand) public AbstractKitRunner(ArcadeManager manager, String name, KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{ {
super(manager, name, kitAvailability, kitDesc, kitPerks, entityType, itemInHand); super(manager, name, name.toLowerCase().replace(" ", ""), kitAvailability, kitDesc, kitPerks, entityType, itemInHand);
} }
public AbstractKitRunner(ArcadeManager manager, String name, KitAvailability kitAvailability, int cost, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand) public AbstractKitRunner(ArcadeManager manager, String name, KitAvailability kitAvailability, int cost, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{ {
super(manager, name, kitAvailability, cost, kitDesc, kitPerks, entityType, itemInHand); super(manager, name, name.toLowerCase().replace(" ", ""), kitAvailability, cost, kitDesc, kitPerks, entityType, itemInHand);
} }
} }

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