Merge branch 'update/clans' into develop

This commit is contained in:
cnr 2016-07-27 20:40:35 -05:00
commit dd38a1dd76
177 changed files with 11577 additions and 1658 deletions

View File

@ -16,9 +16,11 @@ public class Mineplexer extends Plugin
{
@Override
public void onEnable() {
getProxy().getScheduler().runAsync(this, new Runnable() {
getProxy().getScheduler().runAsync(this, new Runnable()
{
@Override
public void run() {
public void run()
{
// Sentry setup
Handler sentry = new SentryHandler(new DefaultRavenFactory().createRavenInstance(
new Dsn("https://470f12378af3453ba089e0c0a0c9aae6:292516b722594784807aebb06db8ec38@app.getsentry.com/66323"
@ -30,10 +32,9 @@ public class Mineplexer extends Plugin
new MotdManager(this);
new LobbyBalancer(this);
PlayerCount playerCount = new PlayerCount(this);
new PlayerCount(this);
new FileUpdater(this);
new PlayerStats(this);
//new InternetStatus(this);
new PlayerTracker(this);
}
}

View File

@ -2,7 +2,6 @@ package mineplex.bungee.lobbyBalancer;
import java.io.File;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -12,21 +11,24 @@ import mineplex.serverdata.Region;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ServerRepository;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
import com.google.common.collect.Lists;
public class LobbyBalancer implements Listener, Runnable
{
private Plugin _plugin;
private ServerRepository _repository;
private List<MinecraftServer> _sortedLobbies = new ArrayList<MinecraftServer>();
private List<MinecraftServer> _sortedLobbies = Lists.newArrayList();
private List<MinecraftServer> _sortedClans = Lists.newArrayList();
private static Object _serverLock = new Object();
private int _lobbyIndex = 0;
private int _clansIndex = 0;
public LobbyBalancer(Plugin plugin)
{
@ -35,7 +37,7 @@ public class LobbyBalancer implements Listener, Runnable
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
_repository = ServerManager.getServerRepository(region);
loadLobbyServers();
run();
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
_plugin.getProxy().getScheduler().schedule(_plugin, this, 500L, 500L, TimeUnit.MILLISECONDS);
@ -44,27 +46,49 @@ public class LobbyBalancer implements Listener, Runnable
@EventHandler
public void playerConnect(ServerConnectEvent event)
{
if (!event.getTarget().getName().equalsIgnoreCase("Lobby"))
return;
synchronized (_serverLock)
if (event.getTarget().getName().equalsIgnoreCase("Lobby"))
{
if (_lobbyIndex >= _sortedLobbies.size() || _sortedLobbies.get(_lobbyIndex).getPlayerCount() >= _sortedLobbies.get(_lobbyIndex).getMaxPlayerCount())
_lobbyIndex = 0;
event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_lobbyIndex).getName()));
_sortedLobbies.get(_lobbyIndex).incrementPlayerCount(1);
System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(_lobbyIndex).getName() + "(" + _sortedLobbies.get(_lobbyIndex).getPublicAddress() + ")");
_lobbyIndex++;
synchronized (_serverLock)
{
if (_lobbyIndex >= _sortedLobbies.size() || _sortedLobbies.get(_lobbyIndex).getPlayerCount() >= _sortedLobbies.get(_lobbyIndex).getMaxPlayerCount())
_lobbyIndex = 0;
event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_lobbyIndex).getName()));
_sortedLobbies.get(_lobbyIndex).incrementPlayerCount(1);
System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(_lobbyIndex).getName() + "(" + _sortedLobbies.get(_lobbyIndex).getPublicAddress() + ")");
_lobbyIndex++;
}
}
if (event.getTarget().getName().equalsIgnoreCase("ClansHub"))
{
synchronized (_serverLock)
{
if (_clansIndex >= _sortedClans.size() || _sortedClans.get(_clansIndex).getPlayerCount() >= _sortedClans.get(_clansIndex).getMaxPlayerCount())
_clansIndex = 0;
event.setTarget(_plugin.getProxy().getServerInfo(_sortedClans.get(_clansIndex).getName()));
_sortedClans.get(_clansIndex).incrementPlayerCount(1);
System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedClans.get(_clansIndex).getName() + "(" + _sortedClans.get(_clansIndex).getPublicAddress() + ")");
_clansIndex++;
}
}
}
public void run()
{
loadLobbyServers();
loadServers();
if (!_plugin.getProxy().getServers().containsKey("ClansHub"))
{
_plugin.getProxy().getServers().put("ClansHub", _plugin.getProxy().constructServerInfo("ClansHub", new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false));
}
if (!_plugin.getProxy().getServers().containsKey("Lobby"))
{
_plugin.getProxy().getServers().put("Lobby", _plugin.getProxy().constructServerInfo("Lobby", new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false));
}
}
public void loadLobbyServers()
public void loadServers()
{
Collection<MinecraftServer> servers = _repository.getServerStatuses();
@ -72,6 +96,7 @@ public class LobbyBalancer implements Listener, Runnable
{
long startTime = System.currentTimeMillis();
_sortedLobbies.clear();
_sortedClans.clear();
for (MinecraftServer server : servers)
{
@ -88,9 +113,17 @@ public class LobbyBalancer implements Listener, Runnable
_sortedLobbies.add(server);
}
}
if (server.getName().toUpperCase().startsWith("CLANSHUB"))
{
if (server.getMotd() == null || !server.getMotd().contains("Restarting"))
{
_sortedClans.add(server);
}
}
}
Collections.sort(_sortedLobbies, new LobbySorter());
Collections.sort(_sortedClans, new LobbySorter());
long timeSpentInLock = System.currentTimeMillis() - startTime;

View File

@ -1,20 +1,18 @@
package mineplex.bungee.motd;
import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.BungeeServer;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ConnectionData.ConnectionType;
import net.md_5.bungee.api.ChatColor;
import mineplex.serverdata.servers.ServerManager;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
@ -31,6 +29,8 @@ public class MotdManager implements Listener, Runnable
private Random _random = new Random();
private String _firstLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r";
private List<String> _motdLines;
private String _firstCLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r";
private List<String> _motdCLines;
public MotdManager(Plugin plugin)
{
@ -70,25 +70,50 @@ public class MotdManager implements Listener, Runnable
public void serverPing(ProxyPingEvent event)
{
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
String motd = _firstLine;
if (_motdLines != null && _motdLines.size() > 0)
if (event.getConnection().getListener() != null && event.getConnection().getListener().getDefaultServer().equalsIgnoreCase("ClansHub"))
{
motd += "\n" + _motdLines.get(_random.nextInt(_motdLines.size()));
String motd = _firstCLine;
if (_motdCLines != null && _motdCLines.size() > 0)
{
motd += "\n" + _motdCLines.get(_random.nextInt(_motdCLines.size()));
}
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
}
else
{
String motd = _firstLine;
if (_motdLines != null && _motdLines.size() > 0)
{
motd += "\n" + _motdLines.get(_random.nextInt(_motdLines.size()));
}
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
}
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
}
@Override
public void run()
{
GlobalMotd motd = _repository.getElement("MainMotd");
if (motd != null)
{
_motdLines = motd.getMotd();
_firstLine = motd.getHeadline();
{
GlobalMotd motd = _repository.getElement("MainMotd");
if (motd != null)
{
_motdLines = motd.getMotd();
_firstLine = motd.getHeadline();
}
}
{
GlobalMotd motd = _repository.getElement("ClansMotd");
if (motd != null)
{
_motdCLines = motd.getMotd();
_firstCLine = motd.getHeadline();
}
else
{
_repository.addElement(new GlobalMotd("ClansMotd", "§4§lMineplex Clans§r", Arrays.asList("Default MOTD")));
}
}
}

View File

@ -1,7 +1,6 @@
package mineplex.bungee.playerCount;
import java.io.File;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import mineplex.bungee.status.InternetStatus;
@ -12,7 +11,6 @@ import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ConnectionData.ConnectionType;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ServerRepository;
import net.md_5.bungee.api.ServerPing.Players;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.event.ProxyPingEvent;
@ -39,7 +37,13 @@ public class PlayerCount implements Listener, Runnable
_plugin.getProxy().getScheduler().schedule(_plugin, this, 4L, 4L, TimeUnit.SECONDS);
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
_listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
for (ListenerInfo info : _plugin.getProxy().getConfigurationAdapter().getListeners())
{
if (info.getDefaultServer().equalsIgnoreCase("Lobby"))
{
_listenerInfo = info;
}
}
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL),
Region.ALL, BungeeServer.class, "bungeeServers");
@ -55,7 +59,10 @@ public class PlayerCount implements Listener, Runnable
public void run()
{
BungeeServer snapshot = generateSnapshot();
_repository.addElement(snapshot, 15); // Update with a 15 second expiry on session
if (snapshot != null)
{
_repository.addElement(snapshot, 15); // Update with a 15 second expiry on session
}
_totalPlayers = fetchPlayerCount();
}
@ -84,6 +91,10 @@ public class PlayerCount implements Listener, Runnable
*/
private BungeeServer generateSnapshot()
{
if (_listenerInfo == null)
{
return null;
}
String name = _listenerInfo.getHost().getAddress().getHostAddress();
String host = _listenerInfo.getHost().getAddress().getHostAddress();
int port = _listenerInfo.getHost().getPort();

View File

@ -190,13 +190,29 @@ public class Schematic
return index < _blocks.length;
}
public short getBlock(int x, int y, int z)
public Short getBlock(int x, int y, int z)
{
if (getIndex(x, y, z) >= _blocks.length)
{
return null;
}
if (getIndex(x, y, z) < 0)
{
return null;
}
return _blocks[getIndex(x, y, z)];
}
public byte getData(int x, int y, int z)
public Byte getData(int x, int y, int z)
{
if (getIndex(x, y, z) >= _blocks.length)
{
return null;
}
if (getIndex(x, y, z) < 0)
{
return null;
}
return _blockData[getIndex(x, y, z)];
}

View File

@ -99,10 +99,13 @@ public class SchematicRunnable implements Runnable
private void setBlock(Block block, int x, int y, int z)
{
int materialId = _schematic.getBlock(x, y, z);
byte data = _schematic.getData(x, y, z);
Short materialId = _schematic.getBlock(x, y, z);
Byte data = _schematic.getData(x, y, z);
if (materialId == null || data == null)
{
return;
}
Material material = Material.getMaterial(materialId);
if (material == null)
{

View File

@ -0,0 +1,60 @@
package mineplex.core.common.events;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.util.Vector;
/**
* Called just before UtilAction#velocity changes an entity's velocity.
*/
public class EntityVelocityChangeEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Entity _ent;
private Vector _vel;
private boolean _cancelled;
public EntityVelocityChangeEvent(Entity entity, Vector velocity)
{
_ent = entity;
_vel = velocity;
}
public Entity getEntity()
{
return _ent;
}
public boolean isCancelled()
{
return _cancelled;
}
public Vector getVelocity()
{
return _vel;
}
public void setVelocity(Vector velocity)
{
_vel = velocity;
}
public void setCancelled(boolean cancelled)
{
_cancelled = cancelled;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -1,5 +1,8 @@
package mineplex.core.common.util;
import mineplex.core.common.events.EntityVelocityChangeEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@ -49,6 +52,15 @@ public class UtilAction
if (groundBoost)
if (UtilEnt.isGrounded(ent))
vec.setY(vec.getY() + 0.2);
EntityVelocityChangeEvent event = new EntityVelocityChangeEvent(ent, vec);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
{
return;
}
vec = event.getVelocity();
//Velocity
ent.setFallDistance(0);
@ -65,6 +77,16 @@ public class UtilAction
public static void zeroVelocity(Entity ent)
{
Vector vec = new Vector(0,0,0);
EntityVelocityChangeEvent event = new EntityVelocityChangeEvent(ent, vec);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
{
return;
}
vec = event.getVelocity();
ent.setFallDistance(0);
//Store It!

View File

@ -160,7 +160,13 @@ public class BlockRestore extends MiniPlugin
public void add(Block block, int toID, byte toData, int fromID, byte fromData, long expireTime, boolean restoreOnBreak)
{
if (!contains(block)) getBlocks().put(block, new BlockRestoreData(block, toID, toData, fromID, fromData, expireTime, 0, restoreOnBreak));
else getData(block).update(toID, toData, expireTime);
else
{
if (getData(block) != null)
{
getData(block).update(toID, toData, expireTime);
}
}
}
public void snow(Block block, byte heightAdd, byte heightMax, long expireTime, long meltDelay, int heightJumps)
@ -168,7 +174,8 @@ public class BlockRestore extends MiniPlugin
//Fill Above
if (((block.getTypeId() == 78 && block.getData() >= (byte)7) || block.getTypeId() == 80) && getData(block) != null)
{
getData(block).update(78, heightAdd, expireTime, meltDelay);
if (getData(block) != null)
getData(block).update(78, heightAdd, expireTime, meltDelay);
if (heightJumps > 0) snow(block.getRelative(BlockFace.UP), heightAdd, heightMax, expireTime, meltDelay, heightJumps - 1);
if (heightJumps == -1) snow(block.getRelative(BlockFace.UP), heightAdd, heightMax, expireTime, meltDelay, -1);
@ -213,8 +220,11 @@ public class BlockRestore extends MiniPlugin
//Snow
if (!contains(block))
getBlocks().put(block, new BlockRestoreData(block, 78, (byte) Math.max(0, heightAdd - 1), block.getTypeId(), block.getData(), expireTime, meltDelay, false));
else
getData(block).update(78, heightAdd, expireTime, meltDelay);
else
{
if (getData(block) != null)
getData(block).update(78, heightAdd, expireTime, meltDelay);
}
}
public boolean contains(Block block)

View File

@ -6,6 +6,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
public class BlockRestoreData
{
@ -23,6 +24,8 @@ public class BlockRestoreData
protected long _meltDelay = 0;
protected long _meltLast = 0;
protected BlockState _fromState;
protected HashMap<Location, Byte> _pad = new HashMap<Location, Byte>();
protected boolean _restoreOnBreak;
@ -30,6 +33,7 @@ public class BlockRestoreData
public BlockRestoreData(Block block, int toID, byte toData, int fromID, byte fromData, long expireDelay, long meltDelay, boolean restoreOnBreak)
{
_block = block;
_fromState = block.getState();
_fromID = fromID;
_fromData = fromData;
@ -163,6 +167,8 @@ public class BlockRestoreData
public void restore()
{
_block.setTypeIdAndData(_fromID, _fromData, true);
_fromState.update();
handleLilypad(true);
}

View File

@ -41,9 +41,14 @@ public class BlockRestoreMap
public void addBlockData(BlockData blockData)
{
Block block = blockData.Block;
if (!_blocks[block.getY()].containsKey(block))
_blocks[block.getY()].put(block, blockData);
if (block.getY() > 0 && block.getY() < _blocks.length)
{
if (!_blocks[block.getY()].containsKey(block))
{
_blocks[block.getY()].put(block, blockData);
}
}
_changedBlocks.add(blockData.Block);
}

View File

@ -40,6 +40,8 @@ import java.util.Map.Entry;
public class DisguiseManager extends MiniPlugin implements IPacketHandler
{
public static DisguiseManager INSTANCE;
private NautHashMap<Integer, DisguiseBase> _spawnPacketMap = new NautHashMap<Integer, DisguiseBase>();
private NautHashMap<Integer, PacketPlayOutEntityVelocity> _movePacketMap = new NautHashMap<Integer, PacketPlayOutEntityVelocity>();
private NautHashMap<Integer, PacketPlayOutEntityVelocity> _moveTempMap = new NautHashMap<Integer, PacketPlayOutEntityVelocity>();
@ -71,6 +73,8 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
PacketPlayOutEntityTeleport.class, PacketPlayOutEntityMetadata.class, PacketPlayOutSpawnEntityLiving.class,
PacketPlayOutUpdateAttributes.class, PacketPlayOutEntityEquipment.class, PacketPlayOutNamedSoundEffect.class);
INSTANCE = this;
try
{
_bedChunk = new Chunk(((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(), 0, 0);

View File

@ -215,12 +215,7 @@ public class MessageManager extends MiniClientPlugin<ClientMessage>
Get(from).LastToTime = System.currentTimeMillis();
// Chiss or defek7
if (to.getName().equals("Chiss") || to.getName().equals("defek7") || to.getName().equals("Phinary") || to.getName().equals("AlexTheCoder"))
{
UtilPlayer.message(from, C.cPurple + to.getName() + " is often AFK or minimized, due to plugin development.");
UtilPlayer.message(from, C.cPurple + "Please be patient if he does not reply instantly.");
}
if (to.getName().equals("xXVevzZXx"))
if (GetClientManager().Get(to).GetRank() == Rank.DEVELOPER)
{
UtilPlayer.message(from, C.cPurple + to.getName() + " is often AFK or minimized, due to plugin development.");
UtilPlayer.message(from, C.cPurple + "Please be patient if she does not reply instantly.");

View File

@ -95,15 +95,21 @@ public class Portal extends MiniPlugin
ServerTransferEvent event = new ServerTransferEvent(player, serverName, draggedByParty);
Bukkit.getPluginManager().callEvent(event);
final boolean override = serverName.equalsIgnoreCase("Lobby");
final boolean override = serverName.equalsIgnoreCase("Lobby") || serverName.equalsIgnoreCase("ClansHub");
final Rank playerRank = _clientManager.Get(player).GetRank();
if(event.getParty() != null && override)
if (event.getParty() != null && override)
{
Party party = event.getParty();
sendParty(party);
return;
}
if (event.getParty() != null && serverName.toUpperCase().startsWith("CLANS-"))
{
event.getParty().sendMessage(F.main(getName(), "You cannot join Clans while in a party!"));
return;
}
if (override)
{
@ -111,7 +117,7 @@ public class Portal extends MiniPlugin
return;
}
if(event.isCancel())
if (event.isCancel())
{
return;
}
@ -139,23 +145,23 @@ public class Portal extends MiniPlugin
MinecraftServer best = null;
List<MinecraftServer> serverList = Lists.newArrayList(repository.getServersByGroup("Lobby"));
int lowest = Integer.MAX_VALUE;
for(MinecraftServer server : serverList)
for (MinecraftServer server : serverList)
{
int playercount = server.getPlayerCount();
if(playercount < 20)
if (playercount < 20)
{
continue;
}
if(playercount < lowest)
if (playercount < lowest)
{
lowest = playercount;
if(best == null)
if (best == null)
{
best = server;
}
}
}
if(best == null)
if (best == null)
{
//Well, fuck.
best = serverList.get(new Random().nextInt(serverList.size()));

View File

@ -4,11 +4,13 @@ import java.util.ArrayList;
import java.util.List;
import mineplex.core.gadget.GadgetManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
@ -121,13 +123,21 @@ public class TreasureManager extends MiniPlugin
for (TreasureLocation treasureLocation : _treasureLocations)
{
treasureLocation.cleanup();
HandlerList.unregisterAll(treasureLocation);
}
_treasureLocations.clear();
}
public void addOpenStat(Player player, TreasureType treasureType)
{
_statsManager.incrementStat(player, "Global.Treasure." + treasureType.getStatName(), 1);
}
public void addTreasureLocation(TreasureLocation loc)
{
_treasureLocations.add(loc);
_plugin.getServer().getPluginManager().registerEvents(loc, _plugin);
}
public Reward[] getRewards(Player player, RewardPool.Type pool, RewardType rewardType)
{

View File

@ -119,23 +119,26 @@ public class Enjin extends MiniPlugin implements CommandExecutor
final UUID playerUUID = uuid;
_cachedUUIDs.put(name, new AbstractMap.SimpleEntry<UUID, Long>(playerUUID, System.currentTimeMillis() + 240000));
if (!checkForBoosterPurchase(args, name, playerUUID, client))
if (!checkForClansPurchase(args, name, client))
{
if (!checkForCoinPurchase(args, name, playerUUID, client))
if (!checkForBoosterPurchase(args, name, playerUUID, client))
{
if (!checkForRankPurchase(args, name, playerUUID, client))
if (!checkForCoinPurchase(args, name, playerUUID, client))
{
if (!checkForPurchase(args, name, client))
if (!checkForRankPurchase(args, name, playerUUID, client))
{
StringBuilder sb = new StringBuilder();
for (String arg : args)
if (!checkForPurchase(args, name, client))
{
sb.append(arg + " ");
}
StringBuilder sb = new StringBuilder();
System.out.println("Received Command : " + sb.toString());
for (String arg : args)
{
sb.append(arg + " ");
}
System.out.println("Received Command : " + sb.toString());
}
}
}
}
@ -292,4 +295,71 @@ public class Enjin extends MiniPlugin implements CommandExecutor
return true;
}
protected boolean checkForClansPurchase(String[] args, final String name, final CoreClient client)
{
if (args.length >= 3 && args[0].equalsIgnoreCase("clansBanner"))
{
String purchase = "Clan Banner Usage";
if (args[2].equalsIgnoreCase("true"))
{
purchase = "Clan Banner Editor";
}
final String packageName = purchase;
_donationManager.PurchaseUnknownSalesPackage(new Callback<TransactionResponse>()
{
public void run(TransactionResponse data)
{
if (data == TransactionResponse.Success)
{
_inventoryManager.addItemToInventoryForOffline(new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), packageName, 1, true);
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received their " + packageName + " access.");
}
else
{
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + packageName + ". Queuing for run later.");
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), packageName, 1, false);
}
}
}, client.getAccountId(), packageName, 1);
}
else
{
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " 1" + ". Queuing for run later.");
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), packageName, 1, data == TransactionResponse.Success);
}
}
}, name, client.getAccountId(), packageName, GlobalCurrency.GEM, 0, false);
//enjin_mineplex clansBanner AlexTheCoder true
return true;
}
if (args.length >= 4 && args[0].equalsIgnoreCase("clansAmplifier"))
{
//enjin_mineplex clansAmplifier AlexTheCoder 20 1
final String item = "Rune Amplifier " + args[2];
final int amount = Integer.parseInt(args[3]);
_inventoryManager.addItemToInventoryForOffline(new Callback<Boolean>()
{
public void run (Boolean response)
{
if (response)
System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " rune amplifiers.");
else
System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " rune amplifiers. Queuing for run later.");
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), item, amount, response);
}
}, client.getAccountId(), item, amount);
}
return false;
}
}

View File

@ -1,3 +1,3 @@
name: Clans
main: mineplex.game.clans.Clans
version: 0.1
version: 1.0

View File

