Merge remote-tracking branch 'origin/develop' into project-cosmetics

Conflicts:
	Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java
This commit is contained in:
xGamingDudex 2016-05-05 21:03:15 +02:00
commit 17a4517e71
24 changed files with 490 additions and 417 deletions

View File

@ -0,0 +1,61 @@
package mineplex.core.common.events;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Called just before UtilPlayer#message sends out a message to the specified Player.
*/
public class PlayerMessageEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _player;
private String _message;
private boolean _cancelled;
public PlayerMessageEvent(Player player, String message)
{
_player = player;
_message = message;
}
public Player getPlayer()
{
return _player;
}
public boolean isCancelled()
{
return _cancelled;
}
public String getMessage()
{
return _message;
}
public String getUnformattedMessage()
{
return ChatColor.stripColor(_message);
}
public void setCancelled(boolean cancelled)
{
_cancelled = cancelled;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -30,6 +30,7 @@ import org.bukkit.util.BlockIterator;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import mineplex.core.common.MinecraftVersion; import mineplex.core.common.MinecraftVersion;
import mineplex.core.common.events.PlayerMessageEvent;
public class UtilPlayer public class UtilPlayer
{ {
@ -310,7 +311,13 @@ public class UtilPlayer
if (wiki) if (wiki)
message = UtilWiki.link(message); message = UtilWiki.link(message);
*/ */
PlayerMessageEvent event = UtilServer.CallEvent(new PlayerMessageEvent((Player) client, message));
if (event.isCancelled())
return;
((Player) client).sendMessage(message); ((Player) client).sendMessage(message);
} }

View File

@ -141,7 +141,12 @@ public class UtilServer
public static boolean IsOnline(String name) public static boolean IsOnline(String name)
{ {
return !UtilStreams.IsEmpty(getPlayersCollection().stream().filter(player -> player.getName().equals(name))); return !UtilStreams.IsEmpty(getPlayersCollection().stream().filter(name::equals));
}
public static boolean IsOffline(String name)
{
return !UtilStreams.IsEmpty(getPlayersCollection().stream().filter(name::equals));
} }
public static Player GetPlayer(String name) public static Player GetPlayer(String name)

View File

@ -2,10 +2,13 @@ package mineplex.core.common.util;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import com.google.common.collect.Lists;
public class UtilStreams public class UtilStreams
{ {
public static boolean IsEmpty(Stream<?> stream) public static boolean IsEmpty(Stream<?> stream)
@ -55,4 +58,9 @@ public class UtilStreams
return read; return read;
} }
public static <T> List<T> ToList(Stream<T> filter)
{
return Lists.newArrayList((T[]) ToArray(filter));
}
} }

View File

@ -24,6 +24,7 @@ import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv;
public class ItemBuilder public class ItemBuilder
{ {
@ -56,6 +57,7 @@ public class ItemBuilder
private Material _mat; private Material _mat;
private String _title = null; private String _title = null;
private boolean _unbreakable; private boolean _unbreakable;
private boolean _dullEnchantment;
private String _playerHeadName = null; private String _playerHeadName = null;
private HashSet<ItemFlag> _itemFlags = new HashSet<ItemFlag>(); private HashSet<ItemFlag> _itemFlags = new HashSet<ItemFlag>();
@ -268,6 +270,11 @@ public class ItemBuilder
item.addUnsafeEnchantments(_enchants); item.addUnsafeEnchantments(_enchants);
if (_dullEnchantment)
{
UtilInv.addDullEnchantment(item);
}
return item; return item;
} }
@ -413,4 +420,11 @@ public class ItemBuilder
return this; return this;
} }
public ItemBuilder addDullEnchantment(boolean dullEnchantment)
{
_dullEnchantment = dullEnchantment;
return this;
}
} }

View File

@ -41,6 +41,7 @@ import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater; import mineplex.core.updater.Updater;
import mineplex.core.visibility.VisibilityManager; import mineplex.core.visibility.VisibilityManager;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ban.ClansBanManager;
import mineplex.game.clans.items.GearManager; import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.shop.building.BuildingShop; import mineplex.game.clans.shop.building.BuildingShop;
import mineplex.game.clans.shop.farming.FarmingShop; import mineplex.game.clans.shop.farming.FarmingShop;
@ -112,7 +113,7 @@ public class Clans extends JavaPlugin
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName()); Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
// ClansBanManager clansBans = new ClansBanManager(this, _clientManager, _donationManager); ClansBanManager clansBans = new ClansBanManager(this, _clientManager, _donationManager);
Punish punish = new Punish(this, webServerAddress, _clientManager); Punish punish = new Punish(this, webServerAddress, _clientManager);
AntiHack.Initialize(this, punish, portal, preferenceManager, _clientManager); AntiHack.Initialize(this, punish, portal, preferenceManager, _clientManager);
@ -135,8 +136,8 @@ public class Clans extends JavaPlugin
ResourcePackManager resourcePackManager = new ResourcePackManager(this, portal); ResourcePackManager resourcePackManager = new ResourcePackManager(this, portal);
resourcePackManager.setResourcePack(new Pair[] resourcePackManager.setResourcePack(new Pair[]
{ {
Pair.create(MinecraftVersion.Version1_8, "http://phinary.ca/ResClans.zip"), Pair.create(MinecraftVersion.Version1_8, "http://file.mineplex.com/ResClans.zip"),
Pair.create(MinecraftVersion.Version1_9, "http://phinary.ca/ResClans19.zip") Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResClans19.zip")
}, true); }, true);
// Enable custom-gear related managers // Enable custom-gear related managers
@ -144,7 +145,7 @@ public class Clans extends JavaPlugin
GearManager customGear = new GearManager(this, packetHandler, _clientManager, _donationManager); GearManager customGear = new GearManager(this, packetHandler, _clientManager, _donationManager);
HologramManager hologram = new HologramManager(this, packetHandler); 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, webServerAddress);
new Recipes(this); new Recipes(this);
new Farming(this); new Farming(this);
new BuildingShop(_clansManager, _clientManager, _donationManager); new BuildingShop(_clansManager, _clientManager, _donationManager);

View File

@ -9,14 +9,11 @@ import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.UUID; import java.util.UUID;
import mineplex.core.recharge.Recharge;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Horse; import org.bukkit.entity.Horse;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
@ -47,6 +44,7 @@ import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.common.Pair; import mineplex.core.common.Pair;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.events.PlayerMessageEvent;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
@ -73,6 +71,7 @@ import mineplex.core.preferences.PreferencesManager;
import mineplex.core.projectile.ProjectileManager; import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish; import mineplex.core.punish.Punish;
import mineplex.core.punish.PunishClient; import mineplex.core.punish.PunishClient;
import mineplex.core.recharge.Recharge;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
import mineplex.core.task.TaskManager; import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport; import mineplex.core.teleport.Teleport;
@ -81,6 +80,7 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.Clans; import mineplex.game.clans.Clans;
import mineplex.game.clans.clans.ClanTips.TipType; import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansUtility.ClanRelation; import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.ban.ClansBanManager;
import mineplex.game.clans.clans.commands.ClanManagementCommand; import mineplex.game.clans.clans.commands.ClanManagementCommand;
import mineplex.game.clans.clans.commands.ClansAllyChatCommand; import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
import mineplex.game.clans.clans.commands.ClansChatCommand; import mineplex.game.clans.clans.commands.ClansChatCommand;
@ -226,19 +226,19 @@ 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; public String UserDataDir = UtilServer.getServer().getWorlds().get(0).getWorldFolder().getPath() + File.separator + ".." + File.separator + "CLANS_USER_DATA" + File.separator;
/*private ClansBanManager _clansBans;*/ private ClansBanManager _clansBans;
public ClanTips ClanTips; public ClanTips ClanTips;
// Spawn area // 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, String webServerAddress)
{ {
super("Clans Manager", plugin); super("Clans Manager", plugin);
_instance = this; _instance = this;
/*_clansBans = clansBans;*/ _clansBans = clansBans;
_punish = punish; _punish = punish;
_incognitoManager = incognitoManager; _incognitoManager = incognitoManager;
@ -354,7 +354,10 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{ {
loadClan(token); loadClan(token);
} }
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict");
// new ClaimVisualizer(plugin, this); // new ClaimVisualizer(plugin, this);
// RedisDataRepository(ConnectionData writeConn, ConnectionData // RedisDataRepository(ConnectionData writeConn, ConnectionData
@ -407,7 +410,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
hologram.start(); hologram.start();
} }
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict");
_siegeManager = new SiegeManager(this); _siegeManager = new SiegeManager(this);
// _netherManager = new NetherManager(this); // _netherManager = new NetherManager(this);
@ -603,21 +605,21 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{ {
event.setJoinMessage(null); event.setJoinMessage(null);
/*if (_clansBans.willBeKicked(event.getPlayer())) if (_clansBans.willBeKicked(event.getPlayer()))
{ {
return; return;
}*/ }
if (_incognitoManager.Get(event.getPlayer()).Status) if (_incognitoManager.Get(event.getPlayer()).Status)
{ {
return; return;
} }
/*_clansBans.runAfterLoad(event.getPlayer().getName(), () -> { _clansBans.runAfterLoad(event.getPlayer().getName(), () -> {
if (_clansBans.Get(event.getPlayer().getName()).isBanned()) if (_clansBans.Get(event.getPlayer().getName()).isBanned())
{ {
return; return;
}*/ }
for (Player other : UtilServer.getPlayers()) for (Player other : UtilServer.getPlayers())
{ {
@ -629,7 +631,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
other.sendMessage(F.sys("Join", event.getPlayer().getName())); other.sendMessage(F.sys("Join", event.getPlayer().getName()));
} }
/*});*/ });
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
@ -642,11 +644,11 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return; return;
} }
/*if (_clansBans.willBeKicked(event.getPlayer())) if (_clansBans.Get(event.getPlayer().getName()) != null && _clansBans.Get(event.getPlayer().getName()).isBanned())
{ {
return; return;
}*/ }
for (Player other : UtilServer.getPlayers()) for (Player other : UtilServer.getPlayers())
{ {
if (_tutorial.inTutorial(other)) if (_tutorial.inTutorial(other))
@ -655,7 +657,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
continue; continue;
} }
other.sendMessage(F.sys("Quit", event.getPlayer().getName())); other.sendMessage(F.sys("Quit ", event.getPlayer().getName()));
} }
} }
@ -668,12 +670,12 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return; return;
} }
/*if (_clansBans.willBeKicked(event.getPlayer())) if (_clansBans.willBeKicked(event.getPlayer()))
{ {
return; return;
}*/ }
if (event.getReason().contains("You are banned from Clans")) if (event.getReason().contains("banned from Clans"))
{ {
return; return;
} }
@ -853,7 +855,13 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{ {
if (clan == null) if (clan == null)
{ {
UtilServer.broadcast(String.format(rank + C.cYellow + "%s " + C.cWhite + "%s", event.getPlayer().getName(), _chat.getFilteredMessage(event.getPlayer(), event.getMessage()))); for (Player other : event.getRecipients())
{
if (_tutorial.inTutorial(other))
continue;
UtilPlayer.message(other, String.format(rank + C.cYellow + "%s " + C.cWhite + "%s", event.getPlayer().getName(), event.getMessage()));
}
return; return;
} }
@ -901,28 +909,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void handlePlayerChat(AsyncPlayerChatEvent event) public void handlePlayerChat(AsyncPlayerChatEvent event)
{ {
// PunishClient punishclient = _punish.GetClient(event.getPlayer().getName());
//
// if (punishclient != null && punishclient.IsMuted())
// {
// return;
// }
//
// if (_chat.SilenceCheck(event.getPlayer()))
// {
// return;
// }
// MessageData lastMessage = _chat.lastMessage(event.getPlayer());
// long chatSlowTime = 1000L * _chat.getChatSlow();
// long timeDiff = System.currentTimeMillis() - lastMessage.getTimeSent();
// if (timeDiff < chatSlowTime && !_clientManager.Get(event.getPlayer()).GetRank().has(Rank.HELPER))
// {
//
// }
ClientClan client = Get(event.getPlayer()); ClientClan client = Get(event.getPlayer());
if (client == null) if (client == null)
@ -1302,17 +1288,23 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
} }
} }
@EventHandler
public void message(PlayerMessageEvent event)
{
if(!_tutorial.inTutorial(event.getPlayer()))
{
return;
}
if (event.getMessage().startsWith(C.cBlue + "Death>"))
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void handleClansDeath(PlayerDeathEvent event) public void handleClansDeath(PlayerDeathEvent event)
{ {
event.setDeathMessage(null);
for(Player player : UtilServer.getPlayers())
{
if(!_tutorial.inTutorial(player))
player.sendMessage(event.getDeathMessage());
}
PlayerClan playerClan; PlayerClan playerClan;
PlayerClan killerClan = null; PlayerClan killerClan = null;

View File

@ -6,6 +6,9 @@ import java.util.UUID;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
/**
* Stores the information about a ban in Clans.
*/
public class ClansBan public class ClansBan
{ {
private int _id; private int _id;
@ -90,4 +93,9 @@ public class ClansBan
{ {
return _uuid; return _uuid;
} }
public void remove()
{
_removed = true;
}
} }

View File

@ -0,0 +1,26 @@
package mineplex.game.clans.clans.ban;
/**
* Stores the data provided through the /cban (Clans ban) command for use further in the plugin.
*/
public class ClansBanCache
{
private String _victim;
private String _reason;
public ClansBanCache(String victim, String reason)
{
_victim = victim;
_reason = reason;
}
public String getVictim()
{
return _victim;
}
public String getReason()
{
return _reason;
}
}

View File

@ -1,17 +1,22 @@
package mineplex.game.clans.clans.ban; package mineplex.game.clans.clans.ban;
import java.util.List; import java.util.Set;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
/**
* Signifies a player on clans, and a Set of their current clan bans.
*/
public class ClansBanClient public class ClansBanClient
{ {
public String Name;
public String UUID; public String UUID;
public List<ClansBan> Bans; public Set<ClansBan> Bans;
public ClansBanClient(String uuid, List<ClansBan> bans) public ClansBanClient(String name, String uuid, Set<ClansBan> bans)
{ {
Name = name;
UUID = uuid; UUID = uuid;
Bans = bans; Bans = bans;
} }
@ -75,7 +80,7 @@ public class ClansBanClient
continue; continue;
} }
if (ban.getTimeLeft() > longest.getTimeLeft()) if (ban.getTimeLeft() > longest.getTimeLeft() || ban.isPermanent())
{ {
longest = ban; longest = ban;
} }

View File

@ -6,7 +6,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -17,16 +16,15 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor; import mineplex.core.account.ILoginProcessor;
import mineplex.core.common.DefaultHashMap; import mineplex.core.common.DefaultHashMap;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilStreams;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
@ -41,7 +39,7 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
private ClansBanRepository _repository; private ClansBanRepository _repository;
private Map<String, ClansBanClient> _clients; private Map<String, ClansBanClient> _clients;
private Map<String, Pair<String, String>> _cache; private Map<String, ClansBanCache> _cache;
private DefaultHashMap<String, List<Runnable>> _runAfterLoad; private DefaultHashMap<String, List<Runnable>> _runAfterLoad;
private ClansBanShop _shop; private ClansBanShop _shop;
@ -55,7 +53,7 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
_clientManager = clientManager; _clientManager = clientManager;
_repository = new ClansBanRepository(plugin, this); _repository = new ClansBanRepository(plugin);
_clients = new HashMap<>(); _clients = new HashMap<>();
_cache = new HashMap<>(); _cache = new HashMap<>();
@ -85,29 +83,30 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
} }
player.kickPlayer(reason); player.kickPlayer(reason);
runSyncLater(() -> {
_toKick.remove(name);
}, 20l);
}); });
} }
if (!event.getType().equals(UpdateType.MIN_01)) if (event.getType().equals(UpdateType.MIN_01))
{ {
return; synchronized (_lock)
} {
UtilStreams.ToList(_clients.keySet().stream().filter(UtilServer::IsOnline)).forEach(this::UnloadClient);
synchronized (_lock) }
{
List<String> purge = Lists.newArrayList();
_clients.keySet().stream().filter(name -> Bukkit.getPlayer(name) == null).forEach(purge::add);
purge.forEach(this::UnloadClient);
} }
} }
public void ban(ClansBanClient client, String name, String admin, long time, String reason, Callback<ClansBanClient> callback) public void ban(ClansBanClient client, String admin, long time, String reason, Callback<ClansBanClient> callback)
{ {
_repository.ban(UUID.fromString(client.UUID), admin, time, reason, time == -1); runAsync(() -> {
_repository.ban(UUID.fromString(client.UUID), admin, time, reason, time == -1, ban -> {
LoadClient(name, callback); client.Bans.add(ban);
callback.run(client);
});
});
} }
public CoreClientManager getClientManager() public CoreClientManager getClientManager()
@ -154,21 +153,7 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
public void UnloadClient(ClansBanClient client) public void UnloadClient(ClansBanClient client)
{ {
synchronized (_lock) UnloadClient(client.Name);
{
String name = "";
for (Entry<String, ClansBanClient> entry : _clients.entrySet())
{
if (entry.getValue().equals(client))
{
name = entry.getKey();
break;
}
}
_clients.remove(name);
}
} }
public void UnloadClient(String name) public void UnloadClient(String name)
@ -179,17 +164,24 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
} }
} }
public void LoadClient(final String name, Callback<ClansBanClient> callback) public void LoadClient(String name, Callback<ClansBanClient> callback)
{ {
if (_clients.containsKey(name)) if (_clients.containsKey(name))
{
System.out.println("Clans Bans> Soft Warning: Loading client even though client is already loaded.");
_clients.remove(name); _clients.remove(name);
}
GetRepository().loadBans(name, client -> { GetRepository().loadClient(name, client -> {
synchronized (_lock) synchronized (_lock)
{ {
_clients.put(name, client); _clients.put(name.toLowerCase(), client);
System.out.println("> CLIENTS: " + _clients); System.out.println("> CLIENTS: " + _clients);
if (callback != null) callback.run(client);
if (callback != null)
{
callback.run(client);
}
} }
}); });
} }
@ -207,12 +199,12 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
return _shop; return _shop;
} }
public void cache(Player player, String playerName, String reason) public void cache(Player player, String victim, String reason)
{ {
_cache.put(player.getName(), Pair.create(playerName, reason)); _cache.put(player.getName(), new ClansBanCache(victim, reason));
} }
public Pair<String, String> getCachedData(Player player) public ClansBanCache getCachedData(Player player)
{ {
return _cache.get(player.getName()); return _cache.get(player.getName());
} }
@ -222,50 +214,45 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
_cache.remove(name); _cache.remove(name);
} }
public void unban(ClansBanClient target, ClansBan ban, String name, Callback<ClansBanClient> callback) public void unban(ClansBanClient target, ClansBan ban, Callback<ClansBanClient> callback)
{ {
if (!target.UUID.equals(ban.getUUID().toString())) if (!target.UUID.equals(ban.getUUID().toString()))
{ {
return; return;
} }
ban.remove();
_repository.removeBan(ban); _repository.removeBan(ban);
LoadClient(name, callback); callback.run(target);
} }
public boolean willBeKicked(Player player) public boolean willBeKicked(Player player)
{ {
return _toKick.containsKey(player.getName()); return _toKick.containsKey(player.getName());
} }
public void queueToKick(Player target, String reason)
{
_toKick.put(target.getName(), reason);
}
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
{ {
_repository.loadBans(playerName, client -> { LoadClient(playerName, client -> {
if (client.isBanned()) if (client.isBanned())
{ {
String time = UtilTime.convertString(client.getLongestBan().getTimeLeft(), 0, TimeUnit.FIT); String time = UtilTime.convertString(client.getLongestBan().getTimeLeft(), 0, TimeUnit.FIT);
if (client.getLongestBan().isPermanent()) if (client.getLongestBan().isPermanent())
{
time = "Permanent"; time = "Permanent";
}
String reason = C.cRedB + "You are banned from Clans for " + time + String reason = C.cRedB + "You are banned from Clans for " + time +
"\n" + C.cWhite + client.getLongestBan().getReason(); "\n" + C.cWhite + client.getLongestBan().getReason();
_toKick.put(playerName, reason); _toKick.put(playerName, reason);
ClansManager.getInstance().runSyncLater(() -> {
if (Bukkit.getPlayer(playerName) != null)
{
Bukkit.getPlayer(playerName).kickPlayer(_toKick.remove(playerName));
}
else
{
_runAfterLoad.get(playerName).forEach(Runnable::run);
_runAfterLoad.get(playerName).clear();
}
}, 5L);
} }
}); });
} }