@ -58,7 +58,7 @@ import net.minecraft.server.v1_8_R3.MinecraftServer;
public class Clans extends JavaPlugin
{
public static final String VERSION = "Beta 1.0";
public static final String MAP = "Map 1";
private String WEB_CONFIG = "webServer";
// Modules
@ -132,7 +132,7 @@ public class Clans extends JavaPlugin
new MemoryFix(this);
new FoodDupeFix(this);
new Explosion(this, blockRestore);
new InventoryManager(this, _clientManager);
InventoryManager inventory = new InventoryManager(this, _clientManager);
ResourcePackManager resourcePackManager = new ResourcePackManager(this, portal);
resourcePackManager.setResourcePack(new Pair[]
{
@ -149,7 +149,7 @@ public class Clans extends JavaPlugin
GearManager customGear = new GearManager(this, packetHandler, _clientManager, _donationManager);
HologramManager hologram = new HologramManager(this, packetHandler);
_clansManager = new ClansManager(this, clansBans, serverStatusManager.getCurrentServerName(), incognito, packetHandler, punish, _clientManager, _donationManager, preferenceManager, blockRestore, statsManager, teleport, chat, customGear, hologram, webServerAddress);
_clansManager = new ClansManager(this, clansBans, serverStatusManager.getCurrentServerName(), incognito, packetHandler, punish, _clientManager, _donationManager, preferenceManager, blockRestore, statsManager, teleport, chat, customGear, hologram, inventory, webServerAddress);
new Recipes(this);
new Farming(this);
new BuildingShop(_clansManager, _clientManager, _donationManager);
@ -196,8 +196,8 @@ public class Clans extends JavaPlugin
getServer().getPluginManager().callEvent(new ServerShutdownEvent(this));
}
public static String version()
public static String getMap()
{
return VERSION;
return MAP;
}
}

View File

@ -363,9 +363,6 @@ public class ClanInfo
}
stringList.add(F.value("Members", members));
// Protected
stringList.add(F.value("TNT Protection", getProtected()));
return stringList;
}
@ -506,25 +503,6 @@ public class ClanInfo
return isOnlineNow();
}
public String getProtected()
{
for (ClansPlayer cur : getMembers().values())
if (cur.isOnline())
return C.cRed + "No - Clan Members are Online";
if (UtilTime.elapsed(_lastOnline.getTime(), Clans.getOnlineTime()))
return C.cGreen + "Yes - Clan Members are Offline";
return C.cGold
+ "No, "
+ UtilTime.convertString(Clans.getOnlineTime() - (System.currentTimeMillis() - _lastOnline.getTime()), 1,
TimeUnit.FIT) + " to Protection";
}
public boolean isProtected() {
return getProtected().startsWith(C.cGreen + "Yes");
}
public TntGenerator getGenerator()
{
return _generator;

View File

@ -226,8 +226,8 @@ public class ClanTips extends MiniPlugin
}),
ENTER_NETHER(
new String[] {
C.cDAqua + "The Nether",
C.cAqua + "Welcome to the Nether. This is a very scary place full of fire and is a place for people to battle to the death! TODO: Write something better about the nether here"
C.cDRedB + "The Nether",
C.cRed + "The Nether is a dangerous place full of powerful mobs and hazardous terrain! However, the mobs here drop powerful Ancient Runes, which can be used to strengthen your gear, making your clan even more fearsome than before!"
}),
;
@ -242,7 +242,7 @@ public class ClanTips extends MiniPlugin
TipType(String[] messages, boolean ignorePreferences)
{
_messages = new LinkedList();
_messages = new LinkedList<>();
for (String message : messages)
{

View File

@ -1,12 +1,7 @@
package mineplex.game.clans.clans;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
@ -17,7 +12,9 @@ import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.core.repository.tokens.ClanToken;
import mineplex.game.clans.core.war.ClanWarData;
import mineplex.serverdata.database.ResultSetCallable;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ClansAdmin
{
@ -341,19 +338,80 @@ public class ClansAdmin
{
ClanWarData war = clan.getWarData(clanAgainst);
// war.set
//
// Clans.getClanDataAccess().updateWar(clan, clanAgainst, war, success -> {
// UtilPlayer.message(caller, F.main("Clans Admin", "Updated war points against " + F.elem(war.getClanB())));
// });
if (war != null)
{
war.set(clan.getName(), war.getClanAPoints() - value);
Clans.getClanDataAccess().updateWar(clan, clanAgainst, war, success ->
{
UtilPlayer.message(caller, F.main("Clans Admin", "Updated war points against " + F.elem(war.getClanB())));
Clans.messageClan(clan, F.main("Clans", "Your war points with " + F.elem(clanAgainst.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
Clans.messageClan(clanAgainst, F.main("Clans", "Your war points with " + F.elem(clan.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
});
}
else
{
UtilPlayer.message(caller, F.main("Clans Admin", "There is no war between those two clans!"));
return;
}
}
else if (operation.equalsIgnoreCase("set"))
{
ClanWarData war = clan.getWarData(clanAgainst);
if (war != null)
{
war.set(clanAgainst.getName(), value);
Clans.getClanDataAccess().updateWar(clan, clanAgainst, war, success ->
{
UtilPlayer.message(caller, F.main("Clans Admin", "Updated war points against " + F.elem(war.getClanB())));
Clans.messageClan(clan, F.main("Clans", "Your war points with " + F.elem(clanAgainst.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
Clans.messageClan(clanAgainst, F.main("Clans", "Your war points with " + F.elem(clan.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
});
}
else
{
Clans.getClanDataAccess().war(clan, clanAgainst, value, new Callback<ClanWarData>()
{
@Override
public void run(ClanWarData data)
{
UtilPlayer.message(caller, F.main("Clans Admin", "Updated war points against " + F.elem(data.getClanB())));
Clans.messageClan(clan, F.main("Clans", "Your war points with " + F.elem(clanAgainst.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
Clans.messageClan(clanAgainst, F.main("Clans", "Your war points with " + F.elem(clan.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
}
});
}
}
else if (operation.equalsIgnoreCase("add"))
{
ClanWarData war = clan.getWarData(clanAgainst);
if (war != null)
{
war.set(clanAgainst.getName(), war.getClanAPoints() + value);
Clans.getClanDataAccess().updateWar(clan, clanAgainst, war, success ->
{
UtilPlayer.message(caller, F.main("Clans Admin", "Updated war points against " + F.elem(war.getClanB())));
Clans.messageClan(clan, F.main("Clans", "Your war points with " + F.elem(clanAgainst.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
Clans.messageClan(clanAgainst, F.main("Clans", "Your war points with " + F.elem(clan.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
});
}
else
{
Clans.getClanDataAccess().war(clan, clanAgainst, value, new Callback<ClanWarData>()
{
@Override
public void run(ClanWarData data)
{
UtilPlayer.message(caller, F.main("Clans Admin", "Updated war points against " + F.elem(data.getClanB())));
Clans.messageClan(clan, F.main("Clans", "Your war points with " + F.elem(clanAgainst.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
Clans.messageClan(clanAgainst, F.main("Clans", "Your war points with " + F.elem(clan.getName()) + " have been edited by " + F.elem(caller.getName()) + "!"));
}
});
}
}
else
{

View File

@ -1,27 +0,0 @@
package mineplex.game.clans.clans;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.task.TaskManager;
import mineplex.game.clans.Clans;
public class ClansBetaManager extends MiniPlugin
{
public ClansBetaManager(ClansManager manager, TaskManager taskManager)
{
super("Clans Beta", manager.getPlugin());
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(final PlayerJoinEvent event)
{
UtilPlayer.message(event.getPlayer(), C.cDAquaB + "Welcome to Mineplex Clans " + Clans.VERSION);
}
}

View File

@ -1,36 +1,6 @@
package mineplex.game.clans.clans;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.blockrestore.BlockRestoreData;
@ -52,6 +22,35 @@ import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
public class ClansGame extends MiniPlugin
{
private ClansManager _clans;
@ -78,6 +77,11 @@ public class ClansGame extends MiniPlugin
}
}
@EventHandler
public void onEnchant(EnchantItemEvent event)
{
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOW)
public void BlockBurn(BlockBurnEvent event)
@ -230,12 +234,6 @@ public class ClansGame extends MiniPlugin
return;
}
if (_clans.getWarManager().allowFromInvade(event.getBlock().getLocation(), event.getPlayer()))
{
// Allow because of invasion
return;
}
// Disallow
event.setCancelled(true);
@ -287,12 +285,6 @@ public class ClansGame extends MiniPlugin
Location loc = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation();
if (UtilBlock.usable(event.getClickedBlock())) loc = event.getClickedBlock().getLocation();
if (_clans.getWarManager().allowFromInvade(loc, event.getPlayer()))
{
// Allow because of invasion
return;
}
// Borderlands
if (player.getGameMode() != GameMode.CREATIVE && player.getItemInHand() != null && _clans.getClanBlocks().denyUsePlace(player.getItemInHand().getTypeId()) && _clans.getClanUtility().isBorderlands(event.getClickedBlock().getLocation()))
{
@ -564,17 +556,8 @@ public class ClansGame extends MiniPlugin
ClanInfo clan = _clans.getClanUtility().getOwner(event.getEntity().getLocation());
if (clan == null) return;
if (_clans.getWarManager().isBeingInvaded(clan))
{
// Allow because of invasion
return;
}
if (!clan.isProtected())
event.setCancelled(true);
else
clan.inform(C.cRed + "Your Territory is under attack!", null);
clan.inform(C.cRed + "Your Territory is under attack!", null);
}
@EventHandler

View File

@ -1,7 +1,14 @@
package mineplex.game.clans.clans;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
@ -10,7 +17,13 @@ import mineplex.core.chat.Chat;
import mineplex.core.common.Pair;
import mineplex.core.common.Rank;
import mineplex.core.common.events.PlayerMessageEvent;
import mineplex.core.common.util.*;
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.UtilTextMiddle;
import mineplex.core.creature.Creature;
import mineplex.core.creature.event.CreatureSpawnCustomEvent;
import mineplex.core.disguise.DisguiseManager;
@ -22,6 +35,7 @@ import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.incognito.events.IncognitoStatusChangeEvent;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.movement.Movement;
import mineplex.core.npc.NpcManager;
import mineplex.core.packethandler.PacketHandler;
@ -36,11 +50,19 @@ import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.Clans;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.amplifiers.AmplifierManager;
import mineplex.game.clans.clans.ban.ClansBanManager;
import mineplex.game.clans.clans.commands.*;
import mineplex.game.clans.clans.banners.BannerManager;
import mineplex.game.clans.clans.commands.ClanManagementCommand;
import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
import mineplex.game.clans.clans.commands.ClansChatCommand;
import mineplex.game.clans.clans.commands.ClansCommand;
import mineplex.game.clans.clans.commands.KillCommand;
import mineplex.game.clans.clans.commands.MapCommand;
import mineplex.game.clans.clans.commands.RegionsCommand;
import mineplex.game.clans.clans.commands.SpeedCommand;
import mineplex.game.clans.clans.data.PlayerClan;
import mineplex.game.clans.clans.event.ClansPlayerDeathEvent;
import mineplex.game.clans.clans.gui.ClanShop;
@ -82,8 +104,8 @@ import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import mineplex.minecraft.game.classcombat.Class.repository.token.CustomBuildToken;
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
import mineplex.minecraft.game.classcombat.Skill.Mage.events.FissureModifyBlockEvent;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
import mineplex.minecraft.game.classcombat.Skill.Mage.events.FissureModifyBlockEvent;
import mineplex.minecraft.game.classcombat.item.ItemFactory;
import mineplex.minecraft.game.classcombat.shop.ClassCombatShop;
import mineplex.minecraft.game.classcombat.shop.ClassShopManager;
@ -96,7 +118,7 @@ import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire;
import mineplex.minecraft.game.core.mechanics.Weapon;
import mineplex.serverdata.commands.ServerCommandManager;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -113,13 +135,18 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.*;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelation
{
@ -153,6 +180,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
private GearManager _gearManager;
private LootManager _lootManager;
private DonationManager _donationManager;
private InventoryManager _inventoryManager;
private NetherManager _netherManager;
private DamageManager _damageManager;
private SiegeManager _siegeManager;
@ -166,6 +194,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
private mineplex.game.clans.legacytutorial.TutorialManager _legacyTutorial;
private ClassManager _classManager;
private BannerManager _bannerManager;
private AmplifierManager _amplifierManager;
public ClassManager getClassManager()
{
@ -206,21 +236,21 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
public String UserDataDir = UtilServer.getServer().getWorlds().get(0).getWorldFolder().getPath() + File.separator + ".." + File.separator + "CLANS_USER_DATA" + File.separator;
private ClansBanManager _clansBans;
private PacketHandler _packetHandler;
public ClanTips ClanTips;
// Spawn area
public ClansManager(JavaPlugin plugin, ClansBanManager clansBans, String serverName, IncognitoManager incognitoManager, PacketHandler packetHandler, Punish punish, CoreClientManager clientManager, DonationManager donationManager, PreferencesManager preferencesManager, BlockRestore blockRestore, StatsManager statsManager, Teleport teleport, Chat chat, GearManager gearManager, HologramManager hologramManager, String webServerAddress)
public ClansManager(JavaPlugin plugin, ClansBanManager clansBans, String serverName, IncognitoManager incognitoManager, PacketHandler packetHandler, Punish punish, CoreClientManager clientManager, DonationManager donationManager, PreferencesManager preferencesManager, BlockRestore blockRestore, StatsManager statsManager, Teleport teleport, Chat chat, GearManager gearManager, HologramManager hologramManager, InventoryManager inventoryManager, String webServerAddress)
{
super("Clans Manager", plugin);
_instance = this;
_clansBans = clansBans;
_punish = punish;
_packetHandler = packetHandler;
_incognitoManager = incognitoManager;
_serverName = serverName;
_clientManager = clientManager;
@ -233,10 +263,10 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_warManager = new WarManager(plugin, this);
_donationManager = donationManager;
_inventoryManager = inventoryManager;
_blacklist = new ClansBlacklist(plugin);
_goldManager = new GoldManager(this, _clientManager, donationManager);
_gearManager = gearManager;
_lootManager = new LootManager(gearManager, _goldManager);
_disguiseManager = new DisguiseManager(plugin, packetHandler);
@ -289,8 +319,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
new ClanEnergyTracker(plugin, this);
// new StuckManager(this);
new ClansBetaManager(this, _taskManager);
new PotatoManager(plugin, this);
new Weapon(plugin, energy);
@ -355,11 +383,15 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_playTracker = new Playtime(this, statsManager);
_legacyTutorial = new mineplex.game.clans.legacytutorial.TutorialManager(plugin, _playTracker, _goldManager, _taskManager, donationManager, preferencesManager, this, packetHandler);
_scoreboard = new ClansScoreboardManager(plugin, this, _warManager, _worldEvent, _tutorial, clientManager, donationManager);
_clanDataAccess = new ClansDataAccessLayer(this, _scoreboard);
_bannerManager = new BannerManager(plugin);
_goldManager = new GoldManager(this, _clientManager, donationManager, _clanDataAccess);
_legacyTutorial = new mineplex.game.clans.legacytutorial.TutorialManager(plugin, _playTracker, _goldManager, _taskManager, donationManager, preferencesManager, this, packetHandler);
for (ClanToken token : _clanDataAccess.getRepository().retrieveClans())
{
loadClan(token);
@ -413,8 +445,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
for (Location location : welcomeHolograms)
{
Hologram hologram = new Hologram(hologramManager, location,
C.cGreenB + "Welcome to Clans Beta",
C.cWhite + "Please be aware there may be bugs",
C.cGreenB + "Welcome to Clans!",
C.cWhite + "Type " + C.cYellow + "/clan" + C.cWhite + " to get started!"
);
hologram.start();
@ -422,7 +453,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_siegeManager = new SiegeManager(this);
// _netherManager = new NetherManager(this);
_netherManager = new NetherManager(this);
_amplifierManager = new AmplifierManager(plugin);
}
@Override
@ -450,6 +482,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
for (ClanTerritoryToken territoryToken : clanToken.Territories)
_claimMap.put(territoryToken.Chunk, new ClanTerritory(territoryToken));
_bannerManager.loadBanner(clan);
}
public DisguiseManager getDisguiseManager()
@ -487,6 +521,11 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return _goldManager;
}
public InventoryManager getInventoryManager()
{
return _inventoryManager;
}
public ItemMapManager getItemMapManager()
{
return _itemMapManager;
@ -497,6 +536,21 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return _explosion;
}
public PacketHandler getPacketHandler()
{
return _packetHandler;
}
public BannerManager getBannerManager()
{
return _bannerManager;
}
public AmplifierManager getAmplifierManager()
{
return _amplifierManager;
}
public int getInviteExpire()
{
return _inviteExpire;
@ -607,6 +661,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
public void Join(PlayerJoinEvent event)
{
event.setJoinMessage(null);
UtilPlayer.message(event.getPlayer(), C.cDAquaB + "Welcome to Mineplex Clans!");
if (_incognitoManager.Get(event.getPlayer()).Status)
{
@ -745,7 +800,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
continue;
}
UtilPlayer.message(event.getPlayer(), F.main("Clans", "Server is on version: " + F.elem(Clans.version())));
UtilPlayer.message(event.getPlayer(), F.main("Clans", "Server is running Mineplex Clans version " + _plugin.getDescription().getVersion() + "!"));
event.setCancelled(true);
}
}
@ -1165,8 +1220,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
if (online >= UtilServer.getServer().getMaxPlayers() && !rank.has(Rank.ADMIN) && !event.getPlayer().isWhitelisted() && !event.getPlayer().isOp())
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Clans Beta is full! Try again soon");
event.setKickMessage("Clans Beta is full! Try again soon");
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "This Clans server is full! Try again soon");
event.setKickMessage("This Clans server is full! Try again soon");
}
else
{
@ -1189,7 +1244,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{
if (event.getMessage().toLowerCase().equals("/lobby") || event.getMessage().toLowerCase().equals("/hub") || event.getMessage().toLowerCase().equals("/leave"))
{
Portal.getInstance().sendPlayerToServer(event.getPlayer(), "Lobby");
Portal.getInstance().sendPlayerToServer(event.getPlayer(), "ClansHub");
event.setCancelled(true);
}
}

View File

@ -0,0 +1,47 @@
package mineplex.game.clans.clans.amplifiers;
import mineplex.game.clans.clans.amplifiers.AmplifierManager.AmplifierType;
import org.bukkit.entity.Player;
/**
* Data class for active amplifiers
*/
public class Amplifier
{
private Player _owner;
private long _end;
public Amplifier(Player owner, AmplifierType type)
{
_owner = owner;
_end = System.currentTimeMillis() + type.getDuration();
}
/**
* Gets the owner of the amplifier
* @return This amplifier's owner
*/
public Player getOwner()
{
return _owner;
}
/**
* Gets the remaining duration of this amplifier
* @return How much time is left before this amplifier expires
*/
public long getRemainingTime()
{
return Math.max(0, _end - System.currentTimeMillis());
}
/**
* Checks whether this amplifier has run out of time
* @return Whether this amplifier has run out of time
*/
public boolean isEnded()
{
return System.currentTimeMillis() >= _end;
}
}

View File

@ -0,0 +1,23 @@
package mineplex.game.clans.clans.amplifiers;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import org.bukkit.entity.Player;
/**
* Main amplifier command
*/
public class AmplifierCommand extends CommandBase<AmplifierManager>
{
public AmplifierCommand(AmplifierManager plugin)
{
super(plugin, Rank.ALL, "amplifier", "runeamplifier");
}
@Override
public void Execute(Player caller, String[] args)
{
new AmplifierGUI(caller, Plugin);
}
}

View File

@ -0,0 +1,197 @@
package mineplex.game.clans.clans.amplifiers;
import java.util.HashMap;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.amplifiers.AmplifierManager.AmplifierType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* GUI manager for amplifiers
*/
public class AmplifierGUI implements Listener
{
private Player _viewer;
private AmplifierManager _manager;
private Inventory _inventory;
private final HashMap<Integer, ItemStack> _items = new HashMap<>();
private final HashMap<Integer, AmplifierType> _boundSlots = new HashMap<>();
private AmplifierType _selected;
public AmplifierGUI(Player viewer, AmplifierManager manager)
{
_viewer = viewer;
_manager = manager;
_inventory = Bukkit.createInventory(viewer, 9, C.cClansNether + "Rune Amplifiers");
Bukkit.getPluginManager().registerEvents(this, manager.getPlugin());
propagate();
open();
}
/**
* Gets the owner of this specific inventory
* @return The owner of this inventory
*/
public Player getViewer()
{
return _viewer;
}
/**
* Fetches all the items registered as buttons in this inventory gui
* @return A list of the items registered as buttons in this inventory gui
*/
public HashMap<Integer, ItemStack> getItems()
{
return _items;
}
/**
* Fills the gui with buttons
*/
public void propagate()
{
getItems().clear();
Integer slot = 0;
for (AmplifierType type : AmplifierType.values())
{
int owned = _manager.getAmountOwned(getViewer(), type);
owned = Math.max(owned, 0);
getItems().put(slot, new ItemBuilder(Material.NETHER_STAR).setAmount(Math.min(owned, 1)).setTitle(type.getDisplayName()).setLore(F.elem(owned) + " Owned").build());
_boundSlots.put(slot, type);
slot++;
}
refresh();
}
/**
* Fils the confirmation menu with buttons
*/
public void propagateConfirmation()
{
getItems().clear();
_boundSlots.clear();
getItems().put(3, new ItemBuilder(Material.STAINED_GLASS_PANE).setData((short) 5).setTitle(C.cGreen + "Confirm").build());
getItems().put(5, new ItemBuilder(Material.STAINED_GLASS_PANE).setData((short) 14).setTitle(C.cRed + "Cancel").build());
refresh();
}
/**
* Handles players clicking on buttons
* @param slot The slot clicked on
* @param type The type of click
*/
public void onClick(Integer slot, ClickType type)
{
if (_boundSlots.containsKey(slot))
{
if (_manager.hasActiveAmplifier())
{
UtilPlayer.message(getViewer(), F.main(_manager.getName(), "An amplifier is already active!"));
_manager.runSyncLater(() ->
{
getViewer().closeInventory();
}, 1L);
}
else
{
_selected = _boundSlots.get(slot);
if (_manager.getAmountOwned(getViewer(), _selected) > 0)
{
propagateConfirmation();
}
else
{
UtilPlayer.message(getViewer(), F.main(_manager.getName(), "You do not have enough of that amplifier! Purchase some at http://www.mineplex.com/shop!"));
}
}
return;
}
if (slot == 3)
{
_manager.runSyncLater(() ->
{
_manager.useAmplifier(getViewer(), _selected);
getViewer().closeInventory();
}, 1L);
}
if (slot == 5)
{
_selected = null;
propagate();
}
}
/**
* Opens this inventory to its viewer
*/
public void open()
{
_viewer.openInventory(_inventory);
}
/**
* Updates the GUI's visuals to match registered button items
*/
public void refresh()
{
_inventory.clear();
for (Integer slot : _items.keySet())
{
_inventory.setItem(slot, _items.get(slot));
}
for (Integer slot = 0; slot < _inventory.getSize(); slot++)
{
if (!_items.containsKey(slot))
{
_inventory.setItem(slot, new ItemBuilder(Material.STAINED_GLASS_PANE).setTitle(C.cGray).setData((short)7).build());
}
}
_viewer.updateInventory();
}
@EventHandler
public void handleClick(InventoryClickEvent event)
{
if (event.getClickedInventory() == null || !event.getClickedInventory().equals(_inventory))
{
return;
}
if (!_viewer.getName().equals(event.getWhoClicked().getName()))
{
return;
}
event.setCancelled(true);
Integer slot = event.getSlot();
if (!_items.containsKey(slot))
{
return;
}
onClick(slot, event.getClick());
}
@EventHandler
public void onClose(InventoryCloseEvent event)
{
if (event.getPlayer().getUniqueId().equals(_viewer.getUniqueId()))
{
HandlerList.unregisterAll(this);
}
}
}

View File

@ -0,0 +1,155 @@
package mineplex.game.clans.clans.amplifiers;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Manager for using amplifiers in clans
*/
public class AmplifierManager extends MiniPlugin
{
public static final double AMPLIFIER_RUNE_DROP_MULTIPLIER = 2;
private static final String AMPLIFIER_NAME = "Rune Amplifier";
private Amplifier _active;
public AmplifierManager(JavaPlugin plugin)
{
super("Rune Amplifiers", plugin);
addCommand(new AmplifierCommand(this));
}
/**
* Checks whether there is an amplifier active on this server
* @return Whether there is an amplifier active on this server
*/
public boolean hasActiveAmplifier()
{
return _active != null;
}
/**
* Checks how many of a certain amplifier type a player owns
* @param player The player to check
* @param type The type of amplifier to check for
* @return The amount of amplifiers of that type owned
*/
public int getAmountOwned(Player player, AmplifierType type)
{
return ClansManager.getInstance().getInventoryManager().Get(player).getItemCount(type.getFullItemName());
}
/**
* Makes a player use an amplifier
* @param user The player to use the amplifier
* @param type The type of amplifier to use
*/
public void useAmplifier(Player user, AmplifierType type)
{
if (getAmountOwned(user, type) < 1)
{
return;
}
if (hasActiveAmplifier())
{
return;
}
ClansManager.getInstance().getInventoryManager().addItemToInventory(user, type.getFullItemName(), -1);
UtilTextMiddle.display(C.cClansNether + AMPLIFIER_NAME, "Has been activated by " + F.elem(user.getName()));
Bukkit.broadcastMessage(F.main(getName(), "A " + F.clansNether(AMPLIFIER_NAME) + " has been activated on this server by " + F.elem(user.getName()) + " for " + F.elem(UtilTime.MakeStr(type.getDuration())) + "!"));
_active = new Amplifier(user, type);
runSyncLater(() ->
{
ClansManager.getInstance().getNetherManager().spawnPortal(type.getDuration());
}, 60L);
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
if (_active != null && _active.isEnded())
{
Bukkit.broadcastMessage(F.main(getName(), "The " + F.clansNether(AMPLIFIER_NAME) + " owned by " + F.elem(_active.getOwner()) + " has run out! You can purchase another at http://www.mineplex.com/shop!"));
_active = null;
}
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
if (_active != null)
{
runSyncLater(() ->
{
if (_active != null)
{
UtilPlayer.message(event.getPlayer(), F.main(getName(), "A " + F.clansNether(AMPLIFIER_NAME) + " owned by " + F.elem(_active.getOwner().getName()) + " is active on this server with " + F.elem(UtilTime.MakeStr(_active.getRemainingTime())) + " remaining!"));
}
}, 40L);
}
}
/**
* Enum containing different types of amplifiers recognized by code
*/
public static enum AmplifierType
{
TWENTY("20", "Twenty Minute Amplifier", UtilTime.convert(20, TimeUnit.MINUTES, TimeUnit.MILLISECONDS)),
SIXTY("60", "One Hour Amplifier", UtilTime.convert(60, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
private String _extension, _display;
private long _duration;
private AmplifierType(String extension, String displayName, long duration)
{
_extension = extension;
_display = C.cClansNether + displayName;
_duration = duration;
}
/**
* Gets the full name of this amplifier as recognized by the inventory database
* @return The full name of this amplifier as recognized by the inventory database
*/
public String getFullItemName()
{
return AMPLIFIER_NAME + " " + _extension;
}
/**
* Gets the display name for this amplifier in this GUI
* @return The display name for this amplifier in this GUI
*/
public String getDisplayName()
{
return _display;
}
/**
* Gets the total duration for this type of amplifier
* @return The total duration for this type of amplifier
*/
public long getDuration()
{
return _duration;
}
}
}

View File

@ -1,23 +1,52 @@
package mineplex.game.clans.clans.ban;
import java.util.HashMap;
import java.util.UUID;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.donation.DonationManager;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ban.commands.ClansBanCommand;
import mineplex.game.clans.clans.ban.commands.FreezeCommand;
import mineplex.game.clans.clans.ban.commands.UnfreezeCommand;
import mineplex.game.clans.clans.event.ClansCommandExecutedEvent;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class ClansBanManager extends MiniPlugin
{
private static final long FREEZE_MESSAGE_INTERVAL = 10000;
private final CoreClientManager _clientManager;
private final DonationManager _donationManager;
private final ClansBanRepository _repository;
private final HashMap<UUID, Float> _frozen = new HashMap<>();
public ClansBanManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
{
@ -34,6 +63,8 @@ public class ClansBanManager extends MiniPlugin
public void addCommands()
{
addCommand(new ClansBanCommand(this));
addCommand(new FreezeCommand(this));
addCommand(new UnfreezeCommand(this));
}
public CoreClientManager getClientManager()
@ -74,6 +105,202 @@ public class ClansBanManager extends MiniPlugin
}
} catch (Exception ignored) {}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onQuit(PlayerQuitEvent event)
{
Float walkSpeed = _frozen.remove(event.getPlayer().getUniqueId());
if (walkSpeed != null)
{
event.getPlayer().setWalkSpeed(walkSpeed);
event.getPlayer().removePotionEffect(PotionEffectType.JUMP);
for (Player staff : UtilServer.GetPlayers())
{
if (_clientManager.hasRank(staff, Rank.HELPER))
{
UtilPlayer.message(staff, F.main(getName(), F.elem(event.getPlayer().getName()) + " has logged out while frozen!"));
}
}
}
}
@EventHandler
public void onMove(PlayerMoveEvent event)
{
if (isFrozen(event.getPlayer()) && UtilMath.offset2d(event.getFrom().getBlock().getLocation(), event.getTo().getBlock().getLocation()) >= 1)
{
event.setCancelled(true);
event.getPlayer().teleport(event.getFrom().getBlock().getLocation().add(0, 1, 0));
}
}
@EventHandler
public void onDisplayFreezeMessage(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
for (UUID frozenUUID : _frozen.keySet())
{
Player frozen = Bukkit.getPlayer(frozenUUID);
if (Recharge.Instance.use(frozen, "Freeze Message", FREEZE_MESSAGE_INTERVAL, false, false))
{
String border = C.cGray + C.Strike + "-----------------------------------------------------";
String sq = "\u2589";
UtilPlayer.message(frozen, border);
UtilPlayer.message(frozen, C.Reset + "");
UtilPlayer.message(frozen, C.cWhite + sq + sq + sq + sq + C.cRed + sq + C.cWhite + sq + sq + sq + sq);
UtilPlayer.message(frozen, C.cWhite + sq + sq + sq + C.cRed + sq + C.cBlack + sq + C.cRed + sq + C.cWhite + sq + sq + sq);
UtilPlayer.message(frozen, C.cWhite + sq + sq + C.cRed + sq + C.cGold + sq + C.cBlack + sq + C.cGold + sq + C.cRed + sq + C.cWhite + sq + sq);
UtilPlayer.message(frozen, C.cWhite + sq + sq + C.cRed + sq + C.cGold + sq + C.cBlack + sq + C.cGold + sq + C.cRed + sq + C.cWhite + sq + sq);
UtilPlayer.message(frozen, C.cWhite + sq + sq + C.cRed + sq + C.cGold + sq + C.cBlack + sq + C.cGold + sq + C.cRed + sq + C.cWhite + sq + sq);
UtilPlayer.message(frozen, C.cWhite + sq + C.cRed + sq + C.cGold + sq + sq + sq + C.cGold + sq + sq + C.cRed + sq + C.cWhite + sq);
UtilPlayer.message(frozen, C.cRed + sq + C.cGold + sq + sq + sq + C.cBlack + sq + C.cGold + sq + sq + sq + C.cRed + sq);
UtilPlayer.message(frozen, C.cRed + sq + sq + sq + sq + sq + sq + sq + sq + sq);
UtilPlayer.message(frozen, C.Reset + "");
UtilPlayer.message(frozen, C.cRed + "You have been frozen by a staff member!");
UtilPlayer.message(frozen, C.cRed + "Do not log out or you will be banned!");
UtilPlayer.message(frozen, C.Reset + "");
UtilPlayer.message(frozen, border);
}
}
}
@EventHandler
public void handleMobs(EntityTargetLivingEntityEvent event)
{
if (event.getTarget() instanceof Player)
{
Player player = (Player) event.getTarget();
if (isFrozen(player))
{
event.setCancelled(true);
}
}
}
@EventHandler
public void onDamage(CustomDamageEvent event)
{
Player damager = event.GetDamagerPlayer(event.GetCause() == DamageCause.PROJECTILE);
Player damagee = event.GetDamageePlayer();
if (damager != null && isFrozen(damager))
{
event.SetCancelled("Frozen Attacker");
UtilPlayer.message(damager, F.main(getName(), "You cannot attack others while frozen!"));
}
if (damagee != null && isFrozen(damagee))
{
event.SetCancelled("Frozen Damagee");
if (damager != null)
{
UtilPlayer.message(damager, F.main(getName(), "You cannot attack " + F.elem(damagee.getName()) + " while they are frozen!"));
}
}
}
@EventHandler
public void onUseSkill(SkillTriggerEvent event)
{
if (isFrozen(event.GetPlayer()))
{
event.SetCancelled(true);
UtilPlayer.message(event.GetPlayer(), F.main(getName(), "You cannot use " + F.skill(event.GetSkillName()) + " while frozen!"));
}
}
@EventHandler
public void onBreak(BlockBreakEvent event)
{
if (isFrozen(event.getPlayer()))
{
event.setCancelled(true);
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You cannot break blocks while frozen!"));
}
}
@EventHandler
public void onPlace(BlockPlaceEvent event)
{
if (isFrozen(event.getPlayer()))
{
event.setCancelled(true);
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You cannot place blocks while frozen!"));
}
}
@EventHandler
public void onTpHome(ClansCommandExecutedEvent event)
{
if (event.getCommand().equalsIgnoreCase("tphome"))
{
if (isFrozen(event.getPlayer()))
{
event.setCancelled(true);
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You cannot teleport to your Clan home while frozen!"));
}
}
}
/**
* Checks if a player is frozen
* @param player The player to check
* @return Whether the player is frozen
*/
public boolean isFrozen(Player player)
{
return _frozen.containsKey(player.getUniqueId());
}
/**
* Freezes a player
* @param player The player to freeze
* @param staff The staff member who froze them
*/
public void freeze(Player player, Player staff)
{
_frozen.put(player.getUniqueId(), player.getWalkSpeed());
player.setWalkSpeed(0);
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 999999, -10));
for (Player alert : UtilServer.GetPlayers())
{
if (_clientManager.hasRank(alert, Rank.HELPER))
{
UtilPlayer.message(alert, F.main(getName(), F.elem(player.getName()) + " has been frozen by " + F.elem(staff.getName()) + "!"));
}
}
}
/**
* Unfreezes a player
* @param player The player to unfreeze
* @param staff The staff member who unfroze them
*/
public void unfreeze(Player player, Player staff)
{
Float walkSpeed = _frozen.remove(player.getUniqueId());
if (walkSpeed != null)
{
player.setWalkSpeed(walkSpeed);
player.removePotionEffect(PotionEffectType.JUMP);
for (Player alert : UtilServer.GetPlayers())
{
if (_clientManager.hasRank(alert, Rank.HELPER))
{
UtilPlayer.message(alert, F.main(getName(), F.elem(player.getName()) + " has been unfrozen by " + F.elem(staff.getName()) + "!"));
continue;
}
if (alert.getName().equals(player.getName()))
{
UtilPlayer.message(alert, F.main(getName(), "You have been unfrozen!"));
}
}
}
}
public void unban(ClansBanClient target, ClansBan ban, Callback<ClansBanClient> callback)
{
@ -87,4 +314,4 @@ public class ClansBanManager extends MiniPlugin
callback.run(target);
}
}
}

View File

@ -22,7 +22,7 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
{
if (args == null || args.length < 1)
{
UtilPlayer.message(caller, C.cBlue + "/cb <username> <reason>" + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view thier past bans.");
UtilPlayer.message(caller, C.cBlue + "/cb <username> <reason>" + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view their past bans.");
}
else if (args.length > 1)
{
@ -52,7 +52,7 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
}
else
{
UtilPlayer.message(caller, C.cBlue + "/cb <username> <reason>" + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view thier past bans.");
UtilPlayer.message(caller, C.cBlue + "/cb <username> <reason>" + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view their past bans.");
}
}
}

View File

@ -0,0 +1,44 @@
package mineplex.game.clans.clans.ban.commands;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ban.ClansBanManager;
import org.bukkit.entity.Player;
/**
* Command to freeze players
*/
public class FreezeCommand extends CommandBase<ClansBanManager>
{
public FreezeCommand(ClansBanManager plugin)
{
super(plugin, Rank.CMOD, "freeze");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args == null || args.length < 1)
{
UtilPlayer.message(caller, C.cBlue + "/freeze <username>" + C.cGray + " - " + C.cYellow + "Freezes a player, restricting their movement and ability to interact with the game.");
}
else if (args.length > 0)
{
Player target = UtilPlayer.searchOnline(caller, args[0], true);
if (target == null)
{
return;
}
if (Plugin.isFrozen(target))
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(args[0]) + " is already frozen!"));
return;
}
Plugin.freeze(target, caller);
}
}
}

View File

@ -0,0 +1,44 @@
package mineplex.game.clans.clans.ban.commands;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ban.ClansBanManager;
import org.bukkit.entity.Player;
/**
* Command to unfreeze players
*/
public class UnfreezeCommand extends CommandBase<ClansBanManager>
{
public UnfreezeCommand(ClansBanManager plugin)
{
super(plugin, Rank.CMOD, "unfreeze");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args == null || args.length < 1)
{
UtilPlayer.message(caller, C.cBlue + "/unfreeze <username>" + C.cGray + " - " + C.cYellow + "Unfreezes a player, restoring their movement and ability to interact with the game.");
}
else if (args.length > 0)
{
Player target = UtilPlayer.searchOnline(caller, args[0], true);
if (target == null)
{
return;
}
if (!Plugin.isFrozen(target))
{
UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(args[0]) + " is not frozen!"));
return;
}
Plugin.unfreeze(target, caller);
}
}
}

View File

@ -0,0 +1,188 @@
package mineplex.game.clans.clans.banners;
import java.util.HashMap;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.banners.command.BannerCommand;
import mineplex.game.clans.core.repository.ClanTerritory;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Banner;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Manager class for cosmetic clans banners
*/
public class BannerManager extends MiniPlugin
{
private static final long BANNER_PLACE_DURATION = UtilTime.convert(30, TimeUnit.MINUTES, TimeUnit.MILLISECONDS);
public final HashMap<String, ClanBanner> LoadedBanners = new HashMap<>();
private final HashMap<Block, Long> _placedBanners = new HashMap<>();
private BannerRepository _repo;
public BannerManager(JavaPlugin plugin)
{
super("Clan Banners", plugin);
_repo = new BannerRepository(plugin, this);
new BannerPacketManager();
addCommand(new BannerCommand(this));
}
/**
* Resets all placed banners to air
*/
@Override
public void disable()
{
for (Block changed : _placedBanners.keySet())
{
changed.setType(Material.AIR);
}
}
/**
* Checks what type of banner unlock a player has
* @param player The player to check
* @return The type of banner unlock a player has
*/
public int getBannerUnlockLevel(Player player)
{
int level = 0;
if (ClansManager.getInstance().getDonationManager().Get(player).OwnsUnknownPackage("Clan Banner Usage"))
{
level = 1;
}
if (ClansManager.getInstance().getDonationManager().Get(player).OwnsUnknownPackage("Clan Banner Editor"))
{
level = 2;
}
if (ClansManager.getInstance().getClientManager().hasRank(player, Rank.ADMIN))
{
level = 2;
}
return level;
}
/**
* Loads a banner for a clan
* @param clan The clan whose banner to load
*/
public void loadBanner(ClanInfo clan)
{
_repo.loadBanner(LoadedBanners, clan);
}
/**
* Saves a banner to the database
* @param banner The banner to save
*/
public void saveBanner(ClanBanner banner)
{
_repo.saveBanner(banner);
}
/**
* Deletes a clan's banner
* @param clan The clan whose banner to delete
*/
public void deleteBanner(ClanInfo clan)
{
_repo.deleteBanner(clan);
LoadedBanners.remove(clan.getName());
}
/**
* Deletes a clan banner
* @param banner The banner to delete
*/
public void deleteBanner(ClanBanner banner)
{
deleteBanner(banner.getClan());
}
/**
* Places a clans banner for a player
* @param placing The player who placed the banner
* @param banner The banner to place
*/
public void placeBanner(Player placing, ClanBanner banner)
{
if (!Recharge.Instance.use(placing, "Place Banner", 30000, true, false))
{
return;
}
Block block = placing.getLocation().getBlock();
BlockPlaceEvent event = new BlockPlaceEvent(block, block.getState(), block, placing.getItemInHand(), placing, true);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled())
{
ClanTerritory claim = ClansManager.getInstance().getClanUtility().getClaim(block.getLocation());
if (claim != null && !claim.Owner.equals(banner.getClan().getName()))
{
UtilPlayer.message(placing, F.main("Clans", "You cannot place your Clan Banner there."));
return;
}
ClansManager.getInstance().getBlockRestore().restore(block);
if (block.getType() == Material.AIR && UtilBlock.fullSolid(block.getRelative(BlockFace.DOWN)))
{
block.setType(Material.STANDING_BANNER);
Banner state = (Banner) block.getState();
state.setBaseColor(banner.getBaseColor());
state.setPatterns(((BannerMeta)banner.getBanner().getItemMeta()).getPatterns());
state.update();
_placedBanners.put(block, System.currentTimeMillis());
}
else
{
UtilPlayer.message(placing, F.main("Clans", "You cannot place your Clan Banner there."));
return;
}
}
}
@EventHandler
public void onBreak(BlockBreakEvent event)
{
if (_placedBanners.containsKey(event.getBlock()))
{
_placedBanners.remove(event.getBlock());
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
}
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() == UpdateType.FAST)
{
for (Block reset : _placedBanners.keySet())
{
if (UtilTime.elapsed(_placedBanners.get(reset), BANNER_PLACE_DURATION))
{
reset.setType(Material.AIR);
}
}
}
}
}

View File

@ -0,0 +1,113 @@
package mineplex.game.clans.clans.banners;
import java.lang.reflect.Field;
import java.util.HashMap;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.game.clans.clans.ClansManager;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment;
import net.minecraft.server.v1_8_R3.PacketPlayOutSetSlot;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
/**
* Handler for banner wearing packets
*/
public class BannerPacketManager implements Listener
{
private Field _itemField;
private static BannerPacketManager Instance;
private final HashMap<Player, IPacketHandler> _wearing = new HashMap<>();
public BannerPacketManager()
{
try
{
_itemField = PacketPlayOutSetSlot.class.getDeclaredField("c");
_itemField.setAccessible(true);
Bukkit.getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
}
catch (Exception e)
{
e.printStackTrace();
}
Instance = this;
}
/**
* Fetches the registered loaded instance of this class
* @return The loaded instance of this class
*/
public static BannerPacketManager getInstance()
{
return Instance;
}
/**
* Toggles a player wearing their clan's banner
* @param player The player to toggle for
* @param banner The banner to toggle
*/
public void toggleBanner(Player player, ItemStack banner)
{
if (_wearing.containsKey(player))
{
IPacketHandler bannerHandler = _wearing.remove(player);
ClansManager.getInstance().getPacketHandler().removePacketHandler(bannerHandler);
for (Player refresh : Bukkit.getOnlinePlayers())
{
ItemStack helmet = new ItemStack(Material.AIR);
if (player.getInventory().getHelmet() != null)
{
helmet = player.getInventory().getHelmet();
}
UtilPlayer.sendPacket(refresh, new PacketPlayOutEntityEquipment(player.getEntityId(), 4, CraftItemStack.asNMSCopy(helmet)));
}
}
else
{
IPacketHandler bannerHandler = new IPacketHandler()
{
@Override
public void handle(PacketInfo packetInfo)
{
if (packetInfo.getPacket() instanceof PacketPlayOutEntityEquipment)
{
PacketPlayOutEntityEquipment equip = (PacketPlayOutEntityEquipment) packetInfo.getPacket();
if (equip.a == player.getEntityId() && equip.b == 4)
{
equip.c = CraftItemStack.asNMSCopy(banner);
}
}
}
};
_wearing.put(player, bannerHandler);
ClansManager.getInstance().getPacketHandler().addPacketHandler(bannerHandler, PacketPlayOutEntityEquipment.class);
for (Player refresh : Bukkit.getOnlinePlayers())
{
UtilPlayer.sendPacket(refresh, new PacketPlayOutEntityEquipment(player.getEntityId(), 4, CraftItemStack.asNMSCopy(banner)));
}
}
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
if (_wearing.containsKey(event.getPlayer()))
{
ClansManager.getInstance().getPacketHandler().removePacketHandler(_wearing.remove(event.getPlayer()));
}
}
}

View File

@ -0,0 +1,84 @@
package mineplex.game.clans.clans.banners;
import org.bukkit.DyeColor;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
/**
* Data class for clans banner patterns
*/
public class BannerPattern
{
private int _layer;
private DyeColor _color;
private PatternType _type;
public BannerPattern(int layer, DyeColor color, PatternType type)
{
_layer = layer;
_color = color;
_type = type;
}
public BannerPattern(int layer)
{
_layer = layer;
_color = null;
_type = null;
}
/**
* Gets the layer this pattern occupies on the clan's banner
* @return The layer this pattern occupies on the clan's banner
*/
public int getLayer()
{
return _layer;
}
/**
* Gets the Bukkit version of this banner pattern
* @return The Bukkit version of this banner pattern, or null if this is not a fully configured pattern
*/
public Pattern getBukkitPattern()
{
if (_color == null || _type == null)
{
return null;
}
return new Pattern(_color, _type);
}
/**
* Gets the form this banner pattern will take in the database
* @return The form this banner pattern will take in the database
*/
public String getDatabaseForm()
{
if (_color == null || _type == null)
{
return "Blank";
}
return _color.toString() + "," + _type.toString();
}
/**
* Sets the color of this banner pattern
* @param color The color to set this pattern to
*/
public void setColor(DyeColor color)
{
_color = color;
}
/**
* Sets the design of this banner pattern
* @param color The design to set this pattern to
*/
public void setPatternType(PatternType type)
{
_type = type;
}
}

View File

@ -0,0 +1,126 @@
package mineplex.game.clans.clans.banners;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import mineplex.core.database.MinecraftRepository;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import org.bukkit.DyeColor;
import org.bukkit.block.banner.PatternType;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Database repository class for banners
*/
public class BannerRepository extends MinecraftRepository
{
private static final String CREATE = "CREATE TABLE IF NOT EXISTS clanBanners (clanId INT NOT NULL,"
+ "baseColor VARCHAR(15),"
+ "patterns VARCHAR(300),"
+ "PRIMARY KEY (clanId));";
private static final String GET_BANNER_BY_CLAN = "SELECT * FROM clanBanners WHERE clanId=? LIMIT 1;";
private static final String INSERT_BANNER = "INSERT INTO clanBanners (clanId, baseColor, patterns) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE baseColor=VALUES(baseColor), patterns=VALUES(patterns);";
private static final String DELETE_BANNER = "DELETE FROM clanBanners WHERE clanId=?;";
private BannerManager _bannerManager;
public BannerRepository(JavaPlugin plugin, BannerManager bannerManager)
{
super(plugin, DBPool.getAccount());
_bannerManager = bannerManager;
}
/**
* Loads a banner for a certain clan into a given hashmap
* @param map The hashmap to load the banner into
* @param clan The clan whose banner to fetch
*/
public void loadBanner(final HashMap<String, ClanBanner> map, ClanInfo clan)
{
_bannerManager.runAsync(() ->
{
executeQuery(GET_BANNER_BY_CLAN, resultSet ->
{
while(resultSet.next())
{
DyeColor baseColor = DyeColor.valueOf(resultSet.getString("baseColor"));
List<String> patternStrs = Arrays.asList(resultSet.getString("patterns").split("/"));
LinkedList<BannerPattern> patterns = new LinkedList<>();
int layer = 1;
for (String patternStr : patternStrs)
{
if (patternStr.equalsIgnoreCase("Blank"))
{
patterns.add(new BannerPattern(layer));
}
else
{
try
{
DyeColor patternColor = DyeColor.valueOf(patternStr.split(",")[0]);
PatternType patternType = PatternType.valueOf(patternStr.split(",")[1]);
patterns.add(new BannerPattern(layer, patternColor, patternType));
}
catch (Exception e)
{
e.printStackTrace();
patterns.add(new BannerPattern(layer));
}
}
layer++;
}
map.put(clan.getName(), new ClanBanner(_bannerManager, clan, baseColor, patterns));
}
}, new ColumnInt("clanId", clan.getId()));
});
}
/**
* Saves a banner into the database
* @param banner The banner to save
*/
public void saveBanner(ClanBanner banner)
{
_bannerManager.runAsync(() ->
{
String patternStr = "";
for (BannerPattern pattern : banner.getPatterns())
{
if (!patternStr.equalsIgnoreCase(""))
{
patternStr = patternStr + "/";
}
patternStr = patternStr + pattern.getDatabaseForm();
}
executeUpdate(INSERT_BANNER, new ColumnInt("clanId", banner.getClan().getId()), new ColumnVarChar("baseColor", 15, banner.getBaseColor().toString()), new ColumnVarChar("patterns", 300, patternStr));
});
}
/**
* Deletes a banner from the database
* @param clan The clan whose banner to delete
*/
public void deleteBanner(ClanInfo clan)
{
_bannerManager.runAsync(() ->
{
executeUpdate(DELETE_BANNER, new ColumnInt("clanId", clan.getId()));
});
}
@Override
protected void initialize()
{
executeUpdate(CREATE);
}
@Override
protected void update() {}
}

View File

@ -0,0 +1,113 @@
package mineplex.game.clans.clans.banners;
import java.util.LinkedList;
import java.util.List;
import mineplex.core.common.util.C;
import mineplex.game.clans.clans.ClanInfo;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.banner.Pattern;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import com.google.common.collect.Lists;
/**
* Data class for clan banners
*/
public class ClanBanner
{
private BannerManager _manager;
private ClanInfo _clan;
private DyeColor _baseColor;
private LinkedList<BannerPattern> _patterns;
public ClanBanner(BannerManager manager, ClanInfo clan, DyeColor baseColor, LinkedList<BannerPattern> patterns)
{
_manager = manager;
_clan = clan;
_baseColor = baseColor;
_patterns = patterns;
}
/**
* Gets the clan that owns this banner
* @return The clan that owns this banner
*/
public ClanInfo getClan()
{
return _clan;
}
/**
* Gets the base color for this banner
* @return The base color for this banner
*/
public DyeColor getBaseColor()
{
return _baseColor;
}
/**
* Gets this banner's patterns
* @return This banner's patterns
*/
public LinkedList<BannerPattern> getPatterns()
{
return _patterns;
}
/**
* Gets the ItemStack representation of this banner
* @return The ItemStack representation of this banner
*/
public ItemStack getBanner()
{
ItemStack banner = new ItemStack(Material.BANNER);
BannerMeta im = (BannerMeta) banner.getItemMeta();
im.setDisplayName(C.cGray + _clan.getName() + "'s Banner");
im.setBaseColor(_baseColor);
List<Pattern> patterns = Lists.newArrayList();
for (BannerPattern bp : _patterns)
{
if (bp.getBukkitPattern() != null)
{
patterns.add(bp.getBukkitPattern());
}
}
im.setPatterns(patterns);
banner.setItemMeta(im);
return banner;
}
/**
* Sets the base color of this banner
* @param color The color to set
*/
public void setBaseColor(DyeColor color)
{
_baseColor = color;
}
/**
* Saves this banner to the database
*/
public void save()
{
_manager.saveBanner(this);
}
/**
* Places this banner on the ground
* @param player The player to place the banner for
*/
public void place(Player player)
{
_manager.placeBanner(player, this);
}
}

View File

@ -0,0 +1,66 @@
package mineplex.game.clans.clans.banners.command;
import java.util.LinkedList;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.banners.BannerManager;
import mineplex.game.clans.clans.banners.BannerPattern;
import mineplex.game.clans.clans.banners.ClanBanner;
import mineplex.game.clans.clans.banners.gui.nonedit.NonEditOverviewGUI;
import org.bukkit.DyeColor;
import org.bukkit.entity.Player;
/**
* Main banner usage command
*/
public class BannerCommand extends CommandBase<BannerManager>
{
public BannerCommand(BannerManager plugin)
{
super(plugin, Rank.ALL, "banner");
}
@Override
public void Execute(Player caller, String[] args)
{
if (ClansManager.getInstance().getClan(caller) == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not in a Clan!"));
return;
}
ClanInfo clan = ClansManager.getInstance().getClan(caller);
if (Plugin.getBannerUnlockLevel(caller) < 1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have not purchased the ability to use Clan banners! Buy it at http://www.mineplex.com/shop!"));
return;
}
if (!Plugin.LoadedBanners.containsKey(clan.getName()))
{
if (Plugin.getBannerUnlockLevel(caller) >= 2 && clan.getMembers().get(caller.getUniqueId()).getRole() == ClanRole.LEADER)
{
LinkedList<BannerPattern> patterns = new LinkedList<>();
for (int i = 0; i < 12; i++)
{
patterns.add(new BannerPattern(i + 1));
}
ClanBanner banner = new ClanBanner(Plugin, clan, DyeColor.WHITE, patterns);
Plugin.LoadedBanners.put(clan.getName(), banner);
banner.save();
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Your Clan does not have a set banner!"));
return;
}
}
new NonEditOverviewGUI(caller, Plugin.LoadedBanners.get(clan.getName()));
}
}

View File

@ -0,0 +1,123 @@
package mineplex.game.clans.clans.banners.gui;
import java.util.HashMap;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClansManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
* Base class to manage banner guis
*/
public abstract class BannerGUI implements Listener
{
private Player _viewer;
private Inventory _inventory;
private final HashMap<Integer, ItemStack> _items = new HashMap<>();
public BannerGUI(Player viewer, String pageName, int slots)
{
_viewer = viewer;
_inventory = Bukkit.createInventory(viewer, slots, pageName);
Bukkit.getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
}
/**
* Gets the owner of this specific inventory
* @return The owner of this inventory
*/
public Player getViewer()
{
return _viewer;
}
/**
* Fetches all the items registered as buttons in this inventory gui
* @return A list of the items registered as buttons in this inventory gui
*/
public HashMap<Integer, ItemStack> getItems()
{
return _items;
}
/**
* Fills the gui with buttons
*/
public abstract void propagate();
/**
* Handles players clicking on buttons
* @param slot The slot clicked on
* @param type The type of click
*/
public abstract void onClick(Integer slot, ClickType type);
/**
* Opens this inventory to its viewer
*/
public void open()
{
_viewer.openInventory(_inventory);
}
/**
* Updates the GUI's visuals to match registered button items
*/
public void refresh()
{
_inventory.clear();
for (Integer slot : _items.keySet())
{
_inventory.setItem(slot, _items.get(slot));
}
for (Integer slot = 0; slot < _inventory.getSize(); slot++)
{
if (!_items.containsKey(slot))
{
_inventory.setItem(slot, new ItemBuilder(Material.STAINED_GLASS_PANE).setTitle(C.cGray).setData((short)7).build());
}
}
_viewer.updateInventory();
}
@EventHandler
public void handleClick(InventoryClickEvent event)
{
if (event.getClickedInventory() == null || !event.getClickedInventory().equals(_inventory))
{
return;
}
if (!_viewer.getName().equals(event.getWhoClicked().getName()))
{
return;
}
event.setCancelled(true);
Integer slot = event.getSlot();
if (!_items.containsKey(slot))
{
return;
}
onClick(slot, event.getClick());
}
@EventHandler
public void onClose(InventoryCloseEvent event)
{
if (event.getPlayer().getUniqueId().equals(_viewer.getUniqueId()))
{
HandlerList.unregisterAll(this);
}
}
}

View File

@ -0,0 +1,78 @@
package mineplex.game.clans.clans.banners.gui.creation;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.banners.ClanBanner;
import mineplex.game.clans.clans.banners.gui.BannerGUI;
import mineplex.game.clans.clans.banners.gui.overview.OverviewGUI;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
/**
* GUI manager for selecting a banner's base color
*/
public class BaseColorSelectionGUI extends BannerGUI
{
private ClanBanner _banner;
public BaseColorSelectionGUI(Player viewer, ClanBanner banner)
{
super(viewer, "Background Color", 27);
_banner = banner;
propagate();
open();
}
@Override
public void propagate()
{
Integer slot = 1;
for (short data = 0; data <= 15; data++)
{
getItems().put(slot, new ItemBuilder(Material.INK_SACK).setData(data).setTitle(C.cGray).build());
if ((slot + 1) == 8)
{
slot = 10;
}
else if ((slot + 1) == 17)
{
slot = 21;
}
else if ((slot + 1) == 22)
{
slot = 23;
}
else
{
slot++;
}
}
refresh();
}
@SuppressWarnings("deprecation")
@Override
public void onClick(Integer slot, ClickType type)
{
if (getItems().get(slot).getType() == Material.INK_SACK)
{
DyeColor color = DyeColor.getByDyeData(getItems().get(slot).getData().getData());
_banner.setBaseColor(color);
_banner.save();
ClansManager.getInstance().runSyncLater(() ->
{
getViewer().closeInventory();
}, 1L);
ClansManager.getInstance().runSyncLater(() ->
{
new OverviewGUI(getViewer(), _banner);
}, 2L);
}
}
}

View File

@ -0,0 +1,80 @@
package mineplex.game.clans.clans.banners.gui.creation;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.banners.BannerPattern;
import mineplex.game.clans.clans.banners.ClanBanner;
import mineplex.game.clans.clans.banners.gui.BannerGUI;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
/**
* GUI manager for selecting a banner pattern's base color
*/
public class PatternColorSelectionGUI extends BannerGUI
{
private ClanBanner _banner;
private int _bannerPos;
public PatternColorSelectionGUI(Player viewer, ClanBanner banner, int bannerPosition)
{
super(viewer, "Pattern Color", 27);
_banner = banner;
_bannerPos = bannerPosition;
propagate();
open();
}
@Override
public void propagate()
{
Integer slot = 1;
for (short data = 0; data <= 15; data++)
{
getItems().put(slot, new ItemBuilder(Material.INK_SACK).setData(data).setTitle(C.cGray).build());
if ((slot + 1) == 8)
{
slot = 10;
}
else if ((slot + 1) == 17)
{
slot = 21;
}
else if ((slot + 1) == 22)
{
slot = 23;
}
else
{
slot++;
}
}
refresh();
}
@SuppressWarnings("deprecation")
@Override
public void onClick(Integer slot, ClickType type)
{
if (getItems().get(slot).getType() == Material.INK_SACK)
{
DyeColor color = DyeColor.getByDyeData(getItems().get(slot).getData().getData());
BannerPattern pattern = _banner.getPatterns().get(_bannerPos);
pattern.setColor(color);
ClansManager.getInstance().runSyncLater(() ->
{
getViewer().closeInventory();
}, 1L);
ClansManager.getInstance().runSyncLater(() ->
{
new PatternTypeSelectionGUI(getViewer(), _banner, _bannerPos, color);
}, 2L);
}
}
}

View File

@ -0,0 +1,87 @@
package mineplex.game.clans.clans.banners.gui.creation;
import java.util.LinkedList;
import mineplex.core.common.util.C;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.banners.BannerPattern;
import mineplex.game.clans.clans.banners.ClanBanner;
import mineplex.game.clans.clans.banners.gui.BannerGUI;
import mineplex.game.clans.clans.banners.gui.overview.OverviewGUI;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
/**
* GUI manager for selecting a banner pattern's design
*/
public class PatternTypeSelectionGUI extends BannerGUI
{
private ClanBanner _banner;
private int _bannerPos;
private DyeColor _color;
public PatternTypeSelectionGUI(Player viewer, ClanBanner banner, int bannerPosition, DyeColor patternColor)
{
super(viewer, "Pattern Color", 45);
_banner = banner;
_bannerPos = bannerPosition;
_color = patternColor;
propagate();
open();
}
@Override
public void propagate()
{
for (int i = 0; i < PatternType.values().length; i++)
{
ItemStack item = new ItemStack(Material.BANNER);
BannerMeta im = (BannerMeta) item.getItemMeta();
im.setBaseColor(_banner.getBaseColor());
LinkedList<Pattern> patterns = new LinkedList<>();
for (int patternId = 0; patternId < _bannerPos; patternId++)
{
BannerPattern show = _banner.getPatterns().get(patternId);
if (show.getBukkitPattern() != null)
{
patterns.add(show.getBukkitPattern());
}
}
patterns.add(new Pattern(_color, PatternType.values()[i]));
im.setPatterns(patterns);
im.setDisplayName(C.cGray);
item.setItemMeta(im);
getItems().put(i, item);
}
refresh();
}
@Override
public void onClick(Integer slot, ClickType ctype)
{
if (getItems().get(slot).getType() == Material.BANNER)
{
PatternType type = ((BannerMeta)getItems().get(slot).getItemMeta()).getPatterns().get(Math.min(_bannerPos, ((BannerMeta)getItems().get(slot).getItemMeta()).getPatterns().size() - 1)).getPattern();
BannerPattern pattern = _banner.getPatterns().get(_bannerPos);
pattern.setPatternType(type);
_banner.save();
ClansManager.getInstance().runSyncLater(() ->
{
getViewer().closeInventory();
}, 1L);
ClansManager.getInstance().runSyncLater(() ->
{
new OverviewGUI(getViewer(), _banner);
}, 2L);
}
}
}

View File

@ -0,0 +1,82 @@
package mineplex.game.clans.clans.banners.gui.nonedit;
import java.util.Arrays;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.banners.BannerPacketManager;
import mineplex.game.clans.clans.banners.ClanBanner;
import mineplex.game.clans.clans.banners.gui.BannerGUI;
import mineplex.game.clans.clans.banners.gui.overview.OverviewGUI;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* GUI manager for viewing a banner usage overview
*/
public class NonEditOverviewGUI extends BannerGUI
{
private ClanBanner _banner;
public NonEditOverviewGUI(Player viewer, ClanBanner banner)
{
super(viewer, "Clan Banner", 9);
_banner = banner;
propagate();
open();
}
@Override
public void propagate()
{
ItemStack banner = _banner.getBanner().clone();
ItemMeta im = banner.getItemMeta();
im.setDisplayName(C.cGreen + "Clan Banner");
im.setLore(Arrays.asList(new String[] {F.elem("Left Click") + " to toggle wearing your banner", F.elem("Right Click") + " to place down your banner"}));
banner.setItemMeta(im);
getItems().put(4, banner);
if (_banner.getClan().getMembers().get(getViewer().getUniqueId()).getRole() == ClanRole.LEADER && ClansManager.getInstance().getBannerManager().getBannerUnlockLevel(getViewer()) >= 2)
{
getItems().put(8, new ItemBuilder(Material.ANVIL).setTitle(C.cGold + "Edit Your Banner").build());
}
refresh();
}
@Override
public void onClick(Integer slot, ClickType type)
{
if (slot == 4)
{
if (type == ClickType.LEFT)
{
BannerPacketManager.getInstance().toggleBanner(getViewer(), _banner.getBanner());
UtilPlayer.message(getViewer(), F.main("Clan Banners", "You have toggled your banner!"));
}
else if (type == ClickType.RIGHT)
{
_banner.place(getViewer());
}
}
if (slot == 8)
{
ClansManager.getInstance().runSyncLater(() ->
{
getViewer().closeInventory();
}, 1L);
ClansManager.getInstance().runSyncLater(() ->
{
new OverviewGUI(getViewer(), _banner);
}, 2L);
}
}
}

View File

@ -0,0 +1,124 @@
package mineplex.game.clans.clans.banners.gui.overview;
import java.util.Arrays;
import mineplex.core.common.util.C;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.banners.BannerPattern;
import mineplex.game.clans.clans.banners.ClanBanner;
import mineplex.game.clans.clans.banners.gui.BannerGUI;
import mineplex.game.clans.clans.banners.gui.creation.BaseColorSelectionGUI;
import mineplex.game.clans.clans.banners.gui.creation.PatternColorSelectionGUI;
import mineplex.game.clans.clans.banners.gui.nonedit.NonEditOverviewGUI;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.MaterialData;
/**
* GUI manager for overviewing a banner's design
*/
public class OverviewGUI extends BannerGUI
{
private static final int MAX_BANNER_LAYERS = 12;
private static final int PATTERN_DISPLAY_START_SLOT = 27;
private final ClanBanner _banner;
public OverviewGUI(Player viewer, ClanBanner banner)
{
super(viewer, "Clan Banner", 45);
_banner = banner;
propagate();
open();
}
@Override
@SuppressWarnings("deprecation")
public void propagate()
{
getItems().put(4, _banner.getBanner());
ItemStack color = new MaterialData(Material.INK_SACK, _banner.getBaseColor().getDyeData()).toItemStack(1);
ItemMeta colorMeta = color.getItemMeta();
colorMeta.setDisplayName(C.cGray);
color.setItemMeta(colorMeta);
getItems().put(22, color);
Integer slot = PATTERN_DISPLAY_START_SLOT;
for (int i = 0; i < MAX_BANNER_LAYERS; i++)
{
ItemStack item = new ItemStack(Material.INK_SACK, 1, (short)8);
if (i < _banner.getPatterns().size())
{
BannerPattern pattern = _banner.getPatterns().get(i);
if (pattern.getBukkitPattern() != null)
{
ItemStack representation = new ItemStack(Material.BANNER);
BannerMeta im = (BannerMeta) representation.getItemMeta();
im.setBaseColor(_banner.getBaseColor());
im.setDisplayName(C.cGray);
im.setPatterns(Arrays.asList(pattern.getBukkitPattern()));
representation.setItemMeta(im);
item = representation;
}
}
getItems().put(slot, item);
slot++;
}
refresh();
}
@Override
public void onClick(Integer slot, ClickType type)
{
if (slot == 4)
{
ClansManager.getInstance().runSyncLater(() ->
{
getViewer().closeInventory();
}, 1L);
ClansManager.getInstance().runSyncLater(() ->
{
new NonEditOverviewGUI(getViewer(), _banner);
}, 2L);
}
if (slot == 22)
{
ClansManager.getInstance().runSyncLater(() ->
{
getViewer().closeInventory();
}, 1L);
ClansManager.getInstance().runSyncLater(() ->
{
new BaseColorSelectionGUI(getViewer(), _banner);
}, 2L);
}
if (slot >= PATTERN_DISPLAY_START_SLOT)
{
if (type == ClickType.RIGHT)
{
_banner.getPatterns().get(slot - PATTERN_DISPLAY_START_SLOT).setColor(null);
ClansManager.getInstance().runSyncLater(() ->
{
getItems().clear();
propagate();
refresh();
}, 1L);
}
else
{
ClansManager.getInstance().runSyncLater(() ->
{
getViewer().closeInventory();
}, 1L);
ClansManager.getInstance().runSyncLater(() ->
{
new PatternColorSelectionGUI(getViewer(), _banner, slot - PATTERN_DISPLAY_START_SLOT);
}, 2L);
}
}
}
}

View File

@ -1,40 +1,14 @@
package mineplex.game.clans.clans.commands;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInput;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.ClientClan;
import mineplex.game.clans.items.CustomItem;
import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.items.attributes.weapon.FlamingAttribute;
import mineplex.game.clans.items.attributes.weapon.FrostedAttribute;
import mineplex.game.clans.items.attributes.weapon.SharpAttribute;
import mineplex.game.clans.items.legendaries.LegendaryItem;
import mineplex.game.clans.items.legendaries.WindBlade;
import org.bukkit.entity.Player;
public class ClanManagementCommand extends CommandBase<ClansManager>
{

View File

@ -349,6 +349,12 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (Plugin.getTutorial().inTutorial(caller))
{
UtilPlayer.message(caller, F.main("Clans", "You cannot invite others while in a tutorial."));
return;
}
if (args.length < 2)
{
UtilPlayer.message(caller, F.main("Clans", "You did not input an invitee."));

View File

@ -1,15 +1,14 @@
package mineplex.game.clans.clans.commands;
import mineplex.game.clans.clans.ClansManager;
import mineplex.minecraft.game.classcombat.Skill.Global.Recharge;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ClansManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import org.bukkit.entity.Player;
public class KillCommand extends CommandBase<DamageManager>
{
public KillCommand(DamageManager plugin)
@ -35,9 +34,14 @@ public class KillCommand extends CommandBase<DamageManager>
UtilPlayer.message(caller, F.main("Clans", "Please wait a bit before suiciding"));
return;
}
if (ClansManager.getInstance().getClanUtility().isSafe(caller.getLocation()) || (ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()) != null && ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equalsIgnoreCase("Spawn")))
{
UtilPlayer.message(caller, F.main("Clans", "You cannot use this command whilst in a safezone!"));
return;
}
UtilPlayer.message(caller, F.main("Clans", "You have imploded."));
caller.setHealth(0D);
}
}
}

View File

@ -65,7 +65,6 @@ public class ClanWhoPage extends ClanPageBase
lore.add(C.Reset + C.cYellow + "Formed " + C.cWhite + UtilTime.convertString(System.currentTimeMillis() - _lookupClan.getDateCreated().getTime(), 1, UtilTime.TimeUnit.FIT) + " ago on " + UtilTime.when(_lookupClan.getDateCreated().getTime()));
lore.add(C.Reset + C.cYellow + "Members " + C.cWhite + _lookupClan.getOnlinePlayerCount() + "/" + _lookupClan.getMembers().size());
lore.add(C.Reset + C.cYellow + "Territory " + C.cWhite + _lookupClan.getClaims() + "/" + _lookupClan.getClaimsMax());
lore.add(C.Reset + C.cYellow + "TNT Protection " + C.cWhite + _lookupClan.getProtected());
if (clanInfo != null)
{
lore.add(C.Reset + C.cYellow + "Your War Points " + C.cWhite + clanInfo.getFormattedWarPoints(_lookupClan));

View File

@ -17,7 +17,7 @@ public class GearLoot implements ILoot
@Override
public void dropLoot(Location location)
{
_gearManager.spawnItem(location);
_gearManager.spawnItem(location.clone().add(0, 3, 0));
}
@Override

View File

@ -1,8 +1,11 @@
package mineplex.game.clans.clans.loot;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.game.clans.items.economy.GoldToken;
@ -23,7 +26,8 @@ public class GoldTokenLoot implements ILoot
int gold = _minGold + UtilMath.r(_maxGold - _minGold);
GoldToken token = new GoldToken(gold);
location.getWorld().dropItemNaturally(location, token.toItemStack());
UtilFirework.playFirework(location.clone().add(0, 3, 0), Type.BALL, Color.YELLOW, true, false);
location.getWorld().dropItemNaturally(location.clone().add(0, 3, 0), token.toItemStack());
}
@Override

View File

@ -1,118 +1,304 @@
package mineplex.game.clans.clans.nether;
import java.io.File;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.generator.VoidGenerator;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.ClansCommandExecutedEvent;
import mineplex.game.clans.clans.nether.command.ForceTeleportCommand;
import mineplex.game.clans.clans.nether.command.PortalCommand;
import mineplex.game.clans.clans.nether.data.ClaimData;
import mineplex.game.clans.clans.nether.miniboss.NetherMinibossManager;
import mineplex.game.clans.spawn.Spawn;
import mineplex.minecraft.game.core.boss.EventCreatureDeathEvent;
import mineplex.minecraft.game.core.boss.broodmother.SpiderCreature;
import mineplex.minecraft.game.core.boss.ironwizard.GolemCreature;
import mineplex.minecraft.game.core.boss.skeletonking.SkeletonCreature;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.WorldCreator;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilCollections;
import mineplex.core.common.util.UtilFile;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.core.repository.ClanTerritory;
/**
* Manager for all nether features
*/
public class NetherManager extends MiniPlugin
{
private ClansManager _clansManager;
private static final long PORTAL_OPEN_DURATION = UtilTime.convert(10, TimeUnit.MINUTES, TimeUnit.MILLISECONDS);
private static final String CLAIM_WAND_NAME = C.cRedB + "Portal Claim Wand";
private static final String[] CLAIM_WAND_LORE = new String[] {C.cYellow + "Left Click to select the Portal's first corner", C.cYellow + "Right Click to select the Portal's second corner"};
private static final ItemStack CLAIM_WAND = new ItemBuilder(Material.WOOD_AXE).setTitle(CLAIM_WAND_NAME).setLore(CLAIM_WAND_LORE).build();
private PortalRepository _repo;
private NetherMinibossManager _miniboss;
private World _netherWorld;
private List<NetherPortal> _portals = Lists.newArrayList();
private List<NetherPortal> _returnPortals = Lists.newArrayList();
public HashMap<Player, Long> InNether = new HashMap<>();
public HashMap<Player, Location> OverworldOrigins = new HashMap<>();
public HashMap<Player, ClaimData> Claiming = new HashMap<>();
private List<Portal> _portals = Lists.newArrayList();
private File _portalCfg;
public NetherManager(ClansManager clansManager)
public NetherManager(ClansManager manager)
{
super("Nether Manager", clansManager.getPlugin());
_clansManager = clansManager;
_portalCfg = new File(UtilServer.getServer().getWorlds().get(0).getWorldFolder().getPath() + File.separator + ".." + File.separator + "nether.cfg");
super("Nether", manager.getPlugin());
begin();
_miniboss = new NetherMinibossManager(this);
addCommand(new PortalCommand(this));
addCommand(new ForceTeleportCommand(this));
}
public void begin()
private void begin()
{
_netherWorld = Bukkit.getWorld("world_nether");
if (Bukkit.getWorld("nether") == null)
{
WorldCreator creator = new WorldCreator("nether");
creator.generator(new VoidGenerator());
Bukkit.createWorld(creator);
}
_netherWorld = Bukkit.getWorld("nether");
_netherWorld.setSpawnLocation(43, 135, 113);
WorldBorder worldBorder = _netherWorld.getWorldBorder();
worldBorder.setCenter(0, 0);
worldBorder.setSize(200 * 2);
worldBorder.setSize(800 * 2);
parsePortals();
_repo = new PortalRepository(getPlugin(), this);
loadPortals();
}
private void parsePortals()
private void loadPortals()
{
String data = UtilFile.read(_portalCfg);
if (data.length() < 5)
_repo.loadPortals();
}
@Override
public void disable()
{
closePortals();
for (Player player : InNether.keySet())
{
return;
player.teleport(Spawn.getNorthSpawn());
}
InNether.clear();
}
/**
* Get the manager for nether miniboss
* @return The loaded Nether Miniboss manager
*/
public NetherMinibossManager getMinibossManager()
{
return _miniboss;
}
/**
* Gets the Nether world
* @return The Nether world
*/
public World getNetherWorld()
{
return _netherWorld;
}
/**
* Checks if a player is in the nether
* @param player The player to check
* @return Whether the player is in the nether
*/
public boolean isInNether(Player player)
{
return player.getWorld().equals(_netherWorld);
}
/**
* Gets the place a player will exit the nether
* @param player The player to check
* @return The place the player will exit the nether
*/
public Location getReturnLocation(Player player)
{
return OverworldOrigins.getOrDefault(player, Spawn.getNorthSpawn());
}
/**
* Fetches the nether portal with the given id
* @param id The id of the portal
* @return The nether portal with the given id
*/
public NetherPortal getPortal(int id)
{
for (NetherPortal portal : _portals)
{
if (portal.getId() == id)
{
return portal;
}
}
UtilCollections.forEach(data.split("\n"), string -> string.trim(), sPortal -> {
String[] destinations = sPortal.split(">>");
Location from = UtilWorld.strToLoc(destinations[0]);
Location to = UtilWorld.strToLoc(destinations[1].split(":")[0]);
Portal portal = Portal.create(from, to, UtilWorld.strToLoc(to.getWorld().getName() + "," + destinations[1].split(":")[1]));
if (portal == null)
return null;
}
/**
* Loads a nether portal into the manager
* @param portal The portal to load
*/
public void addPortal(NetherPortal portal)
{
_portals.add(portal);
if (portal.isReturnPortal())
{
_returnPortals.add(portal);
}
_portals.sort(new Comparator<NetherPortal>()
{
public int compare(NetherPortal o1, NetherPortal o2)
{
log("FAILED TO LOAD PORTAL [" + sPortal + "]");
}
else
{
_portals.add(portal);
if (o1.getId() > o2.getId())
{
return 1;
}
return -1;
}
});
}
@EventHandler
public void cmd(PlayerCommandPreprocessEvent event)
/**
* Deletes a nether portal and removes it from the database
* @param portal The portal to remove
*/
public void deletePortal(NetherPortal portal)
{
if (!_clansManager.getClientManager().hasRank(event.getPlayer(), Rank.JNR_DEV))
portal.close();
_portals.remove(portal);
_returnPortals.remove(portal);
_repo.deletePortal(portal.getId());
}
/**
* Spawns a nether portal for a given duration
* @param duration The duration to maintain the portal for
*/
public void spawnPortal(long duration)
{
if (_portals.isEmpty() || _returnPortals.isEmpty())
{
return;
}
if (event.getMessage().startsWith("/nether"))
List<NetherPortal> available = Lists.newArrayList();
available.addAll(_portals);
for (NetherPortal remove : _returnPortals)
{
event.getPlayer().teleport(new Location(_netherWorld, 0, 90, 0));
event.setCancelled(true);
available.remove(remove);
}
if (available.isEmpty())
{
return;
}
NetherPortal portal = available.get(UtilMath.r(available.size()));
portal.open(duration);
for (NetherPortal returnPortal : _returnPortals)
{
returnPortal.open(-1);
}
UtilTextMiddle.display(F.clansNether("Nether Portal"), "Has opened at " + F.elem(UtilWorld.locToStrClean(portal.getLocation())));
Bukkit.broadcastMessage(F.main(getName(), "A " + F.clansNether("Nether Portal") + " has opened at " + F.elem(UtilWorld.locToStrClean(portal.getLocation())) + " for " + F.elem(UtilTime.MakeStr(duration)) + "!"));
}
/**
* Spawns a portal for the default remain duration
*/
public void spawnPortal()
{
spawnPortal(PORTAL_OPEN_DURATION);
}
/**
* Creates a portal with the player's stored corners
* @param creator The creator of the portal
* @param returnPortal Whether the portal is a return portal
*/
public void createPortal(Player creator, boolean returnPortal)
{
if (Claiming.getOrDefault(creator, new ClaimData()).getTotalSelected() < 2)
{
UtilPlayer.message(creator, F.main(getName(), "You do not have a top and bottom corner selected!"));
return;
}
ClaimData data = Claiming.remove(creator);
_repo.addPortal(UtilWorld.locToStr(data.getFirstCorner().getLocation()), UtilWorld.locToStr(data.getSecondCorner().getLocation()), returnPortal);
UtilPlayer.message(creator, F.main(getName(), "Portal successfully created!"));
}
/**
* Closes all portals and clears away their blocks
*/
public void closePortals()
{
for (NetherPortal portal : _portals)
{
portal.close();
}
}
/**
* Displays a list of all portals to a player
* @param player The player to display the list to
*/
public void showPortalList(Player player)
{
UtilPlayer.message(player, F.main(getName(), "Portal List:"));
for (NetherPortal portal : _portals)
{
UtilPlayer.message(player, C.cBlue + "- " + F.elem("Portal " + portal.getId() + ": " + C.cGray + UtilWorld.locToStrClean(portal.getLocation()).replace("(", "").replace(")", "")));
}
}
/**
* Gives a player a portal claim wand
* @param player The player to give the wand to
*/
public void giveWand(Player player)
{
player.getInventory().addItem(CLAIM_WAND.clone());
UtilPlayer.message(player, F.main(getName(), "You have been given a Portal Claim Wand!"));
}
@EventHandler
@ -120,7 +306,6 @@ public class NetherManager extends MiniPlugin
{
Block block = event.getBlock();
Player player = event.getPlayer();
ItemStack item = player.getItemInHand();
if (player.getGameMode() == GameMode.CREATIVE)
{
@ -132,28 +317,8 @@ public class NetherManager extends MiniPlugin
return;
}
_portals
.stream()
.filter(portal -> UtilAlg.getAverageBlockLocation(portal.getToBlocks()).distance(block.getLocation()) < 15)
.limit(1)
.forEach(portal -> {
UtilPlayer.message(player, F.main("Clans", "You are not allowed to break this block."));
event.setCancelled(true);
});
if (!item.getType().equals(Material.GOLD_PICKAXE))
{
UtilPlayer.message(player, F.main("Clans", "You can only break blocks in the Nether with a " + F.elem("Golden Pickaxe") + "."));
event.setCancelled(true);
return;
}
if (block.getType().equals(Material.OBSIDIAN) || block.getType().equals(Material.PORTAL))
{
UtilPlayer.message(player, F.main("Clans", "You are not allowed to break this block."));
event.setCancelled(true);
return;
}
event.setCancelled(true);
UtilPlayer.message(player, F.main(getName(), "You cannot build in " + F.clansNether("The Nether") + "!"));
}
@EventHandler
@ -161,7 +326,6 @@ public class NetherManager extends MiniPlugin
{
Block block = event.getBlock();
Player player = event.getPlayer();
ItemStack item = player.getItemInHand();
if (player.getGameMode() == GameMode.CREATIVE)
{
@ -173,28 +337,32 @@ public class NetherManager extends MiniPlugin
return;
}
if (!UtilItem.isFromNether(item))
event.setCancelled(true);
UtilPlayer.message(player, F.main(getName(), "You cannot build in " + F.clansNether("The Nether") + "!"));
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPortal(PlayerPortalEvent event)
{
if (event.getTo() == null || event.getTo().getWorld().equals(_netherWorld))
{
UtilPlayer.message(player, F.main("Clans", "You can only place blocks here that come from " + F.clansNether("The Nether") + "."));
event.setCancelled(true);
return;
}
_portals
.stream()
.filter(portal -> UtilAlg.getAverageBlockLocation(portal.getToBlocks()).distance(block.getLocation()) < 15)
.limit(1)
.forEach(portal -> {
UtilPlayer.message(player, F.main("Clans", "You are not allowed to place blocks here."));
event.setCancelled(true);
});
if (block.getType().equals(Material.OBSIDIAN) || block.getType().equals(Material.PORTAL))
event.setCancelled(true);
runSyncLater(() ->
{
UtilPlayer.message(player, F.main("Clans", "You are not allowed to place blocks here."));
event.setCancelled(true);
return;
}
InNether.remove(event.getPlayer());
event.getPlayer().teleport(getReturnLocation(event.getPlayer()));
OverworldOrigins.remove(event.getPlayer());
event.getPlayer().removePotionEffect(PotionEffectType.NIGHT_VISION);
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You have escaped " + F.clansNether("The Nether") + "!"));
}, 1);
}
@EventHandler
public void onPortal(EntityPortalEvent event)
{
event.setCancelled(true);
}
@EventHandler
@ -202,76 +370,132 @@ public class NetherManager extends MiniPlugin
{
if (event.getType() == UpdateType.FAST)
{
List<Player> netherKeys = Lists.newArrayList();
netherKeys.addAll(InNether.keySet());
for (Player player : netherKeys)
{
if (System.currentTimeMillis() >= InNether.get(player))
{
InNether.remove(player);
if (isInNether(player))
{
player.teleport(getReturnLocation(player));
OverworldOrigins.remove(player);
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
UtilPlayer.message(player, F.main(getName(), "You have been forced to escape " + F.clansNether("The Nether") + " to survive its demonic poisons!"));
}
}
else
{
if (!player.hasPotionEffect(PotionEffectType.NIGHT_VISION))
{
int ticks = (int)((InNether.get(player) - System.currentTimeMillis()) / 1000) * 20;
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, ticks, 0));
}
}
}
UtilServer.getPlayersCollection()
.stream()
.filter(player -> player.getWorld().equals(_netherWorld))
.forEach(player -> {
player.setCompassTarget(new Location(_netherWorld, -200.d + UtilMath.r(400), player.getLocation().getY(), -200.d + UtilMath.r(400)));
_clansManager.getItemMapManager().removeMap(player);
});
}
if (event.getType() == UpdateType.SLOW)
{
_portals.forEach(portal -> {
portal.getFromObsidianBlocks().forEach(block -> UtilBlock.setSilent(block, Material.OBSIDIAN));
portal.getFromPortalBlocks().forEach(block -> UtilBlock.setSilent(block, Material.PORTAL));
portal.getToObsidianBlocks().forEach(block -> UtilBlock.setSilent(block, Material.OBSIDIAN));
portal.getToPortalBlocks().forEach(block -> UtilBlock.setSilent(block, Material.PORTAL));
});
.stream()
.filter(player -> isInNether(player))
.forEach(player ->
{
ClansManager.getInstance().getItemMapManager().removeMap(player);
});
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPortal(PlayerPortalEvent event)
@EventHandler(priority = EventPriority.LOWEST)
public void onQuit(PlayerQuitEvent event)
{
Player player = event.getPlayer();
Location location = player.getLocation();
ClanTerritory territory = _clansManager.getClanUtility().getClaim(location);
if (event.getTo().getWorld().equals(_netherWorld))
if (isInNether(event.getPlayer()))
{
if (territory != null && territory.Owner.equals("Borderlands"))
InNether.remove(event.getPlayer());
event.getPlayer().teleport(getReturnLocation(event.getPlayer()));
OverworldOrigins.remove(event.getPlayer());
event.getPlayer().removePotionEffect(PotionEffectType.NIGHT_VISION);
}
Claiming.remove(event.getPlayer());
}
@EventHandler(priority = EventPriority.LOWEST)
public void onDie(PlayerDeathEvent event)
{
InNether.remove(event.getEntity());
OverworldOrigins.remove(event.getEntity());
Claiming.remove(event.getEntity());
}
@EventHandler
public void onTpHome(ClansCommandExecutedEvent event)
{
if (event.getCommand().equalsIgnoreCase("tphome"))
{
if (isInNether(event.getPlayer()))
{
_portals
.stream()
.filter(portal ->
portal.getFromPortalBlocks()
.stream()
.filter(block -> player.getLocation().distance(block.getLocation()) <= 2)
.iterator().hasNext()
).limit(1)
.forEach(portal -> {
event.setTo(portal.getToOut());
_clansManager.ClanTips.displayTip(TipType.ENTER_NETHER, player);
});
event.setCancelled(true);
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You cannot teleport to your Clan home while in " + F.clansNether("The Nether") + "!"));
}
}
else
}
@EventHandler
public void onDropWand(PlayerDropItemEvent event)
{
ItemStack item = event.getItemDrop().getItemStack();
if (item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equalsIgnoreCase(CLAIM_WAND_NAME))
{
_portals
.stream()
.filter(portal ->
portal.getToPortalBlocks()
.stream()
.filter(block -> player.getLocation().distance(block.getLocation()) <= 2)
.iterator().hasNext()
).limit(1)
.forEach(portal -> {
event.setTo(UtilAlg.getAverageBlockLocation(portal.getFromPortalBlocks()));
});
runSyncLater(() ->
{
event.getItemDrop().remove();
}, 1L);
}
}
public World getNetherWorld()
@EventHandler
public void onUseWand(PlayerInteractEvent event)
{
return _netherWorld;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK)
{
return;
}
if (!event.hasBlock() || !event.hasItem())
{
return;
}
if (!ClansManager.getInstance().getClientManager().hasRank(event.getPlayer(), Rank.ADMIN))
{
return;
}
ItemStack item = event.getItem();
if (item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equalsIgnoreCase(CLAIM_WAND_NAME))
{
Block block = event.getClickedBlock();
if (!Claiming.containsKey(event.getPlayer()))
{
Claiming.put(event.getPlayer(), new ClaimData());
}
ClaimData data = Claiming.get(event.getPlayer());
if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
{
data.setSecondCorner(block);
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You have selected the Portal's second corner!"));
}
else
{
data.setFirstCorner(block);
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You have selected the Portal's first corner!"));
}
event.setCancelled(true);
}
}
public boolean isInNether(Player player)
@EventHandler
public void onBossDeath(EventCreatureDeathEvent event)
{
return player.getWorld().equals(_netherWorld);
if (event.getCreature() instanceof GolemCreature || event.getCreature() instanceof SkeletonCreature || event.getCreature() instanceof SpiderCreature)
{
spawnPortal();
}
}
}
}

View File

@ -0,0 +1,289 @@
package mineplex.game.clans.clans.nether;
import java.util.List;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.potion.PotionEffectType;
import com.google.common.collect.Lists;
/**
* Data and listener class for individual nether portals
*/
public class NetherPortal implements Listener
{
private static final int SECONDS_UNTIL_PORTAL = 5;
private int _id;
private List<Block> _frame = Lists.newArrayList();
private List<Block> _portal = Lists.newArrayList();
private Location _loc;
private Location[] _corners;
private boolean _returnPortal;
private byte _portalFacing;
public boolean Open = false;
public long Expire = -1;
public NetherPortal(int id, Location firstCorner, Location secondCorner, boolean returnPortal)
{
_id = id;
int maxX = Math.max(firstCorner.getBlockX(), secondCorner.getBlockX());
int minX = Math.min(firstCorner.getBlockX(), secondCorner.getBlockX());
int maxY = Math.max(firstCorner.getBlockY(), secondCorner.getBlockY());
int minY = Math.min(firstCorner.getBlockY(), secondCorner.getBlockY());
int maxZ = Math.max(firstCorner.getBlockZ(), secondCorner.getBlockZ());
int minZ = Math.min(firstCorner.getBlockZ(), secondCorner.getBlockZ());
for (int x = minX; x <= maxX; x++)
{
for (int y = minY; y <= maxY; y++)
{
for (int z = minZ; z <= maxZ; z++)
{
if (minX == maxX)
{
if ((y != minY && y != maxY) && (z != minZ && z != maxZ))
{
_portal.add(firstCorner.getWorld().getBlockAt(x, y, z));
}
else
{
_frame.add(firstCorner.getWorld().getBlockAt(x, y, z));
}
}
else
{
if ((x != minX && x != maxX) && (y != minY && y != maxY))
{
_portal.add(firstCorner.getWorld().getBlockAt(x, y, z));
}
else
{
_frame.add(firstCorner.getWorld().getBlockAt(x, y, z));
}
}
}
}
}
_loc = new Location(firstCorner.getWorld(), minX + ((maxX - minX) / 2), maxY, minZ + ((maxZ - minZ) / 2));
_corners = new Location[] {firstCorner, secondCorner};
_returnPortal = returnPortal;
if (maxX == minX)
{
_portalFacing = (byte)2;
}
else
{
_portalFacing = (byte)0;
}
}
private boolean isInPortal(Block block)
{
return _frame.contains(block) || _portal.contains(block);
}
/**
* Gets the id of this portal
* @return This portal's id
*/
public int getId()
{
return _id;
}
/**
* Gets the center location of this portal
* @return The center location of this portal
*/
public Location getLocation()
{
return _loc;
}
/**
* Gets the corners of this portal
* @return An array of the corners of this portal
*/
public Location[] getCorners()
{
return _corners;
}
/**
* Checks if this portal is a return portal
* @return Whether this portal is a return portal
*/
public boolean isReturnPortal()
{
return _returnPortal;
}
/**
* Opens this portal for a given duration
* @param duration The duration to hold the portal open for
*/
@SuppressWarnings("deprecation")
public void open(long duration)
{
if (Open)
{
if (Expire != -1)
{
Expire = Expire + duration;
}
}
else
{
if (!_returnPortal)
{
Expire = System.currentTimeMillis() + duration;
}
Open = true;
Bukkit.getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
for (Block block : _frame)
{
block.setType(Material.OBSIDIAN);
}
for (Block block : _portal)
{
block.setType(Material.PORTAL);
block.setData(_portalFacing);
}
}
}
/**
* Closes this portal and clears away its blocks
*/
public void close()
{
Open = false;
Expire = -1;
for (Block block : _portal)
{
block.setType(Material.AIR);
}
for (Block block : _frame)
{
block.setType(Material.AIR);
}
HandlerList.unregisterAll(this);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBreak(BlockDamageEvent event)
{
if (isInPortal(event.getBlock()))
{
event.setInstaBreak(false);
event.setCancelled(true);
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You cannot destroy a " + F.clansNether("Nether Portal")));
}
}
@EventHandler(priority = EventPriority.LOW)
public void playerPortalEvent(PlayerPortalEvent event)
{
if (isInPortal(event.getFrom().getBlock()))
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOW)
public void entityPortalEvent(EntityPortalEvent event)
{
if (isInPortal(event.getFrom().getBlock()))
{
event.setCancelled(true);
}
}
@EventHandler
public void onEnterPortal(EntityPortalEnterEvent event)
{
if (event.getEntity() instanceof Player)
{
if (isInPortal(event.getLocation().getBlock()))
{
Bukkit.getScheduler().runTaskLater(ClansManager.getInstance().getPlugin(), () ->
{
if (isInPortal(event.getEntity().getLocation().getBlock()))
{
if (isReturnPortal())
{
ClansManager.getInstance().getNetherManager().InNether.remove((Player)event.getEntity());
event.getEntity().teleport(ClansManager.getInstance().getNetherManager().getReturnLocation((Player)event.getEntity()));
ClansManager.getInstance().getNetherManager().OverworldOrigins.remove((Player)event.getEntity());
((Player)event.getEntity()).removePotionEffect(PotionEffectType.NIGHT_VISION);
UtilPlayer.message(event.getEntity(), F.main(ClansManager.getInstance().getNetherManager().getName(), "You have escaped " + F.clansNether("The Nether") + "!"));
}
else
{
ClansManager.getInstance().getNetherManager().InNether.put((Player)event.getEntity(), Expire);
Location from = event.getEntity().getLocation();
ClansManager.getInstance().getNetherManager().OverworldOrigins.put((Player)event.getEntity(), from);
event.getEntity().teleport(ClansManager.getInstance().getNetherManager().getNetherWorld().getSpawnLocation());
ClansManager.getInstance().ClanTips.displayTip(TipType.ENTER_NETHER, (Player)event.getEntity());
}
}
}, SECONDS_UNTIL_PORTAL * 20);
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPhysics(BlockPhysicsEvent event)
{
if (isInPortal(event.getBlock()))
{
event.setCancelled(true);
}
}
@EventHandler
public void handleExpiration(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
if (Open && Expire != -1 && System.currentTimeMillis() >= Expire)
{
close();
}
}
@EventHandler
public void onUnload(ChunkUnloadEvent event)
{
if (event.getChunk().getX() == _loc.getChunk().getX() && event.getChunk().getZ() == _loc.getChunk().getZ())
{
event.setCancelled(true);
}
}
}

View File

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

View File

@ -0,0 +1,109 @@
package mineplex.game.clans.clans.nether;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.column.ColumnBoolean;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Database repository class for nether portals
*/
public class PortalRepository extends MinecraftRepository
{
private static final String CREATE = "CREATE TABLE IF NOT EXISTS clansNetherPortals (id INT NOT NULL AUTO_INCREMENT,"
+ "cornerOne VARCHAR(30),"
+ "cornerTwo VARCHAR(30),"
+ "returnPortal BOOL,"
+ "PRIMARY KEY (id));";
private static final String GET_PORTALS = "SELECT * FROM clansNetherPortals;";
private static final String INSERT_PORTAL = "INSERT INTO clansNetherPortals (cornerOne, cornerTwo, returnPortal) VALUES (?, ?, ?);";
private static final String DELETE_PORTAL = "DELETE FROM clansNetherPortals WHERE id=?;";
private NetherManager _nether;
public PortalRepository(JavaPlugin plugin, NetherManager portalManager)
{
super(plugin, DBPool.getAccount());
_nether = portalManager;
}
/**
* Loads all stored portals
*/
public void loadPortals()
{
_nether.runAsync(() ->
{
executeQuery(GET_PORTALS, resultSet ->
{
while (resultSet.next())
{
final int id = resultSet.getInt("id");
final String cornerOne = resultSet.getString("cornerOne");
final String cornerTwo = resultSet.getString("cornerTwo");
final boolean returnPortal = resultSet.getBoolean("returnPortal");
_nether.runSync(() ->
{
NetherPortal portal = new NetherPortal(id, UtilWorld.strToLoc(cornerOne), UtilWorld.strToLoc(cornerTwo), returnPortal);
_nether.addPortal(portal);
});
}
});
});
}
/**
* Adds a portal into the database and loaded portals
* @param cornerOne The serialized first corner of the portal
* @param cornerTwo The serialized second corner of the portal
* @param returnPortal Whether the portal is a return portal
*/
public void addPortal(final String cornerOne, final String cornerTwo, final boolean returnPortal)
{
_nether.runAsync(() ->
{
executeInsert(INSERT_PORTAL, resultSet ->
{
while (resultSet.next())
{
final int id = resultSet.getInt(1);
_nether.runSync(() ->
{
NetherPortal portal = new NetherPortal(id, UtilWorld.strToLoc(cornerOne), UtilWorld.strToLoc(cornerTwo), returnPortal);
_nether.addPortal(portal);
});
}
}, new ColumnVarChar("cornerOne", 30, cornerOne), new ColumnVarChar("cornerTwo", 30, cornerTwo), new ColumnBoolean("returnPortal", returnPortal));
});
}
/**
* Deletes the portal with the given id from the database
* @param id The id of the portal to delete
*/
public void deletePortal(final int id)
{
_nether.runAsync(() ->
{
executeUpdate(DELETE_PORTAL, new ColumnInt("id", id));
});
}
@Override
protected void initialize()
{
executeUpdate(CREATE);
}
@Override
protected void update()
{
}
}

View File

@ -0,0 +1,27 @@
package mineplex.game.clans.clans.nether.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.nether.NetherManager;
/**
* Command to close all nether portals
*/
public class CloseCommand extends CommandBase<NetherManager>
{
public CloseCommand(NetherManager plugin)
{
super(plugin, Rank.ADMIN, "close");
}
@Override
public void Execute(Player caller, String[] args)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Closing all " + F.clansNether("Nether Portals") + "!"));
Plugin.closePortals();
}
}

View File

@ -0,0 +1,39 @@
package mineplex.game.clans.clans.nether.command;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.nether.NetherManager;
import org.bukkit.entity.Player;
/**
* Command to create a nether portal
*/
public class CreateCommand extends CommandBase<NetherManager>
{
public CreateCommand(NetherManager plugin)
{
super(plugin, Rank.ADMIN, "create");
}
@Override
public void Execute(Player caller, String[] args)
{
Boolean returnPortal = null;
try
{
returnPortal = Boolean.parseBoolean(args[0]);
}
catch (Exception e) {}
if (returnPortal == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Usage: " + F.elem("/portal " + _aliasUsed + " <ReturnPortal>")));
return;
}
Plugin.createPortal(caller, returnPortal);
}
}

View File

@ -0,0 +1,40 @@
package mineplex.game.clans.clans.nether.command;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.nether.NetherManager;
import mineplex.game.clans.clans.nether.NetherPortal;
import org.bukkit.entity.Player;
/**
* Command to delete a nether portal
*/
public class DeleteCommand extends CommandBase<NetherManager>
{
public DeleteCommand(NetherManager plugin)
{
super(plugin, Rank.ADMIN, "delete", "remove");
}
@Override
public void Execute(Player caller, String[] args)
{
Integer id = null;
try
{
id = Integer.parseInt(args[0]);
}
catch (Exception e) {}
if (id == null || Plugin.getPortal(id) == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Usage: " + F.elem("/portal " + _aliasUsed + " <ID>")));
return;
}
NetherPortal portal = Plugin.getPortal(id);
UtilPlayer.message(caller, F.main(Plugin.getName(), "Deleting the " + F.clansNether("Nether Portal") + " with ID " + id + "!"));
Plugin.deletePortal(portal);
}
}

View File

@ -0,0 +1,67 @@
package mineplex.game.clans.clans.nether.command;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.nether.NetherManager;
import mineplex.game.clans.spawn.Spawn;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
/**
* Command to artificially portal
*/
public class ForceTeleportCommand extends CommandBase<NetherManager>
{
public ForceTeleportCommand(NetherManager plugin)
{
super(plugin, Rank.ADMIN, "forcePortal");
}
@Override
public void Execute(Player caller, String[] args)
{
boolean natural = false;
if (args.length > 0 && (args[0].equalsIgnoreCase("true") || args[0].equalsIgnoreCase("false")))
{
natural = Boolean.parseBoolean(args[0]);
}
if (Plugin.isInNether(caller))
{
if (natural)
{
Plugin.InNether.remove(caller);
caller.teleport(Plugin.getReturnLocation(caller));
Plugin.OverworldOrigins.remove(caller);
caller.removePotionEffect(PotionEffectType.NIGHT_VISION);
UtilPlayer.message(caller, F.main(ClansManager.getInstance().getNetherManager().getName(), "You have escaped " + F.clansNether("The Nether") + "!"));
}
else
{
caller.teleport(Spawn.getNorthSpawn());
}
}
else
{
if (natural)
{
Plugin.InNether.put(caller, System.currentTimeMillis() + UtilTime.convert(10, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
Plugin.OverworldOrigins.put(caller, caller.getLocation());
caller.teleport(Plugin.getNetherWorld().getSpawnLocation());
ClansManager.getInstance().ClanTips.displayTip(TipType.ENTER_NETHER, caller);
}
else
{
caller.teleport(Plugin.getNetherWorld().getSpawnLocation());
}
}
}
}

View File

@ -0,0 +1,24 @@
package mineplex.game.clans.clans.nether.command;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.game.clans.clans.nether.NetherManager;
import org.bukkit.entity.Player;
/**
* Command to list all nether portals
*/
public class ListCommand extends CommandBase<NetherManager>
{
public ListCommand(NetherManager plugin)
{
super(plugin, Rank.ADMIN, "list");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.showPortalList(caller);
}
}

View File

@ -0,0 +1,37 @@
package mineplex.game.clans.clans.nether.command;
import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.nether.NetherManager;
import org.bukkit.entity.Player;
/**
* Base portal command
*/
public class PortalCommand extends MultiCommandBase<NetherManager>
{
public PortalCommand(NetherManager plugin)
{
super(plugin, Rank.ADMIN, "netherportal", "portal");
AddCommand(new CreateCommand(plugin));
AddCommand(new DeleteCommand(plugin));
AddCommand(new ListCommand(plugin));
AddCommand(new SpawnCommand(plugin));
AddCommand(new CloseCommand(plugin));
AddCommand(new WandCommand(plugin));
}
@Override
protected void Help(Player caller, String[] args)
{
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " spawn", "Forces a Nether Portal to spawn", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " close", "Closes all Nether Portals", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " list", "Lists all loaded Nether Portals", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " wand", "Gives you a Nether Portal claim wand", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " create", "Creates a Nether Portal with the corners you have selected", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " delete", "Deletes a loaded Nether Portal", Rank.ADMIN));
}
}

View File

@ -0,0 +1,27 @@
package mineplex.game.clans.clans.nether.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.nether.NetherManager;
/**
* Command to open a nether portal
*/
public class SpawnCommand extends CommandBase<NetherManager>
{
public SpawnCommand(NetherManager plugin)
{
super(plugin, Rank.ADMIN, "spawn");
}
@Override
public void Execute(Player caller, String[] args)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Spawning a " + F.clansNether("Nether Portal" + "!")));
Plugin.spawnPortal();
}
}

View File

@ -0,0 +1,24 @@
package mineplex.game.clans.clans.nether.command;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.game.clans.clans.nether.NetherManager;
import org.bukkit.entity.Player;
/**
* Command to give yourself a portal creation wand
*/
public class WandCommand extends CommandBase<NetherManager>
{
public WandCommand(NetherManager plugin)
{
super(plugin, Rank.ADMIN, "wand");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.giveWand(caller);
}
}

View File

@ -0,0 +1,66 @@
package mineplex.game.clans.clans.nether.data;
import org.bukkit.block.Block;
/**
* Data class to hold specified player portal corners
*/
public class ClaimData
{
private Block _first, _second;
/**
* Fetches the first selected corner
* @return The first selected corner
*/
public Block getFirstCorner()
{
return _first;
}
/**
* Fetches the second selected corner
* @return The second selected corner
*/
public Block getSecondCorner()
{
return _second;
}
/**
* Fetches the total count of selected corners
* @return The number of selected corners
*/
public int getTotalSelected()
{
int total = 2;
if (_first == null)
{
total--;
}
if (_second == null)
{
total--;
}
return total;
}
/**
* Sets the first selected corner
* @param block The block to set the corner to
*/
public void setFirstCorner(Block block)
{
_first = block;
}
/**
* Sets the first selected corner
* @param block The block to set the corner to
*/
public void setSecondCorner(Block block)
{
_second = block;
}
}

View File

@ -0,0 +1,89 @@
package mineplex.game.clans.clans.nether.miniboss;
import java.util.HashMap;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.game.clans.clans.ClansManager;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.LargeFireball;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
/**
* Manager class for managing boss fireballs
*/
public class MinibossFireball implements Listener
{
private static final double FIREBALL_EXPLOSION_RANGE = 5;
private static final float SOUND_VOLUME = 1f;
private static final float SOUND_PITCH = 0.8f;
private static final double STRENGTH_MULTIPLIER = 1.6;
private static final double VERT_MULTIPLIER = 0.8;
public MinibossFireball()
{
Bukkit.getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
}
@EventHandler
public void onHit(ProjectileHitEvent event)
{
Projectile proj = event.getEntity();
if (!(proj instanceof LargeFireball))
{
return;
}
if (!proj.hasMetadata("MINIBOSS_FIREBALL"))
{
return;
}
HashMap<LivingEntity, Double> hitMap = UtilEnt.getInRadius(proj.getLocation(), FIREBALL_EXPLOSION_RANGE);
for (LivingEntity cur : hitMap.keySet())
{
double range = hitMap.get(cur);
ClansManager.getInstance().getCondition().Factory().Ignite("Fireball", cur, ((LivingEntity)proj.getMetadata("MINIBOSS_FIREBALL").get(0).value()), 7 * range, false, false);
ClansManager.getInstance().getCondition().Factory().Falling("Fireball", cur, ((LivingEntity)proj.getMetadata("MINIBOSS_FIREBALL").get(0).value()), 10, false, true);
UtilAction.velocity(cur, UtilAlg.getTrajectory(proj.getLocation().add(0, -0.5, 0), cur.getEyeLocation()),
STRENGTH_MULTIPLIER * range, false, 0, VERT_MULTIPLIER * range, 1.2, true);
}
}
/**
* Checks if the given projectile is a boss fireball
* @param entity The projectile to check
* @return Whether the given projectile is a boss fireball
*/
public static boolean isFireball(Projectile entity)
{
return entity.hasMetadata("MINIBOSS_FIREBALL");
}
/**
* Makes an entity shoot a fireball
* @param shooter The entity to shoot from
*/
public static void launchFireball(LivingEntity shooter)
{
LargeFireball ball = shooter.launchProjectile(LargeFireball.class);
ball.setShooter(shooter);
ball.setIsIncendiary(false);
ball.setYield(0);
ball.setBounce(false);
ball.teleport(shooter.getEyeLocation().add(shooter.getLocation().getDirection().multiply(1)));
ball.setVelocity(new Vector(0,0,0));
ball.setMetadata("MINIBOSS_FIREBALL", new FixedMetadataValue(ClansManager.getInstance().getPlugin(), shooter));
shooter.getWorld().playSound(shooter.getLocation(), Sound.GHAST_FIREBALL, SOUND_VOLUME, SOUND_PITCH);
}
}

View File

@ -0,0 +1,128 @@
package mineplex.game.clans.clans.nether.miniboss;
import java.util.Arrays;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
/**
* Base class for nether minibosses
* @param <Mob> The type of entity this boss will use
*/
public abstract class NetherMiniBoss<Mob extends LivingEntity> implements Listener
{
private Mob _entity;
private EntityType _type;
private String _name;
private double _maxHealth;
private Location _spawn;
public NetherMiniBoss(String displayName, Double maxHealth, Location spawn, EntityType type)
{
_name = displayName;
_maxHealth = maxHealth;
_spawn = spawn;
_type = type;
spawn();
}
@SuppressWarnings("unchecked")
private void spawn()
{
_entity = (Mob) _spawn.getWorld().spawnEntity(_spawn, _type);
_entity.setMaxHealth(_maxHealth);
_entity.setHealth(_maxHealth);
_entity.setCustomName(_name);
_entity.setCustomNameVisible(true);
customSpawn();
Bukkit.getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
}
/**
* Fetches the entity for this boss
* @return The entity for this boss
*/
public Mob getEntity()
{
return _entity;
}
/**
* Method called after the entity spawns
*/
public void customSpawn() {};
/**
* Method called when the entity dies
* @param deathLocation The location where the entity died
*/
public void customDeath(Location deathLocation) {};
/**
* Method called when the entity despawns for non-death reasons
*/
public void customDespawn() {};
/**
* Method called for updating every 10 ticks
*/
public void update() {};
@EventHandler
public void onDeath(EntityDeathEvent event)
{
if (event.getEntity().equals(_entity))
{
event.setDroppedExp(0);
event.getDrops().clear();
HandlerList.unregisterAll(this);
customDeath(event.getEntity().getLocation());
}
}
@EventHandler
public void onUnload(ChunkUnloadEvent event)
{
if (Arrays.asList(event.getChunk().getEntities()).contains(_entity))
{
HandlerList.unregisterAll(this);
_entity.remove();
customDespawn();
return;
}
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
if (!_entity.isValid())
{
HandlerList.unregisterAll(this);
customDespawn();
return;
}
if (_entity.getFireTicks() > 0)
{
_entity.setFireTicks(-1);
}
update();
}
}

View File

@ -0,0 +1,127 @@
package mineplex.game.clans.clans.nether.miniboss;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.nether.NetherManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import com.google.common.collect.Lists;
/**
* Manager to handle miniboss spawning in the nether
*/
public class NetherMinibossManager implements Listener
{
private static final long MINIBOSS_SPAWN_RATE = 10000;
private NetherManager _manager;
private HashMap<Location, NetherMinibossType> _spawns = new HashMap<>();
private long _lastSpawned;
private boolean _allowSpawn = false;
public NetherMinibossManager(NetherManager manager)
{
_manager = manager;
new MinibossFireball();
manager.runSyncLater(() ->
{
List<Location> sort = Lists.newArrayList();
sort.add(new Location(manager.getNetherWorld(), -18, 142, 61));
sort.add(new Location(manager.getNetherWorld(), -39, 133, -25));
sort.add(new Location(manager.getNetherWorld(), -102, 133, -99));
sort.add(new Location(manager.getNetherWorld(), -27, 141, -140));
sort.add(new Location(manager.getNetherWorld(), 32, 143, -95));
sort.add(new Location(manager.getNetherWorld(), 43, 134, 22));
sort.add(new Location(manager.getNetherWorld(), 102, 141, -31));
sort.add(new Location(manager.getNetherWorld(), 151, 136, 34));
sort.sort(new Comparator<Location>()
{
public int compare(Location o1, Location o2)
{
if (UtilMath.offset2d(o1, manager.getNetherWorld().getSpawnLocation()) < UtilMath.offset(o2, manager.getNetherWorld().getSpawnLocation()))
{
return -1;
}
return 1;
}
});
for (int i = 0; i < 3; i++)
{
_spawns.put(sort.get(i).add(0.5, 1.5, 0.5), NetherMinibossType.ARCHER);
}
for (int i = 3; i < 6; i++)
{
_spawns.put(sort.get(i).add(0.5, 1.5, 0.5), NetherMinibossType.WARRIOR);
}
for (int i = 6; i < 8; i++)
{
_spawns.put(sort.get(i).add(0.5, 1.5, 0.5), NetherMinibossType.GHAST);
}
Bukkit.getPluginManager().registerEvents(this, manager.getPlugin());
}, 20L);
}
private void spawnAttacker(Location loc)
{
NetherMinibossType bossType = _spawns.get(loc);
_allowSpawn = true;
bossType.getNewInstance(loc);
_allowSpawn = false;
}
@EventHandler
public void onSpawnNormal(EntitySpawnEvent event)
{
if (event.getEntity() instanceof LivingEntity && _manager.getNetherWorld().equals(event.getLocation().getWorld()))
{
if (!_allowSpawn)
{
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.LOW)
public void onUnload(ChunkUnloadEvent event)
{
if (_manager.getNetherWorld().equals(event.getWorld()))
{
if (!_manager.InNether.isEmpty())
{
event.setCancelled(true);
}
}
}
@EventHandler
public void onSpawnThreat(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
if (!_manager.InNether.isEmpty() && UtilTime.elapsed(_lastSpawned, MINIBOSS_SPAWN_RATE))
{
_lastSpawned = System.currentTimeMillis();
for (Location spawn : _spawns.keySet())
{
spawnAttacker(spawn);
}
}
}
}

View File

@ -0,0 +1,49 @@
package mineplex.game.clans.clans.nether.miniboss;
import mineplex.game.clans.clans.nether.miniboss.bosses.ArcherMiniboss;
import mineplex.game.clans.clans.nether.miniboss.bosses.GhastMiniboss;
import mineplex.game.clans.clans.nether.miniboss.bosses.WarriorMiniboss;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
/**
* Enum with all types of nether minibosses
*/
public enum NetherMinibossType
{
GHAST("Ghast", 25D, EntityType.GHAST, GhastMiniboss.class),
WARRIOR("Undead Warrior", 30D, EntityType.ZOMBIE, WarriorMiniboss.class),
ARCHER("Undead Archer", 25D, EntityType.SKELETON, ArcherMiniboss.class)
;
private Class<? extends NetherMiniBoss> _code;
private String _name;
private Double _maxHealth;
private EntityType _type;
private NetherMinibossType(String name, Double maxHealth, EntityType type, Class<? extends NetherMiniBoss> code)
{
_name = name;
_maxHealth = maxHealth;
_type = type;
_code = code;
}
/**
* Creates a new instance of this miniboss at a given location
* @param spawn The location to spawn the boss in
* @return The instance of the miniboss
*/
public NetherMiniBoss getNewInstance(Location spawn)
{
try
{
return _code.getConstructor(String.class, Double.class, Location.class, EntityType.class).newInstance(_name, _maxHealth, spawn, _type);
}
catch (Exception e)
{
return null;
}
}
}

View File

@ -0,0 +1,203 @@
package mineplex.game.clans.clans.nether.miniboss.bosses;
import java.util.Random;
import mineplex.core.common.util.UtilMath;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.amplifiers.AmplifierManager;
import mineplex.game.clans.clans.nether.miniboss.NetherMiniBoss;
import mineplex.game.clans.items.runes.RuneManager.RuneAttribute;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Skeleton;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
/**
* Class for running an individual Archer miniboss
*/
public class ArcherMiniboss extends NetherMiniBoss<Skeleton>
{
private static final int BARBED_LEVEL = 1;
private static final double RUNE_DROP_CHANCE = .1;
private static final int MAX_DIAMOND_DROPS = 5;
public ArcherMiniboss(String displayName, Double maxHealth, Location spawn, EntityType type)
{
super(displayName, maxHealth, spawn, type);
}
@Override
public void customSpawn()
{
Skeleton entity = getEntity();
EntityEquipment eq = entity.getEquipment();
eq.setItemInHand(new ItemStack(Material.BOW));
eq.setHelmet(new ItemStack(Material.CHAINMAIL_HELMET));
eq.setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));
eq.setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));
eq.setBoots(new ItemStack(Material.CHAINMAIL_BOOTS));
eq.setItemInHandDropChance(0.f);
eq.setHelmetDropChance(0.f);
eq.setChestplateDropChance(0.f);
eq.setLeggingsDropChance(0.f);
eq.setBootsDropChance(0.f);
entity.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999, 0));
}
@Override
public void customDeath(Location deathLocation)
{
deathLocation.getWorld().dropItemNaturally(deathLocation, new ItemStack(Material.DIAMOND, UtilMath.r(MAX_DIAMOND_DROPS) + 1));
double runeDropChance = RUNE_DROP_CHANCE;
if (ClansManager.getInstance().getAmplifierManager().hasActiveAmplifier())
{
runeDropChance *= AmplifierManager.AMPLIFIER_RUNE_DROP_MULTIPLIER;
}
if (new Random().nextDouble() <= runeDropChance)
{
RuneAttribute runeType = RuneAttribute.values()[UtilMath.r(RuneAttribute.values().length)];
deathLocation.getWorld().dropItemNaturally(deathLocation, ClansManager.getInstance().getGearManager().getRuneManager().getRune(runeType));
}
}
@EventHandler
public void onTarget(EntityTargetLivingEntityEvent event)
{
if (getEntity().equals(event.getEntity()))
{
if (!(event.getTarget() instanceof Player))
{
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void bowShoot(EntityShootBowEvent event)
{
if (BARBED_LEVEL == 0)
{
return;
}
if (!(event.getProjectile() instanceof Arrow))
{
return;
}
if (event.getEntity().getEntityId() != getEntity().getEntityId())
{
return;
}
event.getProjectile().setMetadata("BARBED_ARROW", new FixedMetadataValue(ClansManager.getInstance().getPlugin(), 2));
}
@EventHandler(priority = EventPriority.HIGH)
public void damage(CustomDamageEvent event)
{
if (event.IsCancelled())
{
return;
}
if (event.GetCause() != DamageCause.PROJECTILE)
{
return;
}
Projectile projectile = event.GetProjectile();
LivingEntity damagee = event.GetDamageeEntity();
LivingEntity damager = event.GetDamagerEntity(true);
if (projectile == null)
{
return;
}
if (!projectile.hasMetadata("BARBED_ARROW"))
{
return;
}
if (damagee == null)
{
return;
}
if (damager == null)
{
return;
}
if (!getEntity().equals(damager))
{
return;
}
// Level
if (BARBED_LEVEL == 0)
{
return;
}
Player damageePlayer = event.GetDamageePlayer();
if (damageePlayer != null)
{
damageePlayer.setSprinting(false);
}
// Damage
event.AddMod(damager.getName(), "Barbed Arrows", projectile.getMetadata("BARBED_ARROW").get(0).asDouble(), false);
// Condition
ClansManager.getInstance().getCondition().Factory().Slow("Barbed Arrows", damagee, damager, (projectile.getVelocity().length() / 3) * (2 + BARBED_LEVEL), 0, false, true, true, true);
}
@EventHandler(priority = EventPriority.HIGH)
public void protect(CustomDamageEvent event)
{
if (event.IsCancelled())
{
return;
}
LivingEntity damagee = event.GetDamageeEntity();
LivingEntity damager = event.GetDamagerEntity(event.GetCause() == DamageCause.PROJECTILE);
if (damagee == null)
{
return;
}
if (damager == null)
{
return;
}
if (getEntity().equals(damagee))
{
if (!(damager instanceof Player))
{
event.SetCancelled("Allied Attacker");
}
}
}
}

View File

@ -0,0 +1,124 @@
package mineplex.game.clans.clans.nether.miniboss.bosses;
import java.util.Random;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.amplifiers.AmplifierManager;
import mineplex.game.clans.clans.nether.miniboss.MinibossFireball;
import mineplex.game.clans.clans.nether.miniboss.NetherMiniBoss;
import mineplex.game.clans.items.runes.RuneManager.RuneAttribute;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.inventory.ItemStack;
/**
* Class for running an individual Ghast miniboss
*/
public class GhastMiniboss extends NetherMiniBoss<Ghast>
{
private static final long MAIN_FIREBALL_COOLDOWN = 5000;
private static final long FIREBALL_LAUNCH_RATE = 500;
private static final int FIREBALLS_PER_USE = 5;
private static final double RUNE_DROP_CHANCE = .1;
private static final int MAX_DIAMOND_DROPS = 5;
private static final double MAX_TARGET_RANGE = 25;
private long _lastFireballUse;
private int _fireballsRemaining;
public GhastMiniboss(String displayName, Double maxHealth, Location spawn, EntityType type)
{
super(displayName, maxHealth, spawn, type);
}
private void tryFireballVolley()
{
if (_fireballsRemaining > 0)
{
if (UtilTime.elapsed(_lastFireballUse, FIREBALL_LAUNCH_RATE))
{
_fireballsRemaining--;
_lastFireballUse = System.currentTimeMillis();
MinibossFireball.launchFireball(getEntity());
}
}
else
{
if (UtilTime.elapsed(_lastFireballUse, MAIN_FIREBALL_COOLDOWN))
{
_fireballsRemaining = FIREBALLS_PER_USE;
}
}
}
@Override
public void customSpawn()
{
_lastFireballUse = System.currentTimeMillis();
_fireballsRemaining = 0;
}
@Override
public void customDeath(Location deathLocation)
{
deathLocation.getWorld().dropItemNaturally(deathLocation, new ItemStack(Material.DIAMOND, UtilMath.r(MAX_DIAMOND_DROPS) + 1));
double runeDropChance = RUNE_DROP_CHANCE;
if (ClansManager.getInstance().getAmplifierManager().hasActiveAmplifier())
{
runeDropChance *= AmplifierManager.AMPLIFIER_RUNE_DROP_MULTIPLIER;
}
if (new Random().nextDouble() <= runeDropChance)
{
RuneAttribute runeType = RuneAttribute.values()[UtilMath.r(RuneAttribute.values().length)];
deathLocation.getWorld().dropItemNaturally(deathLocation, ClansManager.getInstance().getGearManager().getRuneManager().getRune(runeType));
}
}
@Override
public void update()
{
Player target = null;
for (Player test : UtilPlayer.getInRadius(getEntity().getLocation(), MAX_TARGET_RANGE).keySet())
{
if (test.getGameMode() == GameMode.SURVIVAL && !ClansManager.getInstance().getIncognitoManager().Get(test).Hidden)
{
target = test;
break;
}
}
if (target != null)
{
UtilEnt.LookAt(getEntity(), target.getLocation());
tryFireballVolley();
}
}
@EventHandler
public void onShoot(ProjectileLaunchEvent event)
{
if (event.getEntity().getShooter() != null && event.getEntity().getShooter().equals(getEntity()))
{
ClansManager.getInstance().runSyncLater(() ->
{
if (event.getEntity() == null || event.getEntity().isDead() || !event.getEntity().isValid())
{
return;
}
if (!MinibossFireball.isFireball(event.getEntity()))
{
event.getEntity().remove();
}
}, 1L);
}
}
}

View File

@ -0,0 +1,150 @@
package mineplex.game.clans.clans.nether.miniboss.bosses;
import java.util.Random;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.amplifiers.AmplifierManager;
import mineplex.game.clans.clans.nether.miniboss.NetherMiniBoss;
import mineplex.game.clans.items.runes.RuneManager.RuneAttribute;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
/**
* Class for running an individual Warrior miniboss
*/
public class WarriorMiniboss extends NetherMiniBoss<Zombie>
{
private static final double RUNE_DROP_CHANCE = .1;
private static final int MAX_DIAMOND_DROPS = 5;
private static final double LEAP_CHANCE = .9;
private static final double LEAP_MIN_DIST = 3;
private static final double LEAP_MAX_DIST = 16;
private static final float SOUND_VOLUME = 1f;
private static final float SOUND_PITCH = 2f;
public WarriorMiniboss(String displayName, Double maxHealth, Location spawn, EntityType type)
{
super(displayName, maxHealth, spawn, type);
}
@Override
public void customSpawn()
{
Zombie entity = getEntity();
EntityEquipment eq = entity.getEquipment();
eq.setHelmet(new ItemStack(Material.IRON_HELMET));
eq.setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
eq.setLeggings(new ItemStack(Material.IRON_LEGGINGS));
eq.setBoots(new ItemStack(Material.IRON_BOOTS));
eq.setItemInHand(new ItemStack(Material.STONE_SWORD));
eq.setHelmetDropChance(0.f);
eq.setChestplateDropChance(0.f);
eq.setLeggingsDropChance(0.f);
eq.setBootsDropChance(0.f);
eq.setItemInHandDropChance(0.f);
entity.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999, 0));
}
@Override
public void customDeath(Location deathLocation)
{
deathLocation.getWorld().dropItemNaturally(deathLocation, new ItemStack(Material.DIAMOND, UtilMath.r(MAX_DIAMOND_DROPS) + 1));
double runeDropChance = RUNE_DROP_CHANCE;
if (ClansManager.getInstance().getAmplifierManager().hasActiveAmplifier())
{
runeDropChance *= AmplifierManager.AMPLIFIER_RUNE_DROP_MULTIPLIER;
}
if (new Random().nextDouble() <= runeDropChance)
{
RuneAttribute runeType = RuneAttribute.values()[UtilMath.r(RuneAttribute.values().length)];
deathLocation.getWorld().dropItemNaturally(deathLocation, ClansManager.getInstance().getGearManager().getRuneManager().getRune(runeType));
}
}
@Override
public void update()
{
if (Math.random() < LEAP_CHANCE)
return;
Zombie zombie = getEntity();
if (zombie.getTarget() == null)
return;
double dist = UtilMath.offset(zombie.getTarget(), zombie);
if (dist <= LEAP_MIN_DIST || dist > LEAP_MAX_DIST)
return;
double power = 0.8 + (1.2 * ((dist-3)/13d)); //Im sorry connor but i have no idea what those numbers are for <3
//Leap
UtilAction.velocity(zombie, UtilAlg.getTrajectory(zombie, zombie.getTarget()),
power, false, 0, 0.2, 1, true);
//Effect
zombie.getWorld().playSound(zombie.getLocation(), Sound.ZOMBIE_HURT, SOUND_VOLUME, SOUND_PITCH);
}
@EventHandler
public void onTarget(EntityTargetLivingEntityEvent event)
{
if (getEntity().equals(event.getEntity()))
{
if (!(event.getTarget() instanceof Player))
{
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void protect(CustomDamageEvent event)
{
if (event.IsCancelled())
{
return;
}
LivingEntity damagee = event.GetDamageeEntity();
LivingEntity damager = event.GetDamagerEntity(event.GetCause() == DamageCause.PROJECTILE);
if (damagee == null)
{
return;
}
if (damager == null)
{
return;
}
if (getEntity().equals(damagee))
{
if (!(damager instanceof Player))
{
event.SetCancelled("Allied Attacker");
}
}
}
}

View File

@ -1,41 +1,22 @@
package mineplex.game.clans.clans.regions;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.java.JavaPlugin;
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldBorder;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansDataAccessLayer;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.spawn.Spawn;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTeleportEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
public class ClansRegions extends MiniPlugin
{
public final static String DEFAULT_WORLD_NAME = "world";
@ -43,7 +24,7 @@ public class ClansRegions extends MiniPlugin
public final static int SHOP_RADIUS = 5; // Radius of shop claim area (measured in chunks)
public final static int FIELDS_RADIUS = 7; // Radius of fields claim area (measured in chunks)
public final static int BORDERLANDS_RADIUS = 85; // Radius of borderlands claim area (measured in chunks)
public static final int BORDER_RADIUS = 1319;
public static final int BORDER_RADIUS = 1250;
private ClansManager _manager;
private World _world;

View File

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

View File

@ -1,10 +1,7 @@
package mineplex.game.clans.clans.scoreboard.elements;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime;
import mineplex.core.scoreboard.ScoreboardManager;
@ -12,6 +9,10 @@ import mineplex.core.scoreboard.elements.ScoreboardElement;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import org.bukkit.entity.Player;
import com.google.common.collect.Lists;
public class ScoreboardElementClan implements ScoreboardElement
{
private ClansManager _clansManager;
@ -24,22 +25,28 @@ public class ScoreboardElementClan implements ScoreboardElement
@Override
public List<String> getLines(ScoreboardManager manager, Player player, List<String> out)
{
List<String> output = new ArrayList<String>();
List<String> output = Lists.newArrayList();
ClanInfo clanInfo = _clansManager.getClan(player);
if (clanInfo != null)
{
output.add(C.cYellow + "Clan " + C.cWhite + clanInfo.getName());
output.add(C.cYellow + "Online " + C.cWhite + clanInfo.getOnlinePlayers().size() + "/" + clanInfo.getMembers().size());
output.add(C.cYellowB + "Clan");
output.add(_clansManager.getClanUtility().mRel(_clansManager.getRelation(player, player), clanInfo.getName(), false));
output.add(" ");
// Energy
if (clanInfo.getEnergyCostPerMinute() > 0)
output.add(C.cYellow + "Energy " + C.cWhite + UtilTime.convertString((clanInfo.getEnergy() / clanInfo.getEnergyCostPerMinute()) * 60000L, 1, UtilTime.TimeUnit.FIT));
{
output.add(C.cYellowB + "Clan Energy");
output.add(C.cGreen + UtilTime.convertString((clanInfo.getEnergy() / clanInfo.getEnergyCostPerMinute()) * 60000L, 1, UtilTime.TimeUnit.FIT));
output.add(" ");
}
}
else
{
output.add(C.cYellow + "You are not in a Clan");
output.add(C.cYellowB + "Clan");
output.add("No Clan");
output.add(" ");
}
return output;

View File

@ -1,15 +1,17 @@
package mineplex.game.clans.clans.scoreboard.elements;
import java.util.List;
import mineplex.core.common.util.C;
import mineplex.core.scoreboard.ScoreboardManager;
import mineplex.core.scoreboard.elements.ScoreboardElement;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansUtility;
import mineplex.game.clans.core.repository.ClanTerritory;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
public class ScoreboardElementPlayer implements ScoreboardElement
{
@ -23,11 +25,14 @@ public class ScoreboardElementPlayer implements ScoreboardElement
@Override
public List<String> getLines(ScoreboardManager manager, Player player, List<String> out)
{
List<String> output = new ArrayList<String>();
output.add(C.cYellow + "Gold " + C.cWhite + _clansManager.getGoldManager().Get(player).getBalance());
String regionString = C.xWilderness + "Wilderness";
List<String> output = Lists.newArrayList();
output.add(C.cYellowB + "Gold");
output.add(C.cGold + "Gold " + _clansManager.getGoldManager().Get(player).getBalance());
output.add(" ");
output.add(" ");
output.add(C.cYellowB + "Territory");
String regionString = C.xWilderness + "Wilderness";
ClanTerritory claim = _clansManager.getClanUtility().getClaim(player.getLocation());
if (claim != null)
{
@ -39,17 +44,18 @@ public class ScoreboardElementPlayer implements ScoreboardElement
//Trust
if (relation == ClansUtility.ClanRelation.ALLY_TRUST)
{
regionString += C.mBody + "(" + C.mElem + "Trusted" + C.mBody + ")";
}
}
// if (_clansManager.getNetherManager().isInNether(player))
// {
// regionString = C.cRed + "The Nether";
// }
if (_clansManager.getNetherManager().isInNether(player))
{
regionString = C.cClansNether + "The Nether";
}
output.add(regionString);
return output;
}
}
}

View File

@ -1,15 +1,5 @@
package mineplex.game.clans.clans.siege;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent;
import com.google.gson.Gson;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
@ -21,6 +11,7 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.command.GiveWeaponCommand;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.repository.SiegeWeaponRepository;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
@ -30,6 +21,16 @@ import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.spawn.Spawn;
import net.minecraft.server.v1_8_R3.Material;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent;
import com.google.gson.Gson;
public class SiegeManager extends MiniPlugin
{
private ClansManager _clansManager;
@ -79,6 +80,8 @@ public class SiegeManager extends MiniPlugin
})
)
);
addCommand(new GiveWeaponCommand(this));
}
@EventHandler
@ -222,12 +225,12 @@ public class SiegeManager extends MiniPlugin
public boolean trySpawnCannon(Player player, Location location)
{
// if (_clansManager.getNetherManager().isInNether(player))
// {
// _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + ".");
//
// return false;
// }
if (_clansManager.getNetherManager().isInNether(player))
{
_clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + ".");
return false;
}
if (!_clansManager.isInClan(player))
{

View File

@ -0,0 +1,26 @@
package mineplex.game.clans.clans.siege.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.weapon.Cannon;
public class GiveWeaponCommand extends CommandBase<SiegeManager>
{
public GiveWeaponCommand(SiegeManager plugin)
{
super(plugin, Rank.ADMIN, "giveweapon", "siegeweapon", "givecannon");
}
@Override
public void Execute(Player caller, String[] args)
{
UtilInv.insert(caller, Cannon.CANNON_ITEM.clone());
UtilPlayer.message(caller, F.main(Plugin.getName(), "You have been given a cannon!"));
}
}

View File

@ -3,6 +3,7 @@ package mineplex.game.clans.clans.siege.weapon;
import java.util.UUID;
import org.apache.commons.lang.Validate;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -487,6 +488,12 @@ public abstract class SiegeWeapon implements Listener
protected void handleLeftClick(Player player)
{
if (player.getGameMode() == GameMode.CREATIVE && player.isSneaking())
{
removeHealth(getHealth());
return;
}
if (_lastLeft == -1)
{
_lastLeft = System.currentTimeMillis();

View File

@ -1,95 +1,24 @@
package mineplex.game.clans.clans.siege.weapon.projectile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
import mineplex.game.clans.core.repository.ClanTerritory;
import net.minecraft.server.v1_8_R3.Explosion;
public class Crater implements Listener
import org.bukkit.Location;
public class Crater
{
public static final Material CHARRED_TYPE = Material.OBSIDIAN;
private final SiegeWeapon _weapon;
private final Location _origin;
private final long _birthTime;
private final List<CraterBlock> _blocks;
public Crater(SiegeWeapon weapon, WeaponProjectile projectile, Location origin)
{
_weapon = weapon;
_origin = origin;
_birthTime = System.currentTimeMillis();
_blocks = new ArrayList<>();
UtilServer.getPluginManager().registerEvents(this, _weapon.getClans().getPlugin());
createExplosion();
}
@EventHandler
public void updateEffects(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
_blocks.stream().filter(block -> block.Type == CHARRED_TYPE).forEach(block -> {
long lifetime = System.currentTimeMillis() - _birthTime;
long max = 80000;
if (block.Location.getBlock().getType() != CHARRED_TYPE)
{
return;
}
// Water touching the charred blocks
if (UtilBlock.getInRadius(block.Location, 1.6).keySet().stream().filter(water -> water.getType() == Material.WATER).iterator().hasNext())
{
return;
}
if (lifetime < max)
{
UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX);
UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX);
}
else
{
HandlerList.unregisterAll(this);
}
});
}
private void createExplosion()
{
ClanTerritory terr = _weapon.getClans().getClanUtility().getClaim(_origin);
@ -98,58 +27,15 @@ public class Crater implements Listener
{
return;
}
boolean explosion = _origin.getWorld().createExplosion(_origin, 2.6f);
boolean floating = _origin.distance(UtilBlock.nearestFloor(_origin)) > 0.6;
if (explosion)
if (terr != null)
{
for (Block block : UtilBlock.getInRadius(_origin.getBlock(), 2.6f).keySet())
ClanInfo clan = ClansManager.getInstance().getClanUtility().getOwner(terr);
if (clan != null && !ClansManager.getInstance().getWarManager().isBeingBesiegedBy(clan, _weapon.getOwner()))
{
boolean charred = false;
double dist = block.getLocation().distance(_origin);
if (floating)
{
if (!block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE)
&& !block.getRelative(BlockFace.DOWN).getType().equals(Material.AIR)
&& Math.random() > 0.79)
{
charred = true;
}
}
else
{
if (block.getRelative(BlockFace.UP).getType().equals(Material.AIR)
&& !block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE)
&& !block.getRelative(BlockFace.DOWN).getType().equals(Material.AIR)
&& Math.random() > 0.79)
{
charred = true;
}
}
if (block.getType().equals(Material.SMOOTH_BRICK))
{
charred = false;
}
if (block.getType().equals(Material.BEDROCK))
{
charred = false;
}
if (charred)
{
CraterBlock charredBlock = new CraterBlock(block.getLocation(), dist, CHARRED_TYPE, (byte) 0);
charredBlock.set();
_blocks.add(charredBlock);
}
return;
}
}
_origin.getWorld().createExplosion(_origin, 2.6f);
}
}
}

View File

@ -7,12 +7,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
@ -31,10 +25,18 @@ import mineplex.game.clans.clans.ClansUtility;
import mineplex.game.clans.clans.event.ClanDisbandedEvent;
import mineplex.game.clans.clans.event.ClansPlayerDeathEvent;
import mineplex.game.clans.clans.war.command.WarPointsCommand;
import mineplex.game.clans.clans.war.event.WarInvasionEndEvent;
import mineplex.game.clans.clans.war.event.WarInvasionStartEvent;
import mineplex.game.clans.clans.war.event.WarSiegeEndEvent;
import mineplex.game.clans.clans.war.event.WarSiegeStartEvent;
import mineplex.game.clans.core.war.ClanWarData;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class WarManager extends MiniPlugin implements ScoreboardElement
{
public static final int WAR_START_POINTS = 0;
@ -45,18 +47,17 @@ public class WarManager extends MiniPlugin implements ScoreboardElement
private final ClansManager _clansManager;
/**
* Map of the active war invasions. This is indexed by the clan that is being invaded on
* We will need to access this when blocks are broken in the invaded on clan's land!
* Map of the active war sieges. This is indexed by the clan that is being besieged
*/
private Map<String, List<WarInvasion>> _invadedMap;
private Map<String, List<WarInvasion>> _invaderMap;
private Map<String, List<WarSiege>> _besiegedMap;
private Map<String, List<WarSiege>> _besiegerMap;
public WarManager(JavaPlugin plugin, ClansManager clansManager)
{
super("ClanWar Manager", plugin);
_clansManager = clansManager;
_invadedMap = new HashMap<String, List<WarInvasion>>();
_invaderMap = new HashMap<String, List<WarInvasion>>();
_besiegedMap = new HashMap<>();
_besiegerMap = new HashMap<>();
}
public ClansManager getClansManager()
@ -64,41 +65,38 @@ public class WarManager extends MiniPlugin implements ScoreboardElement
return _clansManager;
}
public List<WarInvasion> getInvasionsOn(ClanInfo invaded)
public List<WarSiege> getSiegesOn(ClanInfo besieged)
{
return _invadedMap.get(invaded.getName());
return _besiegedMap.get(besieged.getName());
}
public List<WarInvasion> getInvasionsFor(ClanInfo invader)
public List<WarSiege> getSiegesFor(ClanInfo besieger)
{
return _invaderMap.get(invader.getName());
return _besiegerMap.get(besieger.getName());
}
public boolean isBeingInvaded(ClanInfo clanInfo)
public boolean isBeingBesieged(ClanInfo clanInfo)
{
List<WarInvasion> invasions = _invadedMap.get(clanInfo.getName());
return invasions != null && !invasions.isEmpty();
List<WarSiege> sieges = _besiegedMap.get(clanInfo.getName());
return sieges != null && !sieges.isEmpty();
}
public boolean isInvading(ClanInfo clanInfo)
public boolean isBesieging(ClanInfo clanInfo)
{
List<WarInvasion> invasions = _invaderMap.get(clanInfo.getName());
return invasions != null && !invasions.isEmpty();
List<WarSiege> sieges = _besiegerMap.get(clanInfo.getName());
return sieges != null && !sieges.isEmpty();
}
public boolean allowFromInvade(Location location, Player player)
public boolean isBeingBesiegedBy(ClanInfo besieged, ClanInfo besieger)
{
ClanInfo clanInfo = _clansManager.getClanUtility().getOwner(location);
ClanInfo playerClan = _clansManager.getClan(player);
if (clanInfo != null)
List<WarSiege> sieges = _besiegedMap.get(besieged.getName());
if (sieges != null && !sieges.isEmpty())
{
List<WarInvasion> invasions = _invadedMap.get(clanInfo.getName());
if (invasions != null)
for (WarSiege siege : sieges)
{
for (WarInvasion invasion : invasions)
if (siege.getBesiegingClan().equals(besieger.getName()))
{
if (invasion.getInvaderClan().equals(playerClan.getName()))
return true;
return true;
}
}
}
@ -106,14 +104,6 @@ public class WarManager extends MiniPlugin implements ScoreboardElement
return false;
}
/**
* Clear all invasions against clan. This is typically used for when a clan is deleted
*/
// public void clearInvasions(String clan)
// {
// List<WarInvasion> invasions =
// }
@EventHandler
public void handleDeath(final ClansPlayerDeathEvent event)
{
@ -184,106 +174,107 @@ public class WarManager extends MiniPlugin implements ScoreboardElement
private void checkWarComplete(ClanWarData war)
{
String invaderClan = null;
String invadedClan = null;
String besiegerClan = null;
String besiegedClan = null;
if (war.getClanAPoints() >= WAR_FINISH_POINTS)
{
// Clan A invades Clan B
invaderClan = war.getClanA();
invadedClan = war.getClanB();
besiegerClan = war.getClanA();
besiegedClan = war.getClanB();
}
else if (war.getClanBPoints() >= WAR_FINISH_POINTS)
{
// Clan B invades Clan A
invaderClan = war.getClanB();
invadedClan = war.getClanA();
besiegerClan = war.getClanB();
besiegedClan = war.getClanA();
}
if (invadedClan != null && invaderClan != null)
if (besiegedClan != null && besiegerClan != null)
{
// Reset War to 0:0
war.resetPoints();
war.setCooldown(WAR_COOLDOWN);
WarInvasion invasion = new WarInvasion(invadedClan, invaderClan);
startInvasion(invasion);
WarSiege siege = new WarSiege(besiegedClan, besiegerClan);
startSiege(siege);
}
}
private void startInvasion(WarInvasion invasion)
private void startSiege(WarSiege siege)
{
String invaded = invasion.getInvadedClan();
String invader = invasion.getInvaderClan();
String besieged = siege.getBesiegedClan();
String besieger = siege.getBesiegingClan();
addInvasion(invaded, invasion, _invadedMap);
addInvasion(invader, invasion, _invaderMap);
addSiege(besieged, siege, _besiegedMap);
addSiege(besieger, siege, _besiegerMap);
WarInvasionStartEvent event = new WarInvasionStartEvent(invasion);
WarSiegeStartEvent event = new WarSiegeStartEvent(siege);
UtilServer.getServer().getPluginManager().callEvent(event);
}
private void addInvasion(String name, WarInvasion invasion, Map<String, List<WarInvasion>> invasionMap)
private void addSiege(String name, WarSiege siege, Map<String, List<WarSiege>> siegeMap)
{
if (invasionMap.containsKey(name))
if (siegeMap.containsKey(name))
{
invasionMap.get(name).add(invasion);
siegeMap.get(name).add(siege);
}
else
{
LinkedList<WarInvasion> invasions = new LinkedList<WarInvasion>();
invasions.add(invasion);
invasionMap.put(name, invasions);
LinkedList<WarSiege> sieges = new LinkedList<>();
sieges.add(siege);
siegeMap.put(name, sieges);
}
}
@EventHandler
public void clearInvasions(UpdateEvent event)
public void clearSieges(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
long currentTime = System.currentTimeMillis();
Iterator<Map.Entry<String, List<WarInvasion>>> iterator = _invadedMap.entrySet().iterator();
Iterator<Map.Entry<String, List<WarSiege>>> iterator = _besiegedMap.entrySet().iterator();
while (iterator.hasNext())
{
List<WarInvasion> invasions = iterator.next().getValue();
Iterator<WarInvasion> invasionIterator = invasions.iterator();
while (invasionIterator.hasNext())
List<WarSiege> sieges = iterator.next().getValue();
Iterator<WarSiege> siegeIterator = sieges.iterator();
while (siegeIterator.hasNext())
{
WarInvasion invasion = invasionIterator.next();
if (currentTime >= invasion.getEndTime())
WarSiege siege = siegeIterator.next();
if (currentTime >= siege.getEndTime())
{
WarInvasionEndEvent endEvent = new WarInvasionEndEvent(invasion);
WarSiegeEndEvent endEvent = new WarSiegeEndEvent(siege);
Bukkit.getServer().getPluginManager().callEvent(endEvent);
List<WarInvasion> invaderList = _invaderMap.get(invasion.getInvaderClan());
if (invaderList != null)
List<WarSiege> besiegerList = _besiegerMap.get(siege.getBesiegingClan());
if (besiegerList != null)
{
invaderList.remove(invasion);
if (invaderList.isEmpty()) _invaderMap.remove(invasion.getInvaderClan());
besiegerList.remove(siege);
if (besiegerList.isEmpty())
{
_besiegerMap.remove(siege.getBesiegingClan());
}
}
invasionIterator.remove();
siegeIterator.remove();
}
}
if (invasions.isEmpty())
if (sieges.isEmpty())
iterator.remove();
}
}
@EventHandler
public void onInvasionStart(WarInvasionStartEvent event)
public void onSiegeStart(WarSiegeStartEvent event)
{
Bukkit.broadcastMessage(F.main("War", F.elem(event.getWarInvasion().getInvaderClan()) + " can now invade " + F.elem(event.getWarInvasion().getInvadedClan())));
Bukkit.broadcastMessage(F.main("War", F.elem(event.getWarSiege().getBesiegingClan()) + " can now besiege " + F.elem(event.getWarSiege().getBesiegedClan())));
}
@EventHandler
public void onInvasionEnd(WarInvasionEndEvent event)
public void onSiegeEnd(WarSiegeEndEvent event)
{
Bukkit.broadcastMessage(F.main("War", F.elem(event.getWarInvasion().getInvaderClan()) + "'s invasion against " + F.elem(event.getWarInvasion().getInvadedClan()) + " has ended."));
Bukkit.broadcastMessage(F.main("War", F.elem(event.getWarSiege().getBesiegingClan()) + "'s siege against " + F.elem(event.getWarSiege().getBesiegedClan()) + " has ended."));
}
@ -297,9 +288,29 @@ public class WarManager extends MiniPlugin implements ScoreboardElement
public void cancelDisband(ClanDisbandedEvent event)
{
ClanInfo clan = event.getClan();
if (isBeingInvaded(clan) || isInvading(clan))
if (isBeingBesieged(clan) || isBesieging(clan))
{
UtilPlayer.message(event.getDisbander(), F.main("Clans", "Clans cannot be disbanded in the middle of a siege"));
event.setCancelled(true);
}
}
@EventHandler
public void onPlaceTNT(BlockPlaceEvent event)
{
if (event.getBlockPlaced().getType() == Material.TNT)
{
event.setCancelled(true);
event.setBuild(false);
UtilPlayer.message(event.getPlayer(), F.main("Clans", "TNT cannot be used outside of a siege cannon!"));
}
}
@EventHandler
public void onTNTDispense(BlockDispenseEvent event)
{
if (event.getItem().getType() == Material.TNT)
{
UtilPlayer.message(event.getDisbander(), F.main("Clans", "Clans cannot be disbanded in the middle of an invasion"));
event.setCancelled(true);
}
}
@ -313,32 +324,32 @@ public class WarManager extends MiniPlugin implements ScoreboardElement
if (clan != null)
{
List<WarInvasion> invadedList = _invadedMap.get(clan.getName());
List<WarInvasion> invaderList = _invaderMap.get(clan.getName());
List<WarSiege> besiegedList = _besiegedMap.get(clan.getName());
List<WarSiege> besiegerList = _besiegerMap.get(clan.getName());
if (invaderList != null && !invaderList.isEmpty())
if (besiegerList != null && !besiegerList.isEmpty())
{
for (WarInvasion invasion : invaderList)
for (WarSiege siege : besiegerList)
{
element.add(" ");
element.add(C.cPurpleB + "Invading");
element.add(" " + invasion.getInvadedClan());
element.add(" " + UtilTime.convertString(invasion.getTimeLeft(), 1, UtilTime.TimeUnit.FIT));
element.add(C.cPurpleB + "Besieging");
element.add(" " + siege.getBesiegedClan());
element.add(" " + UtilTime.convertString(siege.getTimeLeft(), 1, UtilTime.TimeUnit.FIT));
}
}
if (invadedList != null && !invadedList.isEmpty())
if (besiegedList != null && !besiegedList.isEmpty())
{
for (WarInvasion invasion : invadedList)
for (WarSiege siege : besiegedList)
{
element.add(" ");
element.add(C.cRedB + "Invaded");
element.add(" " + invasion.getInvaderClan());
element.add(" " + UtilTime.convertString(invasion.getTimeLeft(), 1, UtilTime.TimeUnit.FIT));
element.add(C.cRedB + "Besieged");
element.add(" " + siege.getBesiegingClan());
element.add(" " + UtilTime.convertString(siege.getTimeLeft(), 1, UtilTime.TimeUnit.FIT));
}
}
}
return element;
}
}
}

View File

@ -1,16 +1,16 @@
package mineplex.game.clans.clans.war;
public class WarInvasion
public class WarSiege
{
private String _invadedClan;
private String _invaderClan;
private String _besiegedClan;
private String _besiegingClan;
private long _startTime;
private long _endTime;
public WarInvasion(String invadedClan, String invaderClan)
public WarSiege(String besiegedClan, String besiegingClan)
{
_invadedClan = invadedClan;
_invaderClan = invaderClan;
_besiegedClan = besiegedClan;
_besiegingClan = besiegingClan;
_startTime = System.currentTimeMillis();
_endTime = _startTime + WarManager.INVADE_LENGTH;
}
@ -20,14 +20,14 @@ public class WarInvasion
return _endTime - System.currentTimeMillis();
}
public String getInvadedClan()
public String getBesiegedClan()
{
return _invadedClan;
return _besiegedClan;
}
public String getInvaderClan()
public String getBesiegingClan()
{
return _invaderClan;
return _besiegingClan;
}
public long getStartTime()
@ -39,4 +39,4 @@ public class WarInvasion
{
return _endTime;
}
}
}

View File

@ -1,29 +1,29 @@
package mineplex.game.clans.clans.war.event;
import mineplex.game.clans.clans.war.WarSiege;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.game.clans.clans.war.WarInvasion;
/**
* Called when a war invasion is ended
* Called when a war siege is ended
*/
public class WarInvasionEndEvent extends Event
public class WarSiegeEndEvent extends Event
{
private WarInvasion _warInvasion;
private WarSiege _warSiege;
public WarInvasionEndEvent(WarInvasion warInvasion)
public WarSiegeEndEvent(WarSiege warSiege)
{
_warInvasion = warInvasion;
_warSiege = warSiege;
}
public WarInvasion getWarInvasion()
public WarSiege getWarSiege()
{
return _warInvasion;
return _warSiege;
}
// Bukkit event stuff
private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() { return handlers; }
public HandlerList getHandlers() { return handlers; }
}
}

View File

@ -1,29 +1,29 @@
package mineplex.game.clans.clans.war.event;
import mineplex.game.clans.clans.war.WarSiege;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.game.clans.clans.war.WarInvasion;
/**
* Called when a war invasion is started
* Called when a war siege is started
*/
public class WarInvasionStartEvent extends Event
public class WarSiegeStartEvent extends Event
{
private WarInvasion _warInvasion;
private WarSiege _warSiege;
public WarInvasionStartEvent(WarInvasion warInvasion)
public WarSiegeStartEvent(WarSiege warSiege)
{
_warInvasion = warInvasion;
_warSiege = warSiege;
}
public WarInvasion getWarInvasion()
public WarSiege getWarSiege()
{
return _warInvasion;
return _warSiege;
}
// Bukkit event stuff
private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() { return handlers; }
public HandlerList getHandlers() { return handlers; }
}
}

View File

@ -1,74 +1,74 @@
package mineplex.game.clans.clans.worldevent;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.Set;
import org.bukkit.Chunk;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClansManager;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import mineplex.core.common.util.EnclosedObject;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.regions.ClansRegions;
import com.google.common.collect.Lists;
public class EventTerrainFinder
{
private WorldEventManager _eventManager;
private static final long EVENT_AREA_COOLDOWN = UtilTime.convert(3, TimeUnit.HOURS, TimeUnit.MILLISECONDS);
private ClansManager _clansManager;
private ClansRegions _clansRegions;
public EventTerrainFinder(WorldEventManager eventManager, ClansManager clansManager, ClansRegions clansRegions)
public EventTerrainFinder(ClansManager clansManager)
{
_eventManager = eventManager;
_clansManager = clansManager;
_clansRegions = clansRegions;
}
public double posNeg()
public Location findAreaInBorderlands(boolean force)
{
if (Math.random() > 0.5) return -1;
return 1;
}
public Location findAreaInBorderlands(World world, int size, int vert)
{
for (int i = 0; i < 150; i++)
List<EventLocation> locs = Lists.newArrayList();
locs.addAll(Arrays.asList(EventLocation.values()));
locs.sort(new Comparator<EventLocation>()
{
EnclosedObject<Location> loc = new EnclosedObject<>();
if (_clansManager.getClanUtility().getClanByClanName("Borderlands") == null)
public int compare(EventLocation loc1, EventLocation loc2)
{
System.out.println("[WORLD EVENT] FATAL ERROR: CLAN BORDERLANDS NOT FOUND.");
break;
if (!UtilTime.elapsed(loc1.getLastUsed(), EVENT_AREA_COOLDOWN))
{
return 1;
}
if (!UtilTime.elapsed(loc2.getLastUsed(), EVENT_AREA_COOLDOWN))
{
return -1;
}
int[] rand = new int[] {1, -1};
return rand[new Random().nextInt(rand.length)];
}
_clansManager.getClanUtility().getClanByClanName("Borderlands").getClaimSet().stream().filter(claim -> Math.random() > .5).filter(claim -> Math.random() > .5).filter(claim -> Math.random() > .3).filter(claim -> Math.random() > .7).limit(1).forEach(claim -> {
Chunk chunk = UtilWorld.strToChunk(claim);
loc.Set(UtilBlock.getHighest(chunk.getWorld(), chunk.getBlock(0, 0, 0)).getLocation());
});
if (!UtilWorld.isBoxInWorldBorder(world, loc.Get().clone().subtract(size * 2, vert, size * 2), loc.Get().clone().add(size * 2, vert, size * 2)))
});
for (EventLocation loc : locs)
{
if (!UtilTime.elapsed(loc.getLastUsed(), EVENT_AREA_COOLDOWN))
{
continue;
}
if (loc.Get() == null)
if (_clansManager.getClanUtility().getClaim(loc.getLocation()) == null || _clansManager.getClanUtility().getClaim(loc.getLocation()).Owner.contains("Borderlands"))
{
continue;
loc.use();
return loc.getLocation();
}
System.out.println("Done finding area... [success]");
// Success
return loc.Get();
}
System.out.println("Failed to find area...");
if (force && !locs.isEmpty())
{
EventLocation loc = locs.get(UtilMath.r(locs.size()));
loc.use();
return loc.getLocation();
}
return null;
}
@ -129,4 +129,61 @@ public class EventTerrainFinder
return null;
}
}
/**
* Enum with locations around the map for world events to spawn
*/
private static enum EventLocation
{
NORTH_1("world", -495, 73, -1028),
NORTH_2("world", 197, 66, -1018),
NORTH_3("world", 948, 71, -959),
EAST_1("world", 1109, 66, -753),
EAST_2("world", 1141, 68, 31),
EAST_3("world", 1044, 71, 603),
SOUTH_1("world", 690, 71, 895),
SOUTH_2("world", 144, 66, 1012),
SOUTH_3("world", -1093, 71, 895),
WEST_1("world", -937, 71, 559),
WEST_2("world", -1092, 67, -9),
WEST_3("world", -969, 71, -441);
private String _world;
private double _x, _y, _z;
private long _last = 0;
private EventLocation(String worldName, double x, double y, double z)
{
_world = worldName;
_x = x;
_y = y;
_z = z;
}
/**
* Returns the Bukkit center location for this event space
* @return The Bukkit center location for this event space
*/
public Location getLocation()
{
return new Location(UtilWorld.getWorld(_world), _x, _y, _z);
}
/**
* Gets the last time this event space has been used
* @return The last time this event space has been used
*/
public Long getLastUsed()
{
return _last;
}
/**
* Updates this event space's last used time to now
*/
public void use()
{
_last = System.currentTimeMillis();
}
}
}

View File

@ -1,21 +1,14 @@
package mineplex.game.clans.clans.worldevent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.scoreboard.ScoreboardManager;
import mineplex.core.scoreboard.elements.ScoreboardElement;
@ -26,12 +19,26 @@ import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.regions.ClansRegions;
import mineplex.game.clans.clans.worldevent.command.WorldEventCommand;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
import mineplex.minecraft.game.core.boss.EventCreatureDeathEvent;
import mineplex.minecraft.game.core.boss.EventState;
import mineplex.minecraft.game.core.boss.WorldEvent;
import mineplex.minecraft.game.core.boss.broodmother.SpiderCreature;
import mineplex.minecraft.game.core.boss.ironwizard.GolemCreature;
import mineplex.minecraft.game.core.boss.skeletonking.SkeletonCreature;
import mineplex.minecraft.game.core.damage.DamageManager;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Lists;
public class WorldEventManager extends MiniPlugin implements ScoreboardElement
{
private static final double ARENA_RADIUS = 40;
private final List<WorldEvent> _runningEvents;
private Random _random;
@ -50,7 +57,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
super("World Event", plugin);
_random = new Random();
_terrainFinder = new EventTerrainFinder(this, clansManager, clansRegions);
_terrainFinder = new EventTerrainFinder(clansManager);
_clansManager = clansManager;
_damageManager = damageManager;
_lootManager = lootManager;
@ -81,7 +88,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
{
for (WorldEvent event : _runningEvents)
{
if (event.isInBounds(location))
if (UtilMath.offset2d(location, event.getCenterLocation()) <= ARENA_RADIUS)
{
return true;
}
@ -90,6 +97,37 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
return false;
}
@EventHandler
public void onIcePrison(SkillTriggerEvent event)
{
if (event.GetSkillName().equalsIgnoreCase("Ice Prison"))
{
for (WorldEvent e : _runningEvents)
{
if (isInEvent(event.GetPlayer().getLocation()))
{
event.SetCancelled(true);
}
}
}
}
@EventHandler
public void onBossDeath(EventCreatureDeathEvent event)
{
if (event.getCreature() instanceof GolemCreature || event.getCreature() instanceof SkeletonCreature || event.getCreature() instanceof SpiderCreature)
{
Location drop = event.getCreature().getLastKnownLocation();
if (drop != null)
{
runSyncLater(() ->
{
ClansManager.getInstance().getLootManager().dropRare(drop);
}, 20 * 2);
}
}
}
@EventHandler
public void update(UpdateEvent event)
{
@ -137,31 +175,34 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
}
}
public void randomEvent()
public WorldEventType randomEvent()
{
if (_runningEvents.size() == 0)
{
if (UtilServer.getPlayers().length > 0)
{
tryStartEvent();
return tryStartEvent();
}
}
return null;
}
private void tryStartEvent()
private WorldEventType tryStartEvent()
{
WorldEventType[] types = WorldEventType.values();
WorldEventType type = types[_random.nextInt(types.length)];
Location location = _terrainFinder.findAreaInBorderlands(Bukkit.getWorlds().get(0), type.getAreaNeeded(), type.getAreaNeeded());
Location location = _terrainFinder.findAreaInBorderlands(false);
if (location != null)
{
initializeEvent(type.createInstance(this, location, _skillFactory));
return type;
}
else
{
// Try again in 5 minutes
_nextEventStart = System.currentTimeMillis() + (5 * 60 * 1000);
}
return null;
}
private void initializeEvent(WorldEvent event)
@ -189,12 +230,16 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
return null;
}
public WorldEvent startEventFromType(Location location, WorldEventType eventType)
public WorldEvent startEventFromType(WorldEventType eventType)
{
if (eventType != null)
{
Location location = _terrainFinder.findAreaInBorderlands(true);
WorldEvent event = eventType.createInstance(this, location, _skillFactory);
initializeEvent(event);
if (event != null)
{
initializeEvent(event);
}
return event;
}
@ -245,7 +290,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
@Override
public List<String> getLines(ScoreboardManager manager, Player player, List<String> out)
{
List<String> output = new ArrayList<String>();
List<String> output = Lists.newArrayList();
Iterator<WorldEvent> iterator = _runningEvents.iterator();
while (iterator.hasNext())
@ -254,7 +299,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
if (event.getState() == EventState.LIVE)
{
output.add(" ");
output.add(" ");
output.add(C.cAqua + C.Bold + "Event");
Location eventLocation = event.getCenterLocation();

View File

@ -2,19 +2,21 @@ package mineplex.game.clans.clans.worldevent;
import java.lang.reflect.Constructor;
import org.bukkit.Location;
import mineplex.game.clans.clans.worldevent.kinghill.KingHill;
import mineplex.game.clans.clans.worldevent.undead.UndeadCamp;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
import mineplex.minecraft.game.core.boss.WorldEvent;
import mineplex.minecraft.game.core.boss.ironwizard.GolemBoss;
import mineplex.minecraft.game.core.boss.skeletonking.SkeletonBoss;
import org.bukkit.Location;
public enum WorldEventType
{
// SLIME_KING("Slime King", SlimeBoss.class, 30),
// KING_HILL("King of The Hill", KingHill.class, 30),
UNDEAD_CAMP("Undead Camp", UndeadCamp.class, 30);// ,
// Golem("Iron Wizard", GolemBoss.class, 30);
//SLIME_KING("Slime King", SlimeBoss.class, 30),
//KING_OF_THE_HILL("King of The Hill", KingHill.class, 30),
//UNDEAD_CAMP("Undead Camp", UndeadCamp.class, 30),
IRON_WIZARD("Iron Wizard",GolemBoss.class, 30),
//BROOD_MOTHER("Brood Mother", SpiderBoss.class, 30),
SKELETON_KING("Skeleton King", SkeletonBoss.class, 30);
private String _name;
private Class<? extends WorldEvent> _clazz;
@ -70,4 +72,9 @@ public enum WorldEventType
return worldEvent;
}
public String getName()
{
return this._name;
}
}

View File

@ -18,13 +18,13 @@ public class ClearCommand extends CommandBase<WorldEventManager>
{
public ClearCommand(WorldEventManager plugin)
{
super(plugin, Rank.EVENT, "clear");
super(plugin, Rank.ADMIN, "clear");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.clearEvents();
UtilPlayer.message(caller, F.main("Clans", "All world events cleared!"));
UtilPlayer.message(caller, F.main(Plugin.getName(), "All world events cleared!"));
}
}

View File

@ -17,12 +17,20 @@ public class RandomCommand extends CommandBase<WorldEventManager>
{
public RandomCommand(WorldEventManager plugin)
{
super(plugin, Rank.JNR_DEV, "random", "rand");
super(plugin, Rank.ADMIN, "random", "rand");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.randomEvent();
WorldEventType typeStarted = Plugin.randomEvent();
if (typeStarted != null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Started " + F.name(typeStarted.getName())));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Could not start World Event"));
}
}
}

View File

@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
@ -14,7 +15,7 @@ public class StartCommand extends CommandBase<WorldEventManager>
{
public StartCommand(WorldEventManager plugin)
{
super(plugin, Rank.EVENT, "start", "create");
super(plugin, Rank.ADMIN, "start", "create");
}
@Override
@ -26,20 +27,32 @@ public class StartCommand extends CommandBase<WorldEventManager>
try
{
WorldEventType eventType = WorldEventType.valueOf(args[0]);
WorldEvent event = Plugin.startEventFromType(caller.getLocation(), eventType);
WorldEvent event = Plugin.startEventFromType(eventType);
if (event == null)
{
UtilPlayer.message(caller, F.main("WorldEvent", "Error whilst starting the world event you chose."));
UtilPlayer.message(caller, F.main(Plugin.getName(), "Error whilst starting the world event you chose."));
}
else
{
UtilPlayer.message(caller, F.main("worldEvent", "Started WorldEvent " + F.elem(args[0]) + " at your current location"));
UtilPlayer.message(caller, F.main(Plugin.getName(), "Started WorldEvent " + F.elem(args[0]) + "!"));
}
}
catch (IllegalArgumentException e)
{
UtilPlayer.message(caller, F.main("WorldEvent", "Could not find a WorldEvent with the name " + F.elem(args[0])));
UtilPlayer.message(caller, F.main(Plugin.getName(), "Could not find a WorldEvent with the name " + F.elem(args[0]) + "! Available types:"));
for (WorldEventType type : WorldEventType.values())
{
UtilPlayer.message(caller, C.cBlue + "- " + C.cGray + type.toString());
}
}
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "No World Event type specified. Available types:"));
for (WorldEventType type : WorldEventType.values())
{
UtilPlayer.message(caller, C.cBlue + "- " + C.cGray + type.toString());
}
}
}

View File

@ -1,5 +1,7 @@
package mineplex.game.clans.clans.worldevent.command;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import org.bukkit.entity.Player;
import mineplex.core.command.MultiCommandBase;
@ -20,7 +22,9 @@ public class WorldEventCommand extends MultiCommandBase<WorldEventManager>
@Override
protected void Help(Player caller, String[] args)
{
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " start <type>", "Start a World Event where you're standing", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " clear", "Clears all World Events", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/" + _aliasUsed + " random", "Starts a random World Event", Rank.ADMIN));
}
}

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import mineplex.core.common.util.*;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -53,7 +54,7 @@ public class KingHill extends WorldEvent
private long _lastOnHillMessage;
private long _goldDrops;
public KingHill(WorldEventManager eventManager, Location centerLocation)
public KingHill(WorldEventManager eventManager, Location centerLocation, SkillFactory skillFactory)
{
super(eventManager.getClans().getDisguiseManager(), eventManager.getClans().getProjectile(), eventManager.getDamage(), eventManager.getBlockRestore(), eventManager.getClans().getCondition(), "King of the Hill", centerLocation);
_clansManager = eventManager.getClans();

View File

@ -8,6 +8,7 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.donation.Donor;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansDataAccessLayer;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.items.economy.GoldToken;
import mineplex.game.clans.shop.bank.BankShop;
@ -41,24 +42,26 @@ public class GoldManager extends MiniDbClientPlugin<GoldData>
public static GoldManager getInstance() { return _instance; }
private DonationManager _donationManager;
private final int _serverId;
private TransferTracker _transferTracker;
private Set<Item> _itemSet;
private Map<Player, Integer> _playerPickupMap;
private BankShop _bankShop;
private final GoldRepository _repository;
public GoldManager(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager)
public GoldManager(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager, ClansDataAccessLayer dataAccessLayer)
{
super("Clans Gold", plugin.getPlugin(), clientManager);
_instance = this;
_donationManager = donationManager;
_serverId = dataAccessLayer.getRepository().getServerId();
_transferTracker = new TransferTracker();
_itemSet = new HashSet<Item>();
_playerPickupMap = new HashMap<Player, Integer>();
_bankShop = new BankShop(plugin, clientManager, donationManager);
_repository = new GoldRepository(plugin.getPlugin());
_repository = new GoldRepository(_serverId);
}
@Override
@ -396,12 +399,15 @@ public class GoldManager extends MiniDbClientPlugin<GoldData>
@Override
public String getQuery(int accountId, String uuid, String name) {
return "SELECT gold FROM accounts WHERE id = '" + accountId + "';";
return "SELECT gold FROM clansGold WHERE id = '" + accountId + "' AND serverId=" + _serverId + ";";
}
@Override
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException {
Get(playerName).setBalance(resultSet.getInt(1));
if (resultSet.next())
{
Get(playerName).setBalance(resultSet.getInt(1));
}
}
@Override

View File

@ -1,31 +1,47 @@
package mineplex.game.clans.economy;
import mineplex.core.common.util.Callback;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.DatabaseRunnable;
import mineplex.serverdata.database.column.ColumnInt;
import org.bukkit.plugin.java.JavaPlugin;
public class GoldRepository extends MinecraftRepository {
private static final String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE id = ? && gold >= ?;";
private static final String SET_ACCOUNT_GOLD = "UPDATE accounts SET gold = ? WHERE id = ?;";
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public GoldRepository(JavaPlugin plugin) {
super(plugin, DBPool.getAccount());
public class GoldRepository {
private static final String CREATE_TABLE = "CREATE TABLE clansGold (serverId int(11) not null, id int(11) not null, gold int not null, primary key (serverId, id), foreign key (serverId) references clanServer(id), foreign key (id) references accounts(id))";
private static final String UPDATE_ACCOUNT_GOLD = "INSERT INTO clansGold (serverId, id, gold) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE gold=gold+?";
private static final String SET_ACCOUNT_GOLD = "INSERT INTO clansGold (serverId, id, gold) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE gold=?";
private final int _serverId;
public GoldRepository(int serverId) {
_serverId = serverId;
}
public void rewardGold(final Callback<Boolean> callback, final int accountId, final int gold)
{
handleDatabaseCall(new DatabaseRunnable(new Runnable()
try (Connection connection = DBPool.getAccount().getConnection())
{
public void run()
PreparedStatement statement = connection.prepareStatement(UPDATE_ACCOUNT_GOLD);
statement.setInt(1, _serverId);
statement.setInt(2, accountId);
statement.setInt(3, gold);
statement.setInt(4, gold);
statement.executeUpdate();
if (callback != null)
{
ColumnInt min = new ColumnInt("gold", gold < 0 ? -gold : 0);
boolean success = executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId), min) > 0;
callback.run(success);
callback.run(true);
}
}), "Error updating player gold amount in DonationRepository : ");
} catch (SQLException e) {
e.printStackTrace();
if (callback != null)
{
callback.run(false);
}
}
}
public void setGold(final Callback<Boolean> callback, final int accountId, final int gold)
@ -34,19 +50,27 @@ public class GoldRepository extends MinecraftRepository {
{
throw new IllegalArgumentException("gold cannot be negative");
}
handleDatabaseCall(new DatabaseRunnable(new Runnable()
try (Connection connection = DBPool.getAccount().getConnection())
{
public void run()
PreparedStatement statement = connection.prepareStatement(SET_ACCOUNT_GOLD);
statement.setInt(1, _serverId);
statement.setInt(2, accountId);
statement.setInt(3, gold);
statement.setInt(4, gold);
statement.executeUpdate();
if (callback != null)
{
boolean success = executeUpdate(SET_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId)) > 0;
callback.run(success);
callback.run(true);
}
}), "Error updating player gold amount in DonationRepository : ");
} catch (SQLException e) {
e.printStackTrace();
if (callback != null)
{
callback.run(false);
}
}
}
@Override
protected void initialize() {}
@Override
protected void update() {}
}

View File

@ -4,6 +4,38 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import mineplex.core.MiniPlugin;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEvent;
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.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.weight.Weight;
import mineplex.core.common.weight.WeightSet;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.ClansWaterPlaceEvent;
import mineplex.game.clans.clans.event.IronDoorOpenEvent;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.items.GearManager;
import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
import mineplex.minecraft.game.classcombat.Skill.event.BlockTossEvent;
import mineplex.minecraft.game.classcombat.Skill.event.BlockTossLandEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import mineplex.minecraft.game.core.damage.DamageManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
@ -14,7 +46,6 @@ import org.bukkit.Sound;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
@ -47,38 +78,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Dye;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEvent;
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.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.common.weight.Weight;
import mineplex.core.common.weight.WeightSet;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.ClansWaterPlaceEvent;
import mineplex.game.clans.clans.event.IronDoorOpenEvent;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
import mineplex.minecraft.game.classcombat.Skill.event.BlockTossEvent;
import mineplex.minecraft.game.classcombat.Skill.event.BlockTossLandEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import mineplex.minecraft.game.core.damage.DamageManager;
public class Gameplay extends MiniPlugin
{
private ClansManager _clansManager;
@ -357,9 +356,19 @@ public class Gameplay extends MiniPlugin
@EventHandler
public void WebBreak(BlockDamageEvent event)
{
if (event.isCancelled()) return;
if (event.isCancelled())
{
return;
}
if (_clansManager.getWorldEvent().isInEvent(event.getBlock().getLocation()))
{
return;
}
if (event.getBlock().getType() == Material.WEB) event.setInstaBreak(true);
if (event.getBlock().getType() == Material.WEB)
{
event.setInstaBreak(true);
}
}
@EventHandler
@ -818,6 +827,12 @@ public class Gameplay extends MiniPlugin
return;
}
if (GearManager.isCustomItem(item))
{
UtilPlayer.message(player, F.main("Repair", "You cannot repair " + F.item(item.getItemMeta().getDisplayName()) + "."));
return;
}
int repairs = ItemStackFactory.Instance.GetLoreVar(item, "Repaired", 0);
boolean canRepair = canRepair(item);

View File

@ -186,6 +186,11 @@ public class CustomItem implements Listener
meta.setLore(lore);
item.setItemMeta(meta);
if (_dullEnchantment)
{
UtilInv.addDullEnchantment(item);
}
GearManager.writeNBT(this, item);
}
@ -201,7 +206,7 @@ public class CustomItem implements Listener
name += word.substring(0, 1).toUpperCase() + word.substring(1) + " ";
}
return name;
return name.trim();
}
public Material getMaterial()
@ -213,4 +218,13 @@ public class CustomItem implements Listener
{
return _attributes;
}
public void setMaterial(Material material)
{
if (_material == null)
{
_displayName = prettifyName(material);
}
_material = material;
}
}

View File

@ -1,8 +1,6 @@
package mineplex.game.clans.items;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
@ -12,30 +10,11 @@ import java.util.Map;
import java.util.Set;
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.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.weight.Weight;
import mineplex.core.common.weight.WeightSet;
@ -65,6 +44,7 @@ import mineplex.game.clans.items.attributes.weapon.HasteAttribute;
import mineplex.game.clans.items.attributes.weapon.JaggedAttribute;
import mineplex.game.clans.items.attributes.weapon.SharpAttribute;
import mineplex.game.clans.items.commands.GearCommand;
import mineplex.game.clans.items.commands.RuneCommand;
import mineplex.game.clans.items.economy.GoldToken;
import mineplex.game.clans.items.legendaries.AlligatorsTooth;
import mineplex.game.clans.items.legendaries.GiantsBroadsword;
@ -75,14 +55,35 @@ import mineplex.game.clans.items.legendaries.MeridianScepter;
import mineplex.game.clans.items.legendaries.WindBlade;
import mineplex.game.clans.items.rares.RareItem;
import mineplex.game.clans.items.rares.RunedPickaxe;
import mineplex.game.clans.items.runes.RuneManager;
import mineplex.game.clans.items.smelting.SmeltingListener;
import mineplex.game.clans.items.ui.GearShop;
import mineplex.serverdata.serialization.RuntimeTypeAdapterFactory;
import net.minecraft.server.v1_8_R3.NBTBase;
import net.minecraft.server.v1_8_R3.NBTTagByte;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.NBTTagString;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutSetSlot;
import net.minecraft.server.v1_8_R3.PacketPlayOutWindowItems;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
/**
* Handles converting legendary itemstacks to their respective CustomItem objects
*/
@ -92,14 +93,14 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
private static final Gson GSON;
// Weightings for randomly selecting number of attributes (1, 2, 3)
private static final WeightSet<Integer> ATTRIBUTE_WEIGHTS = new WeightSet<>(
private static final WeightSet<Integer> ATTRIBUTE_WEIGHTS = new WeightSet<Integer>(
new Weight<>(3, 3),
new Weight<>(20, 2),
new Weight<>(77, 1)
);
// Weightings for randomly selecting item type (legendary/weapon/armor/bow)
private static final WeightSet<ItemType> TYPE_WEIGHTS = new WeightSet<>(
private static final WeightSet<ItemType> TYPE_WEIGHTS = new WeightSet<ItemType>(
new Weight<>(6, ItemType.LEGENDARY),
new Weight<>(9, ItemType.RARE),
new Weight<>(46 - 9, ItemType.ARMOR),
@ -215,6 +216,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
private Map<Player, PlayerGear> _playerGears = new HashMap<>();
private GearShop _shop;
private RuneManager _rune;
public GearManager(JavaPlugin plugin, PacketHandler packetHandler, CoreClientManager clientManager, DonationManager donationManager)
{
@ -228,6 +230,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
_instance = this;
_shop = new GearShop(this, clientManager, donationManager);
_rune = new RuneManager("Rune", plugin);
// Register listeners
UtilServer.getServer().getPluginManager().registerEvents(new ItemListener(getPlugin()), getPlugin());
@ -242,6 +245,12 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
public void addCommands()
{
addCommand(new GearCommand(this));
addCommand(new RuneCommand(this));
}
public RuneManager getRuneManager()
{
return _rune;
}
/**
@ -303,8 +312,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
factory.setType(Material.BOW);
}
if (itemType != ItemType.LEGENDARY) // Only non-legendaries have
// attributes
if (itemType != ItemType.LEGENDARY || (UtilMath.random.nextDouble() <= .35 && factory.getMaterial() != Material.RECORD_6)) // Melee Legendaries have a chance to spawn with attributes
{
AttributeContainer attributes = new AttributeContainer();
generateAttributes(attributes, itemType, attributeCount);
@ -352,6 +360,9 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
case WEAPON:
sampleAttribute = instantiate(WEAPON_ATTRIBUTES.generateRandom());
break;
case LEGENDARY:
sampleAttribute = instantiate(WEAPON_ATTRIBUTES.generateRandom());
break;
case BOW:
sampleAttribute = instantiate(BOW_ATTRIBUTES.generateRandom());
break;
@ -366,14 +377,25 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
attempts++;
}
container.addAttribute(attribute);
if (attribute != null)
{
container.addAttribute(attribute);
}
}
}
public void spawnItem(Location location)
{
CustomItem item = generateItem();
if (item.getMaterial() == Material.RECORD_4 || item.getMaterial() == Material.GOLD_RECORD || item.getMaterial() == Material.RECORD_3 || item.getMaterial() == Material.RECORD_5 || item.getMaterial() == Material.RECORD_6 || item.getMaterial() == Material.GREEN_RECORD)
{
UtilFirework.playFirework(location, Type.BALL, Color.RED, true, false);
}
else
{
UtilFirework.playFirework(location, Type.BALL, Color.AQUA, true, false);
}
location.getWorld().dropItem(location, item.toItemStack());
}
@ -667,7 +689,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
List<String> cleansed = new ArrayList<>();
for (String s : input)
{
if (s.startsWith(ITEM_SERIALIZATION_TAG))
if (!s.startsWith(ITEM_SERIALIZATION_TAG))
{
cleansed.add(s);
}

View File

@ -68,7 +68,7 @@ public class AttributeContainer
if (_suffix != null)
{
itemName += "of " + _suffix.getDisplayName();
itemName += " of " + _suffix.getDisplayName();
}
return itemName;

View File

@ -0,0 +1,58 @@
package mineplex.game.clans.items.commands;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.items.runes.RuneManager;
import mineplex.game.clans.items.runes.RuneManager.RuneAttribute;
import org.bukkit.entity.Player;
/**
* Command to give yourself a rune
*/
public class RuneCommand extends CommandBase<GearManager>
{
private RuneManager _rune;
public RuneCommand(GearManager plugin)
{
super(plugin, Rank.ADMIN, "rune", "giverune", "getrune");
}
@Override
public void Execute(Player caller, String[] args)
{
if (_rune == null)
{
_rune = Plugin.getRuneManager();
}
if (args.length < 1)
{
UtilPlayer.message(caller, F.main("Rune", "Usage: /" + _aliasUsed + " <Rune Type>"));
UtilPlayer.message(caller, F.main(Plugin.getName(), "Available types:"));
for (RuneAttribute rune : RuneAttribute.values())
{
UtilPlayer.message(caller, C.cBlue + "- " + C.cGray + rune.toString());
}
return;
}
RuneAttribute rune = RuneAttribute.getFromString(args[0]);
if (rune == null)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "Invalid rune type! Available types:"));
for (RuneAttribute type : RuneAttribute.values())
{
UtilPlayer.message(caller, C.cBlue + "- " + C.cGray + type.toString());
}
return;
}
UtilInv.insert(caller, _rune.getRune(rune));
UtilPlayer.message(caller, F.main("Rune", "You have been given a(n) " + F.elem(rune.getDisplay()) + " rune!"));
}
}

View File

@ -55,7 +55,7 @@ public class HyperAxe extends LegendaryItem
{
event.SetIgnoreRate(true);
event.AddMod("Hyper Axe", 9);
event.AddMod("Hyper Axe", 5);
_lastAttack = System.currentTimeMillis();
}
else

View File

@ -17,7 +17,6 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClansManager;
@ -67,7 +66,7 @@ public class MeridianScepter extends LegendaryItem
return;
}
if (Recharge.Instance.use(wielder, "Meridian Scepter", 4000, true, true))
if (Recharge.Instance.use(wielder, "Meridian Scepter", 2000, true, true))
{
fire(wielder);
@ -93,22 +92,22 @@ public class MeridianScepter extends LegendaryItem
{
for (Entity cur : projectile.getWorld().getEntities())
{
if (cur == shooter || !(cur instanceof Player) || (cur instanceof Player && UtilPlayer.isSpectator(cur)))
if (cur == shooter || !(cur instanceof LivingEntity) || (cur instanceof Player && UtilPlayer.isSpectator(cur)))
continue;
Player player = (Player) cur;
LivingEntity ent = (LivingEntity) cur;
// If they are less than 0.5 blocks away
if (player.getEyeLocation().subtract(0, .3, 0).distance(projectile) <= 2)
if (ent.getEyeLocation().subtract(0, .3, 0).distance(projectile) <= 2)
{
AttackAnimation aa = new AttackAnimation(player, shooter);
AttackAnimation aa = new AttackAnimation(ent, shooter);
int i = UtilServer.getServer().getScheduler().scheduleSyncRepeatingTask(UtilServer.getPlugin(), () -> {
aa.update();
}, 0, 1);
_animations.put(aa, i);
UtilPlayer.message(player, F.main("Clans", F.elem(shooter.getName()) + " hit you with a " + F.elem("Meridian Scepter") + C.mBody + "."));
UtilPlayer.message(shooter, F.main("Clans", "You hit " + F.elem(player.getName()) + " with your " + F.elem("Meridian Scepter") + C.mBody + "."));
UtilPlayer.message(ent, F.main("Clans", F.elem(shooter.getName()) + " hit you with a " + F.elem("Meridian Scepter") + C.mBody + "."));
UtilPlayer.message(shooter, F.main("Clans", "You hit " + F.elem(ent.getName()) + " with your " + F.elem("Meridian Scepter") + C.mBody + "."));
}
}
@ -199,7 +198,7 @@ public class MeridianScepter extends LegendaryItem
Vector newDirection = closestPlayer.getLocation().add(0, 1, 0).toVector()
.subtract(projectile.toVector());
direction.add(newDirection.normalize().multiply(0.01)).normalize().multiply(0.15);
direction.add(newDirection.normalize().multiply(0.02)).normalize().multiply(0.25);
}
projectile.add(direction);
@ -254,12 +253,13 @@ public class MeridianScepter extends LegendaryItem
private class AttackAnimation
{
private Player _hit, _shooter;
private LivingEntity _hit;
private Player _shooter;
private double _step;
private double _radius;
private long _start, _lastStepIncrease;
public AttackAnimation(Player hit, Player shooter)
public AttackAnimation(LivingEntity hit, Player shooter)
{
_step = 0;
_start = System.currentTimeMillis();
@ -271,25 +271,25 @@ public class MeridianScepter extends LegendaryItem
public void update()
{
if (_hit == null)
if (_hit == null || !_hit.isValid() || _hit.isDead() || ((_hit instanceof Player) && !((Player)_hit).isOnline()))
{
end();
return;
}
if (UtilTime.elapsed(_lastStepIncrease, UtilTime.convert(1, TimeUnit.SECONDS, TimeUnit.MILLISECONDS)))
if (UtilTime.elapsed(_lastStepIncrease, 500))
{
_step++;
_lastStepIncrease = System.currentTimeMillis();
}
drawHelix();
if (UtilTime.elapsed(_start, 4000))
if (UtilTime.elapsed(_start, 2000))
{
_hit.getWorld().strikeLightningEffect(_hit.getLocation());
ClansManager.getInstance().getDamageManager().NewDamageEvent(_hit, _shooter, null,
DamageCause.CUSTOM, 6, false, true, true,
DamageCause.CUSTOM, 8, false, true, true,
_shooter.getName(), "Meridian Scepter");
ClansManager.getInstance().getCondition().Factory().Blind("Meridian Scepter", _hit, _shooter, 1, 0, true, true, true);
ClansManager.getInstance().getCondition().Factory().Blind("Meridian Scepter", _hit, _shooter, 3, 0, true, true, false);
end();
return;
}

View File

@ -77,7 +77,7 @@ public class RunedPickaxe extends RareItem
{
return;
}
RunedPickaxe pick = (RunedPickaxe) gear.getWeapon();
String playerClan = ClansManager.getInstance().getClanUtility().getClanByPlayer(event.getPlayer()) == null ? null : ClansManager.getInstance().getClanUtility().getClanByPlayer(event.getPlayer()).getName();
@ -90,6 +90,9 @@ public class RunedPickaxe extends RareItem
if (event.getBlock().getType() == Material.BEDROCK)
return;
if (ClansManager.getInstance().getNetherManager().getNetherWorld().equals(event.getBlock().getWorld()))
return;
if (!UtilTime.elapsed(pick._instamineEnabled, 12000))
{
event.getBlock().breakNaturally();

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