View File

@ -1,14 +1,13 @@
package mineplex.game.clans.clans.ban; package mineplex.game.clans.clans.ban;
import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.Set;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.CoreClient; import com.google.common.collect.Sets;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.database.MinecraftRepository; import mineplex.core.database.MinecraftRepository;
@ -20,65 +19,44 @@ import mineplex.serverdata.database.column.ColumnVarChar;
public class ClansBanRepository extends MinecraftRepository public class ClansBanRepository extends MinecraftRepository
{ {
private ClansBanManager _manager;
private static final String BAN_PLAYER = "INSERT INTO clanBans (uuid, admin, reason, banTime, unbanTime, permanent, removed) VALUES (?, ?, ?, ?, ?, ?, ?);"; private static final String BAN_PLAYER = "INSERT INTO clanBans (uuid, admin, reason, banTime, unbanTime, permanent, removed) VALUES (?, ?, ?, ?, ?, ?, ?);";
private static final String REMOVE_BAN = "UPDATE clanBans SET removed = 1 WHERE id = ?;"; private static final String REMOVE_BAN = "UPDATE clanBans SET removed = 1 WHERE id = ?;";
private static final String GET_ALL_BANS = "SELECT * FROM clanBans WHERE uuid = ?;"; private static final String GET_ALL_BANS = "SELECT * FROM clanBans WHERE uuid = ?;";
public ClansBanRepository(JavaPlugin plugin, ClansBanManager manager) public ClansBanRepository(JavaPlugin plugin)
{ {
super(plugin, DBPool.getAccount()); super(plugin, DBPool.getAccount());
_manager = manager;
} }
public void ban(UUID uuid, String admin, long time, String reason, boolean permanent) public void ban(UUID uuid, String admin, long time, String reason, boolean permanent, Callback<ClansBan> callback)
{ {
executeInsert(BAN_PLAYER, null, Timestamp banTime = new Timestamp(System.currentTimeMillis());
Timestamp unbanTime = new Timestamp(System.currentTimeMillis() + time);
executeInsert(BAN_PLAYER,
generatedKeys -> {
if (generatedKeys.next() && callback != null)
{
callback.run(new ClansBan(generatedKeys.getInt(1), uuid, admin, reason, banTime, unbanTime, permanent, false));
}
},
new ColumnVarChar("uuid", 36, uuid.toString()), new ColumnVarChar("uuid", 36, uuid.toString()),
new ColumnVarChar("admin", 16, admin), new ColumnVarChar("admin", 16, admin),
new ColumnVarChar("reason", 128, reason), new ColumnVarChar("reason", 128, reason),
new ColumnTimestamp("banTime", new Timestamp(System.currentTimeMillis())), new ColumnTimestamp("banTime", banTime),
new ColumnTimestamp("unbanTime", new Timestamp(System.currentTimeMillis() + time)), new ColumnTimestamp("unbanTime", unbanTime),
new ColumnBoolean("permanent", permanent), new ColumnBoolean("permanent", permanent),
new ColumnBoolean("removed", false) new ColumnBoolean("removed", false)
); );
} }
public void loadBans(final String name, final Callback<ClansBanClient> callback) public void loadClient(String name, final Callback<ClansBanClient> callback)
{ {
loadClientByName(name, client -> { String uuid = UUIDFetcher.getUUIDOf(name).toString();
String uuid = UUIDFetcher.getUUIDOf(client.GetPlayerName()).toString();
executeQuery(GET_ALL_BANS, resultSet -> {
executeQuery(GET_ALL_BANS, resultSet -> { final Set<ClansBan> bans = Sets.newConcurrentHashSet();
final List<ClansBan> list = new ArrayList<ClansBan>();
while (resultSet.next())
{
int id = resultSet.getInt(1);
String ruuid = resultSet.getString(2);
String admin = resultSet.getString(3);
String reason = resultSet.getString(4);
Timestamp banTime = resultSet.getTimestamp(5);
Timestamp unbanTime = resultSet.getTimestamp(6);
boolean permanent = resultSet.getBoolean(7);
boolean removed = resultSet.getBoolean(8);
list.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed));
}
callback.run(new ClansBanClient(uuid, list));
}, new ColumnVarChar("uuid", 36, uuid));
});
}
public void loadBans(final String name, final String uuid, final ResultSet resultSet, final Callback<ClansBanClient> callback)
{
try
{
final List<ClansBan> list = new ArrayList<ClansBan>();
while (resultSet.next()) while (resultSet.next())
{ {
@ -90,33 +68,15 @@ public class ClansBanRepository extends MinecraftRepository
Timestamp unbanTime = resultSet.getTimestamp(6); Timestamp unbanTime = resultSet.getTimestamp(6);
boolean permanent = resultSet.getBoolean(7); boolean permanent = resultSet.getBoolean(7);
boolean removed = resultSet.getBoolean(8); boolean removed = resultSet.getBoolean(8);
list.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed)); bans.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed));
System.out.println("Got ban for " + name);
} }
callback.run(new ClansBanClient(uuid, list)); if (callback != null)
{
System.out.println("> Successfully handled result"); callback.run(new ClansBanClient(name, uuid, bans));
System.out.println(">> FINISH"); }
} }, new ColumnVarChar("uuid", 36, uuid));
catch (Exception exception)
{
exception.printStackTrace();
}
}
private void loadClientByName(String name, Callback<CoreClient> client)
{
if (_manager.getClientManager().Contains(name))
{
client.run(_manager.getClientManager().Get(name));
}
else
{
_manager.getClientManager().loadClientByName(name, () -> client.run(_manager.getClientManager().Get(name)));
}
} }
@Override @Override
@ -128,7 +88,7 @@ public class ClansBanRepository extends MinecraftRepository
protected void update() protected void update()
{ {
} }
public void removeBan(ClansBan ban) public void removeBan(ClansBan ban)
{ {
executeUpdate(REMOVE_BAN, new ColumnInt("id", ban.getId())); executeUpdate(REMOVE_BAN, new ColumnInt("id", ban.getId()));

View File

@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ban.ClansBanManager; import mineplex.game.clans.clans.ban.ClansBanManager;
@ -21,7 +20,7 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
{ {
if (args == null || args.length < 1) if (args == null || args.length < 1)
{ {
UtilPlayer.message(caller, C.cGold + "/cb <username> <reason> - Displays the \"Clans Punish\" GUI, allowing you to ban the player, and "); 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.");
} }
else if (args.length > 1) else if (args.length > 1)
{ {
@ -36,18 +35,6 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
final String finalReason = reason; final String finalReason = reason;
//Match exact online first
Player target = UtilPlayer.searchExact(playerName);
if (target != null)
{
Plugin.LoadClient(playerName, client -> {
Plugin.cache(caller, playerName, finalReason);
Plugin.getShop().attemptShopOpen(caller);
});
return;
}
Plugin.LoadClient(playerName, client -> { Plugin.LoadClient(playerName, client -> {
Plugin.cache(caller, playerName, finalReason); Plugin.cache(caller, playerName, finalReason);
Plugin.getShop().attemptShopOpen(caller); Plugin.getShop().attemptShopOpen(caller);
@ -55,7 +42,7 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
} }
else else
{ {
UtilPlayer.message(caller, C.cGold + "/cb <username> <reason> - Displays the \"Clans Punish\" GUI, allowing you to ban the player, and "); 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.");
} }
} }
} }

View File

@ -2,163 +2,144 @@ package mineplex.game.clans.clans.ban.ui;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ban.ClansBan; import mineplex.game.clans.clans.ban.ClansBan;
import mineplex.game.clans.clans.ban.ClansBanClient;
import mineplex.game.clans.clans.ban.ClansBanManager; import mineplex.game.clans.clans.ban.ClansBanManager;
public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop> public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop>
{ {
private int _days; private long _time;
private int _hours;
private boolean _permanent; private boolean _permanent;
private ClansBanClient _victimClient;
private String _victim;
private String _reason;
public ClansBanPage(final ClansBanManager banManager, final ClansBanShop shop, final CoreClientManager clientManager, final DonationManager donationManager, final String name, final Player player) public ClansBanPage(final ClansBanManager banManager, final ClansBanShop shop, final CoreClientManager clientManager, final DonationManager donationManager, final String name, final Player player)
{ {
super(banManager, shop, clientManager, donationManager, name, player); super(banManager, shop, clientManager, donationManager, name, player);
_victim = getPlugin().getCachedData(player).getVictim();
_reason = getPlugin().getCachedData(player).getReason();
_victimClient = getPlugin().Get(_victim);
buildPage(); buildPage();
} }
protected void buildPage() protected void buildPage()
{ {
getPlugin().runAsync(() -> { _time = Math.max(0, _time);
_days = Math.max(0, _days);
_hours = Math.max(0, _hours); int slot = 27;
Pair<String, String> data = getPlugin().getCachedData(getPlayer()); // Middle of first row
getPlugin().LoadClient(data.getLeft(), client -> { addButton(4, new ItemBuilder(Material.SKULL_ITEM)
int slot = 27; .setData((short) 3)
.setPlayerHead(_victim)
// Middle of first row .setTitle(C.cDGreenB + _victim)
addButton(4, new ItemBuilder(Material.COAL_BLOCK) .addLore(" ")
.setTitle(C.cDGreenB + data.getLeft()) .addLore(C.cYellow + _reason).build(), (player, click) -> {});
.addLore(" ")
.addLore(C.cYellow + data.getRight()).build(), (player, click) -> {}); addTimeAdjuster((9 * 1 + 2), -(1000l * 60l * 60l));
addTimeAdjuster((9 * 1 + 1), -(1000l * 60l * 60l * 24l));
addButton((9 * 1) + 3, new ItemBuilder(Material.PAPER) addTimeAdjuster((9 * 1 + 0), -(1000l * 60l * 60l * 24l * 30l));
.setTitle(C.cRed + "-1 Hour").build(), addTimeAdjuster((9 * 1 + 6), (1000l * 60l * 60l));
(player, click) -> { addTimeAdjuster((9 * 1 + 7), (1000l * 60l * 60l * 24l));
_hours--; addTimeAdjuster((9 * 1 + 8), (1000l * 60l * 60l * 24l * 30l));
refresh();
}); addButton((9 * 1) + 4,
new ItemBuilder(Material.RECORD_5)
addButton((9 * 1) + 2, new ItemBuilder(Material.PAPER) .setTitle(C.cRedB + "Ban Player")
.setTitle(C.cRed + "-1 Day").build(), .setLore(
(player, click) -> { " ",
_days--; C.cGray + "Player: " + F.elem(_victim),
refresh(); C.cGray + "Reason: " + F.elem(_reason),
}); C.cGray + "Time: " + F.elem(_permanent ? "Permanent" : UtilTime.MakeStr(_time)),
"",
addButton((9 * 1) + 1, new ItemBuilder(Material.PAPER) C.cRed + C.Italics + "Left-Click to BAN PLAYER",
.setTitle(C.cRed + "-30 Days").build(), C.cGray + C.Italics + "Right-Click to toggle permanent ban setting"
(player, click) -> { ).build(),
_days -= 30; (player, click) -> {
refresh(); if (click == ClickType.RIGHT)
}); {
_permanent = !_permanent;
refresh();
addButton((9 * 1) + 5, new ItemBuilder(Material.PAPER) }
.setTitle(C.cGreen + "+1 Hour").build(), else
(player, click) -> { {
_hours++; performBan();
refresh(); }
}); });
addButton((9 * 1) + 6, new ItemBuilder(Material.PAPER) for (ClansBan ban : _victimClient.Bans)
.setTitle(C.cGreen + "+1 Day").build(), {
(player, click) -> { ItemStack item = new ItemBuilder(ban.isActive() ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK)
_days++;
refresh();
});
addButton((9 * 1) + 7, new ItemBuilder(Material.PAPER)
.setTitle(C.cGreen + "+30 Days").build(),
(player, click) -> {
_days += 30;
refresh();
});
// Middle of second row
addButton((9 * 1) + 4, new ItemBuilder(Material.WATCH)
.setTitle(C.cGold + "Time Options")
.addLore(" ")
.addLore("Permanent: " + F.elem(_permanent ? "Yes" : "No"))
.addLore("Days: " + F.elem(Integer.valueOf(_days)))
.addLore("Hours: " + F.elem(Integer.valueOf(_hours)))
.addLore(" ")
.addLore("Right-Click this button")
.addLore("to ban permanently.").build(),
(player, click) -> {
if (click == ClickType.RIGHT)
{
_permanent = !_permanent;
refresh();
}
});
// Middle of third row
addButton((9 * 2) + 4, new ItemBuilder(Material.EMERALD_BLOCK)
.setTitle(C.cRedB + "BAN PLAYER")
.addLore(" ")
.addLore("Player: " + F.elem(data.getLeft()))
.addLore("Reason: " + F.elem(data.getRight())).build(),
(player, click) -> {
getPlugin().runAsync(() -> {
double time = _days + ((1.f / 24.f) * _hours);
getPlugin().ban(client, data.getLeft(), getPlayer().getName(), _permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), data.getRight(), c -> {
UtilPlayer.message(getPlayer(), F.main("Clans", F.elem(data.getLeft()) + " is now banned " + c.getBanTimeFormatted() + "."));
getPlugin().runSync(() -> {
Player target = Bukkit.getPlayer(data.getLeft());
if (target != null)
target.kickPlayer(C.cRedB + "You have been banned from Clans " + c.getBanTimeFormatted() + ".");
});
});
});
});
for (ClansBan ban : client.Bans)
{
ItemStack item =
new ItemBuilder(ban.isActive() ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK)
.setTitle(ban.isActive() ? C.cGreenB + "Active" : C.cRedB + "Inactive") .setTitle(ban.isActive() ? C.cGreenB + "Active" : C.cRedB + "Inactive")
.addLore(" ") .addLore(" ")
.addLore("Date banned: " + C.cYellow + UtilTime.date(ban.getBanTime().getTime())) .addLore(C.cGray + "Date banned: " + C.cYellow + UtilTime.date(ban.getBanTime().getTime()))
.addLore("Admin: " + C.cYellow + ban.getAdmin()) .addLore(C.cGray + "Admin: " + C.cYellow + ban.getAdmin())
.addLore("Time left: " + C.cYellow + (ban.isActive() ? ban.getBanTimeFormatted(false) : "None")) .addLore(C.cGray + "Time left: " + C.cYellow + (ban.isActive() ? ban.getBanTimeFormatted(false) : "None"))
.addLore("Permanent: " + C.cYellow + (ban.isPermanent() ? "Yes" : "No")) .addLore(C.cGray + "Permanent: " + C.cYellow + (ban.isPermanent() ? "Yes" : "No"))
.addLore(C.cGray + "Reason: " + C.cYellow + ban.getReason(), 16) .addLore(C.cGray + "Reason: " + C.cYellow + ban.getReason(), 16)
.addLore("Is Disabled: " + C.cYellow + (ban.isRemoved() ? "Yes" : "No")) .addLore(C.cGray + "Is Disabled: " + C.cYellow + (ban.isRemoved() ? "Yes" : "No"))
.addLore(!ban.isActive() ? null : C.cDAqua + "Left-Click to disable ban") .addLore(ban.isActive() ? " " : null)
.addLore(ban.isActive() ? C.cDAqua + "Left-Click to disable ban" : null)
.build(); .addDullEnchantment(ban.isActive())
.build();
if (ban.isActive())
UtilInv.addDullEnchantment(item); addButton(slot++, item, (player, click) -> {
if (ban.isActive())
addButton(slot++, item, (player, click) -> { {
if (ban.isActive()) getPlugin().runAsync(() -> {
{ getPlugin().unban(_victimClient, ban, client -> {
getPlugin().runAsync(() -> getPlugin().unban(client, ban, data.getLeft(), c -> refresh())); refresh();
} player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1f);
});
}); });
} }
}); });
}
}
private void performBan()
{
getPlugin().runAsync(() -> {
getPlugin().ban(_victimClient, getPlayer().getName(), _permanent ? -1 : _time, _reason, client -> {
UtilPlayer.message(getPlayer(), F.main("Clans", F.elem(_victim) + " is now banned " + client.getBanTimeFormatted() + "."));
Player target = Bukkit.getPlayer(_victim);
if (target != null)
{
getPlugin().queueToKick(target, C.cRedB + "You have been banned from Clans " + client.getBanTimeFormatted() + ".");
}
refresh();
});
}); });
} }
private void addTimeAdjuster(int index, long time)
{
addButton(index, new ItemBuilder(Material.PAPER).setTitle(C.cRed + (time < 0 ? "-" : "") + UtilTime.MakeStr(Math.abs(time))).build(),
(player, click) -> {
_time += time;
refresh();
});
}
} }

View File

@ -423,8 +423,15 @@ public class ItemMapManager extends MiniPlugin
} }
} }
Byte color = Iterables.getFirst(Multisets.copyHighestCountFirst(hashmultiset), (byte) 0); Byte color;
try
{
color = Iterables.getFirst(Multisets.copyHighestCountFirst(hashmultiset), (byte) 0);
}
catch (Exception e)
{
color = (byte) 0;
}
second[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] = color; second[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] = color;
} }
} }

View File

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

View File

@ -1,6 +1,8 @@
package mineplex.game.clans.clans.siege.weapon; package mineplex.game.clans.clans.siege.weapon;
import java.util.ArrayList; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -41,6 +43,7 @@ import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.AccessType;
import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo;
import mineplex.game.clans.core.repository.ClanTerritory;
public class Cannon extends SiegeWeapon public class Cannon extends SiegeWeapon
{ {
@ -425,32 +428,17 @@ public class Cannon extends SiegeWeapon
@EventHandler @EventHandler
public void explosionEffects(SiegeWeaponExplodeEvent event) public void explosionEffects(SiegeWeaponExplodeEvent event)
{ {
// for (int i = 0; i < 8; i++) List<Block> blocks = Stream.generate(() -> UtilAlg.getRandomLocation(event.getProjectile().getLocation(), 4 * getPowerLevel()).getBlock())
// { .limit(30) // Generate up to 30
// // Explosion particle effects. .distinct() // distinct blocks,
// Location point = UtilAlg.getRandomLocation(event.getProjectile().getLocation(), 5); .filter(block -> block.getType() != Material.AIR) // filter for non-air
// UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, point, 0, 0, 0, 1, 2, ViewDist.MAX); .filter(block -> // and blocks whose locations aren't blacklisted,
// }
// Block explosion.
ArrayList<Block> blocks = new ArrayList<>();
int attempts = 0;
while (blocks.size() < 10 && (attempts < 30))
{
Block block = UtilAlg.getRandomLocation(event.getProjectile().getLocation(), (4 * getPowerLevel())).getBlock();
if (_siegeManager.getClansManager().getClanUtility().getClaim(block.getLocation()) != null && !_siegeManager.getClansManager().getBlacklist().allowed(_siegeManager.getClansManager().getClanUtility().getClaim(block.getLocation()).Owner))
{ {
continue; ClanTerritory claim = _siegeManager.getClansManager().getClanUtility().getClaim(block.getLocation());
} return claim == null || _siegeManager.getClansManager().getBlacklist().allowed(claim.Owner);
})
if ((block.getType() != Material.AIR) && (!blocks.contains(block))) .limit(10) // and take up to 10 of them.
{ .collect(Collectors.toList());
blocks.add(block);
}
attempts++;
}
_clans.getExplosion().BlockExplosion( _clans.getExplosion().BlockExplosion(
blocks, blocks,
@ -459,5 +447,4 @@ public class Cannon extends SiegeWeapon
false false
); );
} }
} }

View File

@ -121,6 +121,8 @@ public abstract class SiegeWeapon implements Listener
// Customizability // Customizability
private double[] _forcedVelocity; private double[] _forcedVelocity;
private float[] _lockedYaw;
protected boolean _isRideable; protected boolean _isRideable;
protected boolean _invertRotation; protected boolean _invertRotation;
protected AccessRule _mountAccess; protected AccessRule _mountAccess;
@ -299,6 +301,22 @@ public abstract class SiegeWeapon implements Listener
double yaw = (float) ((float)standYaw + Math.min(dif / _rotSpeed, 4f)); double yaw = (float) ((float)standYaw + Math.min(dif / _rotSpeed, 4f));
if (_lockedYaw != null)
{
float min = _lockedYaw[0];
float max = _lockedYaw[1];
if (yaw < min)
{
yaw = min;
}
if (yaw > max)
{
yaw = max;
}
}
armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(CustomRotate(_yaw = yaw)), 0)); armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(CustomRotate(_yaw = yaw)), 0));
} }
} }
@ -313,6 +331,11 @@ public abstract class SiegeWeapon implements Listener
_forcedVelocity = new double[] { vertical, horizontal }; _forcedVelocity = new double[] { vertical, horizontal };
} }
public void LockYaw(float minYaw, float maxYaw)
{
_lockedYaw = new float[] { minYaw, maxYaw };
}
private void fire(Player player) private void fire(Player player)
{ {
_lastFired = System.currentTimeMillis(); _lastFired = System.currentTimeMillis();
@ -458,7 +481,7 @@ public abstract class SiegeWeapon implements Listener
private void dismount(Player player) private void dismount(Player player)
{ {
player.teleport(player.getLocation().add(0, 1, 0)); _clans.runSync(() -> player.teleport(player.getLocation().add(0, 1, 0)));
} }
protected void handleLeftClick(Player player) protected void handleLeftClick(Player player)
@ -523,7 +546,12 @@ public abstract class SiegeWeapon implements Listener
protected void CustomRightClick(Player player) { return; } protected void CustomRightClick(Player player) { return; }
protected void CustomCleanup() { return; } protected void CustomCleanup() { return; }
protected void CustomUpdateState(String state) { return; } protected void CustomUpdateState(String state) { return; }
protected double CustomRotate(double yaw) { return yaw; }
protected double CustomRotate(double yaw)
{
return yaw;
}
protected boolean CustomDismount(Player player, Entity entity) { return false; } protected boolean CustomDismount(Player player, Entity entity) { return false; }
protected boolean CustomMount(Player player) { return false; } protected boolean CustomMount(Player player) { return false; }

View File

@ -212,17 +212,7 @@ public class Spawn extends MiniPlugin
} }
} }
} }
@EventHandler
public void ignoreVelocity(PlayerVelocityEvent event)
{
if (_clansManager.getClanUtility().isSafe(event.getPlayer()))
{
event.setCancelled(true);
System.out.println("cancelled");
}
}
@EventHandler @EventHandler
public void onSkill(SkillTriggerEvent event) public void onSkill(SkillTriggerEvent event)
{ {

View File

@ -62,55 +62,46 @@ public class BlowUpWallGoal extends ObjectiveGoal<AttackEnemyObjective>
TutorialRegion region = getObjective().getPlugin().getRegion(shooter); TutorialRegion region = getObjective().getPlugin().getRegion(shooter);
if (getObjective().getPlugin().isIn(center, region, ClansMainTutorial.Bounds.ENEMY_ATTACK_AREA)) double radius = 5.2;
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
int iR = (int) radius + 1;
for (int x = -iR; x <= iR; x++)
{ {
double radius = 5.2; for (int z = -iR; z <= iR; z++)
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
int iR = (int) radius + 1;
for (int x = -iR; x <= iR; x++)
{ {
for (int z = -iR; z <= iR; z++) for (int y = -iR; y <= iR; y++)
{ {
for (int y = -iR; y <= iR; y++) Block curBlock = center.getBlock().getRelative(x, y, z);
double offset = UtilMath.offset(center, curBlock.getLocation());
if (offset <= radius)
{ {
Block curBlock = center.getBlock().getRelative(x, y, z); blockList.put(curBlock, Double.valueOf(offset));
double offset = UtilMath.offset(center, curBlock.getLocation());
if (offset <= radius)
{
blockList.put(curBlock, Double.valueOf(offset));
}
} }
} }
} }
}
blockList.forEach((block, dist) -> {
blockList.forEach((block, dist) -> { if (block.getType() == Material.SMOOTH_BRICK
|| block.getType() == Material.SMOOTH_STAIRS
|| block.getType() == Material.IRON_DOOR_BLOCK)
if (Math.random() < 0.2 + (dist.doubleValue() / 2.55) || dist.doubleValue() < 1.75)
{
block.setType(Material.AIR, false);
if (block.getType() == Material.SMOOTH_BRICK if (block.getType() != Material.IRON_DOOR_BLOCK && block.getType().name().endsWith("BANNER"))
|| block.getType() == Material.SMOOTH_STAIRS FallingBlocks.Instance.Spawn(block.getLocation(), block.getType(), block.getData(), center);
|| block.getType() == Material.IRON_DOOR_BLOCK) }
});
if (Math.random() < 0.2 + (dist.doubleValue() / 2.55) || dist.doubleValue() < 1.75)
{
block.setType(Material.AIR, false);
if (block.getType() != Material.IRON_DOOR_BLOCK && block.getType().name().endsWith("BANNER"))
FallingBlocks.Instance.Spawn(block.getLocation(), block.getType(), block.getData(), center);
}
});
event.setCancelled(true); event.setCancelled(true);
finish(shooter); finish(shooter);
}
else
{
UtilPlayer.message(shooter, F.main("Clans", "You missed! Try to hit the enemy's front wall, that should make a nice big hole!"));
UtilInv.give(shooter, Material.TNT);
event.setCancelled(true);
}
} }
@Override @Override

View File

@ -36,8 +36,10 @@ public class MountCannonGoal extends ObjectiveGoal<AttackEnemyObjective>
protected void customStart(Player player) protected void customStart(Player player)
{ {
getObjective().getCannons().put(player.getName(), _clansManager.getSiegeManager().spawnCannon(player, getObjective().getPlugin().getPoint(getObjective().getPlugin().getRegion(player), Point.CANNON), false)); getObjective().getCannons().put(player.getName(), _clansManager.getSiegeManager().spawnCannon(player, getObjective().getPlugin().getPoint(getObjective().getPlugin().getRegion(player), Point.CANNON), false));
getObjective().getCannons().get(player.getName()).SetForcedVelocity(0.4, 2.45); getObjective().getCannons().get(player.getName()).SetForcedVelocity(0.44, 2.45);
getObjective().getCannons().get(player.getName()).setInvincible(true); getObjective().getCannons().get(player.getName()).setInvincible(true);
getObjective().getCannons().get(player.getName()).LockYaw(-193, -173);
TutorialSession session = getObjective().getPlugin().getTutorialSession(player); TutorialSession session = getObjective().getPlugin().getTutorialSession(player);
session.setMapTargetLocation(getObjective().getPlugin().getPoint(session.getRegion(), ClansMainTutorial.Point.CANNON)); session.setMapTargetLocation(getObjective().getPlugin().getPoint(session.getRegion(), ClansMainTutorial.Point.CANNON));

View File

@ -411,7 +411,7 @@ public class CombatManager extends MiniPlugin
} }
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOW)
public void HandleDeath(PlayerDeathEvent event) public void HandleDeath(PlayerDeathEvent event)
{ {
event.setDeathMessage(null); event.setDeathMessage(null);
@ -485,7 +485,7 @@ public class CombatManager extends MiniPlugin
killPlayer += " + " + log.GetAssists(); killPlayer += " + " + log.GetAssists();
String weapon = log.GetKiller().GetLastDamageSource(); String weapon = log.GetKiller().GetLastDamageSource();
UtilPlayer.message( UtilPlayer.message(
cur, cur,
F.main("Death", F.main("Death",

View File

@ -935,6 +935,22 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return _game.IsAlive(player); return _game.IsAlive(player);
} }
/**
* Checks if a player is participating in/has been participating in the current game
* @param player The player to check
* @return Whether they are/have been playing
*/
public boolean hasBeenPlaying(Player player)
{
if (_game == null)
return false;
if (_game.GetTeam(player) == null)
return false;
return true;
}
public void Clear(Player player) public void Clear(Player player)
{ {

View File

@ -114,12 +114,12 @@ public abstract class RankedTeamGame extends TeamGame
event.disallow(Result.KICK_OTHER, message); event.disallow(Result.KICK_OTHER, message);
} }
@EventHandler @EventHandler(priority = EventPriority.LOWEST)
public void onQuit(PlayerQuitEvent event) public void onQuit(PlayerQuitEvent event)
{ {
if (InProgress()) if (InProgress())
{ {
if (!Manager.IsObserver(event.getPlayer())) if (Manager.hasBeenPlaying(event.getPlayer()))
{ {
Manager.getEloManager().banFromRanked(getAccountId(event.getPlayer().getUniqueId())); Manager.getEloManager().banFromRanked(getAccountId(event.getPlayer().getUniqueId()));
} }