Merge branch 'develop' into project-cosmetics

This commit is contained in:
cnr 2016-05-19 10:04:19 -05:00
commit 7f44281441
122 changed files with 27980 additions and 1297 deletions

View File

@ -10,10 +10,10 @@ import mineplex.core.common.util.UtilPlayer;
public enum Rank public enum Rank
{ {
//Staff //Staff
LT("Leader", ChatColor.GOLD, "Leaders manage the operation of their respective team \nor projects. They usually operate on affairs within \nthe staff, development, or management team."), LT("Leader", ChatColor.DARK_RED, "Leaders manage the operation of their respective team \nor projects. They usually operate on affairs within \nthe staff, development, or management team."),
OWNER("Owner", ChatColor.GOLD, "Owners are the founders of Mineplex. \nEach owner manages a different aspect of the \nserver and ensures its efficient operation."), OWNER("Owner", ChatColor.DARK_RED, "Owners are the founders of Mineplex. \nEach owner manages a different aspect of the \nserver and ensures its efficient operation."),
DEVELOPER("Dev", ChatColor.GOLD, "Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience."), DEVELOPER("Dev", ChatColor.DARK_RED, "Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience."),
ADMIN("Admin", ChatColor.GOLD, "An Administrators role is to manage \ntheir respective Senior Moderator team \nand all moderators within it."), ADMIN("Admin", ChatColor.DARK_RED, "An Administrators role is to manage \ntheir respective Senior Moderator team \nand all moderators within it."),
JNR_DEV("Jr.Dev", ChatColor.GOLD, "Junior Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience."), JNR_DEV("Jr.Dev", ChatColor.GOLD, "Junior Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience."),
SUPPORT("Support", ChatColor.BLUE, "Support agents handle tickets and \nprovide customer service."), SUPPORT("Support", ChatColor.BLUE, "Support agents handle tickets and \nprovide customer service."),
CMOD("C.Mod", ChatColor.GOLD, "Clans Moderators are members of the Clans Management Senior Mod team. \nTheir duties include moderation and support within the Clans servers. \n\nFor assistance, contact them using " + F.elem("/a <message>") + "."), CMOD("C.Mod", ChatColor.GOLD, "Clans Moderators are members of the Clans Management Senior Mod team. \nTheir duties include moderation and support within the Clans servers. \n\nFor assistance, contact them using " + F.elem("/a <message>") + "."),

View File

@ -20,7 +20,7 @@ public class ChildJsonMessage extends JsonMessage
_parent = parent; _parent = parent;
} }
public ChildJsonMessage add(String text) public ChildJsonMessage add(String text)
{ {
Builder.append("}, "); Builder.append("}, ");
@ -42,6 +42,38 @@ public class ChildJsonMessage extends JsonMessage
return this; return this;
} }
@Override
public ChildJsonMessage italic()
{
super.italic();
return this;
}
@Override
public ChildJsonMessage underlined()
{
super.underlined();
return this;
}
@Override
public ChildJsonMessage strikethrough()
{
super.strikethrough();
return this;
}
@Override
public ChildJsonMessage obfuscated()
{
super.obfuscated();
return this;
}
@Override @Override
public ChildJsonMessage click(String action, String value) public ChildJsonMessage click(String action, String value)
@ -50,6 +82,14 @@ public class ChildJsonMessage extends JsonMessage
return this; return this;
} }
@Override
public ChildJsonMessage click(ClickEvent event, String value)
{
super.click(event, value);
return this;
}
@Override @Override
public ChildJsonMessage hover(String action, String value) public ChildJsonMessage hover(String action, String value)
@ -58,7 +98,15 @@ public class ChildJsonMessage extends JsonMessage
return this; return this;
} }
@Override
public ChildJsonMessage hover(HoverEvent event, String value)
{
super.hover(event, value);
return this;
}
@Override @Override
public String toString() public String toString()
{ {

View File

@ -1,15 +1,8 @@
package mineplex.core.common.util; package mineplex.core.common.util;
import java.lang.reflect.Field; import com.google.common.collect.Lists;
import java.util.ArrayList; import mineplex.core.common.events.PlayerRecieveBroadcastEvent;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -20,9 +13,8 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.google.common.collect.Lists; import java.lang.reflect.Field;
import java.util.*;
import mineplex.core.common.events.PlayerRecieveBroadcastEvent;
public class UtilServer public class UtilServer
{ {
@ -139,26 +131,6 @@ public class UtilServer
runnable.runTaskTimer(getPlugin(), time, time); runnable.runTaskTimer(getPlugin(), time, time);
} }
public static boolean IsOnline(String 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)
{
return UtilStreams.GetFirst(getPlayersCollection().stream().filter(player -> player.getName().equals(name)));
}
public static OfflinePlayer GetOffline(String player)
{
return getServer().getOfflinePlayer(player);
}
public static String getServerName() public static String getServerName()
{ {
if (_serverName == null) if (_serverName == null)

View File

@ -1,66 +0,0 @@
package mineplex.core.common.util;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.List;
import java.util.stream.Stream;
import org.apache.commons.lang.Validate;
import com.google.common.collect.Lists;
public class UtilStreams
{
public static boolean IsEmpty(Stream<?> stream)
{
return Sum(stream) != 0;
}
public static int Sum(Stream<?> stream)
{
return stream.mapToInt(v -> 1).sum();
}
public static Object[] ToArray(Stream<? extends Object> stream)
{
return stream.toArray();
}
public static <T> T Get(int index, Stream<T> stream)
{
if (Sum(stream) < index + 1)
{
return null;
}
return (T) ToArray(stream)[index];
}
public static <T> T GetFirst(Stream<T> stream)
{
return Get(0, stream);
}
public static <T> T GetLast(Stream<T> stream)
{
return Get(Sum(stream) + 1, stream);
}
public static byte[] ReadBytes(DataInputStream dos, int bytes) throws IOException
{
Validate.isTrue(bytes > 0, "Amount of bytes to read must be > 0");
byte[] read = new byte[bytes];
for (int i = 0; i < bytes; i++)
read[i] = dos.readByte();
return read;
}
public static <T> List<T> ToList(Stream<T> filter)
{
return Lists.newArrayList((T[]) ToArray(filter));
}
}

View File

@ -442,8 +442,8 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
{ {
PacketPlayInUseEntity newPacket = new PacketPlayInUseEntity(); PacketPlayInUseEntity newPacket = new PacketPlayInUseEntity();
newPacket.a = entry.getKey(); newPacket.a = entry.getKey();
newPacket.action = usePacket.action == EnumEntityUseAction.ATTACK ? EnumEntityUseAction.ATTACK newPacket.action = usePacket.action;
: EnumEntityUseAction.INTERACT; newPacket.c = usePacket.c;
{ {
((CraftPlayer) owner).getHandle().playerConnection.a(newPacket); ((CraftPlayer) owner).getHandle().playerConnection.a(newPacket);

View File

@ -1,33 +1,26 @@
package mineplex.core.achievement; package mineplex.core.achievement;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.command.StatsCommand; import mineplex.core.achievement.command.StatsCommand;
import mineplex.core.achievement.ui.AchievementShop; import mineplex.core.achievement.ui.AchievementShop;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.elo.EloManager; import mineplex.core.elo.EloManager;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.incognito.IncognitoManager;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
import mineplex.core.stats.event.StatChangeEvent; import mineplex.core.stats.event.StatChangeEvent;
public class AchievementManager extends MiniPlugin public class AchievementManager extends MiniPlugin
{ {
private IncognitoManager _incognitoManager;
private StatsManager _statsManager; private StatsManager _statsManager;
private EloManager _eloManager; private EloManager _eloManager;
@ -39,10 +32,11 @@ public class AchievementManager extends MiniPlugin
private boolean _shopEnabled = true; private boolean _shopEnabled = true;
public AchievementManager(StatsManager statsManager, CoreClientManager clientManager, DonationManager donationManager, EloManager eloManager) public AchievementManager(StatsManager statsManager, CoreClientManager clientManager, DonationManager donationManager, IncognitoManager incognitoManager, EloManager eloManager)
{ {
super("Achievement Manager", statsManager.getPlugin()); super("Achievement Manager", statsManager.getPlugin());
_incognitoManager = incognitoManager;
_statsManager = statsManager; _statsManager = statsManager;
_eloManager = eloManager; _eloManager = eloManager;
_shop = new AchievementShop(this, _statsManager, clientManager, donationManager, "Achievement"); _shop = new AchievementShop(this, _statsManager, clientManager, donationManager, "Achievement");
@ -221,4 +215,9 @@ public class AchievementManager extends MiniPlugin
{ {
_shopEnabled = var; _shopEnabled = var;
} }
public IncognitoManager getIncognito()
{
return _incognitoManager;
}
} }

View File

@ -29,6 +29,11 @@ public class StatsCommand extends CommandBase<AchievementManager>
{ {
return; return;
} }
if (/* StaffServer special case */Plugin.getIncognito() != null && Plugin.getIncognito().Get(target).Hidden)
{
return;
}
Plugin.openShop(caller, target); Plugin.openShop(caller, target);
} }

View File

@ -1,33 +1,23 @@
package mineplex.core.bonuses; package mineplex.core.bonuses;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.TimeZone;
import mineplex.core.MiniClientPlugin; import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor; import mineplex.core.account.ILoginProcessor;
import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.bonuses.animations.AnimationCarl;
import mineplex.core.bonuses.commands.AnimationCommand;
import mineplex.core.bonuses.commands.GuiCommand;
import mineplex.core.bonuses.commands.TicketCommand;
import mineplex.core.bonuses.event.CarlSpinnerEvent;
import mineplex.core.bonuses.gui.BonusGui;
import mineplex.core.bonuses.gui.SpinGui;
import mineplex.core.bonuses.redis.VoteHandler; import mineplex.core.bonuses.redis.VoteHandler;
import mineplex.core.bonuses.redis.VotifierCommand; import mineplex.core.bonuses.redis.VotifierCommand;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.*;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.serverdata.database.DBPool;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.donation.GiveDonorData; import mineplex.core.donation.GiveDonorData;
import mineplex.core.facebook.FacebookManager; import mineplex.core.facebook.FacebookManager;
@ -39,6 +29,7 @@ import mineplex.core.inventory.InventoryManager;
import mineplex.core.npc.Npc; import mineplex.core.npc.Npc;
import mineplex.core.npc.NpcManager; import mineplex.core.npc.NpcManager;
import mineplex.core.pet.PetManager; import mineplex.core.pet.PetManager;
import mineplex.core.poll.PollManager;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.reward.RewardManager; import mineplex.core.reward.RewardManager;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
@ -47,19 +38,12 @@ import mineplex.core.treasure.TreasureType;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.database.Tables; import mineplex.database.Tables;
import mineplex.core.bonuses.animations.AnimationCarl;
import mineplex.core.bonuses.commands.AnimationCommand;
import mineplex.core.bonuses.commands.GuiCommand;
import mineplex.core.bonuses.commands.TicketCommand;
import mineplex.core.bonuses.event.CarlSpinnerEvent;
import mineplex.core.bonuses.gui.BonusGui;
import mineplex.database.tables.records.BonusRecord; import mineplex.database.tables.records.BonusRecord;
import mineplex.core.bonuses.gui.SpinGui;
import mineplex.core.poll.PollManager;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.database.DBPool;
import org.jooq.SQLDialect; import net.minecraft.server.v1_8_R3.DataWatcher;
import org.jooq.impl.DSL; import net.minecraft.server.v1_8_R3.EntityCreeper;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
@ -72,10 +56,14 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import net.minecraft.server.v1_8_R3.DataWatcher; import java.sql.Date;
import net.minecraft.server.v1_8_R3.EntityCreeper; import java.sql.ResultSet;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata; import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.*;
public class BonusManager extends MiniClientPlugin<BonusClientData> implements ILoginProcessor public class BonusManager extends MiniClientPlugin<BonusClientData> implements ILoginProcessor
{ {
@ -921,6 +909,10 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (client.getHologram() == null) if (client.getHologram() == null)
{ {
double yAdd = 2.3; double yAdd = 2.3;
if(!UtilPlayer.is1_9(player))
{
yAdd = 2.45;
}
hologram = new Hologram(_hologramManager, _carlNpc.getLocation().clone().add(0, yAdd, 0), ""); hologram = new Hologram(_hologramManager, _carlNpc.getLocation().clone().add(0, yAdd, 0), "");
hologram.setHologramTarget(Hologram.HologramTarget.WHITELIST); hologram.setHologramTarget(Hologram.HologramTarget.WHITELIST);
hologram.addPlayer(player); hologram.addPlayer(player);

View File

@ -0,0 +1,10 @@
package mineplex.core.chatsnap;
/**
* Holds all types of messages a player can receive from another player
*/
public enum MessageType
{
CHAT,
PM
}

View File

@ -0,0 +1,119 @@
package mineplex.core.chatsnap;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import com.google.gson.annotations.SerializedName;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Represents a message sent by a player.
*/
public class Snapshot implements Comparable<Snapshot>
{
@SerializedName("type")
private MessageType _messageType;
@SerializedName("sender")
private UUID _sender;
@SerializedName("recipients")
private Collection<UUID> _recipients;
@SerializedName("message")
private String _message;
@SerializedName("time")
private LocalDateTime _time;
public Snapshot(UUID sender, UUID recipient, String message)
{
this(MessageType.PM, sender, Collections.singletonList(recipient), message, LocalDateTime.now());
}
public Snapshot(UUID sender, Collection<UUID> recipients, String message)
{
this(MessageType.CHAT, sender, recipients, message, LocalDateTime.now());
}
public Snapshot(MessageType messageType, UUID sender, Collection<UUID> recipients, String message, LocalDateTime time)
{
_messageType = messageType;
_sender = checkNotNull(sender);
_recipients = checkNotNull(recipients);
_message = checkNotNull(message);
_time = checkNotNull(time);
if (messageType == MessageType.PM && recipients.size() > 1)
{
throw new IllegalArgumentException("Snapshot type PM may not have more than 1 recipient.");
}
}
public MessageType getMessageType()
{
return _messageType;
}
public UUID getSender()
{
return _sender;
}
public String getMessage()
{
return _message;
}
public Set<UUID> getRecipients()
{
return new HashSet<>(_recipients);
}
public LocalDateTime getSentTime()
{
return _time;
}
@Override
public int compareTo(Snapshot o)
{
return getSentTime().compareTo(o.getSentTime());
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Snapshot that = (Snapshot) o;
return _time == that._time &&
Objects.equals(_sender, that._sender) &&
Objects.equals(_recipients, that._recipients) &&
Objects.equals(_message, that._message);
}
@Override
public int hashCode()
{
return Objects.hash(_sender, _recipients, _message, _time);
}
@Override
public String toString()
{
return "Snapshot{" +
"sender=" + _sender +
", recipients=" + _recipients +
", message='" + ChatColor.stripColor(_message) + '\'' +
", created=" + _time +
'}';
}
}

View File

@ -0,0 +1,77 @@
package mineplex.core.chatsnap;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
/**
* Handles temporary storage of {@link Snapshot} instances.
*/
public class SnapshotManager
{
// There aren't any List or Set caching implementations
// For an easy work around, we store values as the Key
// For the value we just use some dummy object
// I went with Boolean as it's the smallest data type
private final Cache<Snapshot, Boolean> _snapshots = CacheBuilder.newBuilder()
.concurrencyLevel(4)
.expireAfterWrite(30, TimeUnit.MINUTES)
.build();
private final SnapshotPublisher _snapshotPublisher;
public SnapshotManager(SnapshotPublisher snapshotPublisher)
{
_snapshotPublisher = snapshotPublisher;
}
public SnapshotPublisher getSnapshotPublisher()
{
return _snapshotPublisher;
}
/**
* Keeps a snapshot in memory temporarily (30 minutes) and then discards it.
* During this time, other modules (such as the Report module) can access it for their own use.
*
* @param snapshot the snapshot to temporarily store
*/
public void cacheSnapshot(Snapshot snapshot)
{
_snapshots.put(snapshot, true);
}
/**
* Gets all currently stored snapshots.
* The set is in chronological order of the time the message was sent.
*
* @return a set containing all snapshots
*/
public Set<Snapshot> getSnapshots()
{
// The compareTo method in Snapshot will ensure this in chronological order
Set<Snapshot> snapshots = new TreeSet<>();
snapshots.addAll(_snapshots.asMap().keySet());
return snapshots;
}
/**
* Gets all instances of {@link Snapshot} which involve a particular user.
* The user may be the sender or recipient of a message.
*
* @param search the user to search for snaps involved in
* @return the snaps that the user is involved in
*/
public Set<Snapshot> getSnapshots(UUID search)
{
return _snapshots.asMap().keySet().stream()
.filter(snapshot -> snapshot.getSender().equals(search) || snapshot.getRecipients().contains(search))
.collect(Collectors.toCollection(TreeSet::new));
}
}

View File

@ -0,0 +1,73 @@
package mineplex.core.chatsnap;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.chatsnap.commands.ChatCacheCommand;
import mineplex.core.message.PrivateMessageEvent;
/**
* Starter class for all snapshot related functions (ie capturing messages, retrieving snapshots).
*/
public class SnapshotPlugin extends MiniPlugin
{
private final SnapshotManager _snapshotManager;
public SnapshotPlugin(JavaPlugin plugin, SnapshotManager snapshotManager)
{
super("ChatSnap", plugin);
_snapshotManager = snapshotManager;
}
public SnapshotManager getSnapshotManager()
{
return _snapshotManager;
}
@Override
public void addCommands()
{
addCommand(new ChatCacheCommand(this));
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChat(AsyncPlayerChatEvent e)
{
_snapshotManager.cacheSnapshot(createSnapshot(e));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPrivateMessage(PrivateMessageEvent e)
{
_snapshotManager.cacheSnapshot(createSnapshot(e));
}
public Set<UUID> getUUIDSet(Set<Player> playerSet)
{
return playerSet.stream().map(Player::getUniqueId).collect(Collectors.toSet());
}
public Snapshot createSnapshot(AsyncPlayerChatEvent e)
{
UUID senderUUID = e.getPlayer().getUniqueId();
Set<UUID> uuidSet = getUUIDSet(e.getRecipients());
uuidSet.remove(senderUUID);
return new Snapshot(senderUUID, uuidSet, e.getMessage());
}
public Snapshot createSnapshot(PrivateMessageEvent e)
{
Player sender = e.getSender();
Player recipient = e.getRecipient();
String message = e.getMessage();
return new Snapshot(sender.getUniqueId(), recipient.getUniqueId(), message);
}
}

View File

@ -0,0 +1,54 @@
package mineplex.core.chatsnap.commands;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import mineplex.core.chatsnap.SnapshotPlugin;
import mineplex.core.chatsnap.Snapshot;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
/**
* Displays what chat messages we have cached for a player.
*/
public class ChatCacheCommand extends CommandBase<SnapshotPlugin>
{
public ChatCacheCommand(SnapshotPlugin plugin)
{
super(plugin, Rank.MODERATOR, "chatcache");
}
@Override
public void Execute(final Player caller, String[] args)
{
if (args.length != 1)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), String.format("Invalid arguments, usage: /%s <player>", AliasUsed)));
return;
}
final String playerName = args[0];
// getOfflinePlayer sometimes blocks, see this needs to be async
Plugin.getScheduler().runTaskAsynchronously(Plugin.getPlugin(), new Runnable()
{
@Override
public void run()
{
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName);
Set<Snapshot> snaps = Plugin.getSnapshotManager().getSnapshots(offlinePlayer.getUniqueId());
for (Snapshot snapshot : snaps)
{
// TODO: show sender name
caller.sendMessage(snapshot.getMessage());
}
}
});
}
}

View File

@ -0,0 +1,33 @@
package mineplex.core.chatsnap.publishing;
import java.lang.reflect.Type;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
/**
* Handles serialization of Java 8's {@link LocalDateTime}.
*/
public class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime>
{
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
private ZoneId _zoneId;
public LocalDateTimeSerializer(ZoneId zoneId)
{
_zoneId = zoneId;
}
@Override
public JsonElement serialize(LocalDateTime localDateTime, Type type, JsonSerializationContext jsonSerializationContext)
{
return new JsonPrimitive(localDateTime.atZone(_zoneId).toLocalDateTime().truncatedTo(ChronoUnit.SECONDS).format(FORMATTER));
}
}

View File

@ -0,0 +1,32 @@
package mineplex.core.chatsnap.publishing;
import java.lang.reflect.Type;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import mineplex.core.report.Report;
/**
* Handles serialization of {@link Report} instances.
*/
public class ReportSerializer implements JsonSerializer<Report>
{
@Override
public JsonElement serialize(Report report, Type type, JsonSerializationContext jsonSerializationContext)
{
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("id", report.getReportId());
jsonObject.addProperty("serverName", report.getServerName());
if (report.getHandler() != null)
{
jsonObject.addProperty("handler", report.getHandler().toString());
}
jsonObject.addProperty("suspect", report.getSuspect().toString());
jsonObject.add("reporters", jsonSerializationContext.serialize(report.getReportReasons()));
return jsonObject;
}
}

View File

@ -0,0 +1,119 @@
package mineplex.core.chatsnap.publishing;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import mineplex.core.chatsnap.Snapshot;
import mineplex.core.report.Report;
import mineplex.serverdata.Utility;
import mineplex.serverdata.servers.ServerManager;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
/**
* Class responsible for publishing snapshots on the website via Redis and a separate Report server.
*/
public class SnapshotPublisher
{
private static final ZoneId ZONE_ID = ZoneId.of("America/Chicago"); // This means "CST"
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer(ZONE_ID))
.registerTypeAdapter(Report.class, new ReportSerializer())
.create();
public static ZoneId getZoneId()
{
return ZONE_ID;
}
public static Gson getGson()
{
return GSON;
}
public static String getURL(String token)
{
return URL_PREFIX + token;
}
private static final String URL_PREFIX = "http://file.mineplex.com/chatsnap/view.php?identifier=";
public static final String CHANNEL_DEPLOY = "reportserver:deploy";
public static final String CHANNEL_DESTROY = "reportserver:destroy";
private JavaPlugin _plugin;
private JedisPool _jedisPool;
public SnapshotPublisher(JavaPlugin plugin)
{
_plugin = plugin;
_jedisPool = Utility.generatePool(ServerManager.getMasterConnection());
}
public void publishChatLog(String token, JsonObject jsonObject)
{
jsonObject.addProperty("token", token);
String json = GSON.toJson(jsonObject);
// getting a Jedis resource can block, so lets async it
Bukkit.getScheduler().runTaskAsynchronously(_plugin, () ->
{
try (Jedis jedis = _jedisPool.getResource())
{
jedis.publish(CHANNEL_DEPLOY, json);
}
});
}
public void unpublishChatLog(String token)
{
// getting a Jedis resource can block, so lets async it
Bukkit.getScheduler().runTaskAsynchronously(_plugin, () ->
{
try (Jedis jedis = _jedisPool.getResource())
{
jedis.publish(CHANNEL_DESTROY, token);
}
});
}
public Set<UUID> getUUIDs(Collection<Snapshot> snapshots)
{
// Being a Set ensures no duplicates
Set<UUID> uuids = new HashSet<>();
for (Snapshot snapshot : snapshots)
{
uuids.add(snapshot.getSender());
uuids.addAll(snapshot.getRecipients().stream().collect(Collectors.toList()));
}
return uuids;
}
public Map<UUID, String> getUsernameMap(Collection<UUID> collection)
{
Map<UUID, String> uuidUsernameMap = new HashMap<>();
for (UUID uuid : collection)
{
String username = Bukkit.getOfflinePlayer(uuid).getName();
uuidUsernameMap.put(uuid, username);
}
return uuidUsernameMap;
}
}

View File

@ -10,6 +10,7 @@ import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -340,24 +341,34 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
} }
/** /**
* Method for fetching the Itemstack that represents a player's division and their progress in it * Method for fetching the ItemStack that represents a player's division and their progress in it
*/ */
public ItemStack getVisual(int elo) public ItemStack getVisual(int elo)
{ {
ItemBuilder build = new ItemBuilder(_visual); ItemBuilder build = new ItemBuilder(_visual);
build.setTitle(C.cGreen + _disp); build.setTitle(C.cGreen + _disp);
int percentage = (elo * 100) / _maxElo; int percentage;
if (_maxElo == -1)
{
percentage = 100;
}
else
{
percentage = ((elo - Math.max(0, _minElo)) * 100) / (_maxElo - Math.max(0, _minElo));
}
String color = C.cYellow; String color = C.cYellow;
if (percentage <= 35) if (percentage <= 35)
{ {
color = C.cRed; color = C.cRed;
} else if (percentage >= 65) }
else if (percentage >= 65)
{ {
color = C.cGreen; color = C.cGreen;
} }
build.addLore(C.cGold + "Your Progress:", color + percentage + "% complete with this Division"); build.addLore(C.cGold + "Progress:", color + percentage + "% complete with this Division");
return build.build(); return build.build();
} }
} }

View File

@ -1,16 +1,5 @@
package mineplex.core.incognito; package mineplex.core.incognito;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniDbClientPlugin; import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
@ -26,6 +15,16 @@ import mineplex.core.packethandler.PacketHandler;
import mineplex.core.preferences.PreferencesManager; import mineplex.core.preferences.PreferencesManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.ResultSet;
import java.sql.SQLException;
public class IncognitoManager extends MiniDbClientPlugin<IncognitoClient> public class IncognitoManager extends MiniDbClientPlugin<IncognitoClient>
{ {
@ -69,18 +68,7 @@ public class IncognitoManager extends MiniDbClientPlugin<IncognitoClient>
} }
} }
} }
else
{
IncognitoHidePlayerEvent customEvent = UtilServer.CallEvent(new IncognitoHidePlayerEvent(caller));
if (!customEvent.isCancelled())
{
UtilServer.getPlayersCollection().forEach(player -> {
player.hidePlayer(caller);
});
}
}
runAsync(() -> _repository.setStatus(_clientManager.getAccountId(caller), enabled)); runAsync(() -> _repository.setStatus(_clientManager.getAccountId(caller), enabled));
return enabled; return enabled;
@ -150,6 +138,12 @@ public class IncognitoManager extends MiniDbClientPlugin<IncognitoClient>
{ {
other.hidePlayer(player); other.hidePlayer(player);
} }
Get(player).Hidden = !customEvent.isCancelled();
}
else
{
Get(player).Hidden = false;
} }
if (Get(other).Status) if (Get(other).Status)
@ -160,6 +154,12 @@ public class IncognitoManager extends MiniDbClientPlugin<IncognitoClient>
{ {
player.hidePlayer(other); player.hidePlayer(other);
} }
Get(other).Hidden = !customEvent.isCancelled();
}
else
{
Get(other).Hidden = false;
} }
} }
} }

View File

@ -1,36 +1,34 @@
package mineplex.core.incognito.commands; package mineplex.core.incognito.commands;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.incognito.IncognitoManager; import mineplex.core.incognito.IncognitoManager;
import org.bukkit.entity.Player;
public class IncognitoToggleCommand extends CommandBase<IncognitoManager> public class IncognitoToggleCommand extends CommandBase<IncognitoManager>
{ {
public IncognitoToggleCommand(IncognitoManager plugin) public IncognitoToggleCommand(IncognitoManager plugin)
{ {
super(plugin, Rank.HELPER, "incognito", "vanish"); super(plugin, Rank.HELPER, "incognito", "vanish");
} }
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
{ {
if (Plugin.getPreferences().Get(caller).Invisibility) if (Plugin.getPreferences().Get(caller).Invisibility && !Plugin.Get(caller).Status)
{ {
UtilPlayer.message(caller, F.main("Incognito", "You are not allowed to toggle incognito on while Hub Invisibility is enabled.")); UtilPlayer.message(caller, F.main("Incognito", "You are not allowed to toggle incognito on while Hub Invisibility is enabled."));
return; return;
} }
if (Plugin.toggle(caller)) if (Plugin.toggle(caller))
{ {
UtilPlayer.message(caller, F.main("Incognito", "You are now incognito. Your status will only change when you run " + F.elem(AliasUsed) + " again.")); UtilPlayer.message(caller, F.main("Incognito", "You are now incognito. Your status will only change when you run " + F.elem("/" + AliasUsed) + " again."));
} } else
else {
{ UtilPlayer.message(caller, F.main("Incognito", "You are no longer incognito. Your status will only change when you run " + F.elem("/" + AliasUsed) + " again."));
UtilPlayer.message(caller, F.main("Incognito", "You are no longer incognito. Your status will only change when you run " + F.elem(AliasUsed) + " again.")); }
} }
}
} }

View File

@ -3,4 +3,5 @@ package mineplex.core.incognito.repository;
public class IncognitoClient public class IncognitoClient
{ {
public boolean Status; public boolean Status;
public boolean Hidden;
} }

View File

@ -1,38 +1,17 @@
package mineplex.core.message; package mineplex.core.message;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.MiniClientPlugin; import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.*;
import mineplex.core.common.util.F;
import mineplex.core.common.util.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.UtilTime.TimeUnit;
import mineplex.core.friend.FriendManager; import mineplex.core.friend.FriendManager;
import mineplex.core.friend.data.FriendData; import mineplex.core.friend.data.FriendData;
import mineplex.core.friend.data.FriendStatus; import mineplex.core.friend.data.FriendStatus;
import mineplex.core.ignore.IgnoreManager; import mineplex.core.ignore.IgnoreManager;
import mineplex.core.incognito.IncognitoManager; import mineplex.core.incognito.IncognitoManager;
import mineplex.core.message.commands.AdminCommand; import mineplex.core.message.commands.*;
import mineplex.core.message.commands.AnnounceCommand;
import mineplex.core.message.commands.MessageAdminCommand;
import mineplex.core.message.commands.MessageCommand;
import mineplex.core.message.commands.ResendAdminCommand;
import mineplex.core.message.commands.ResendCommand;
import mineplex.core.message.redis.AnnouncementHandler; import mineplex.core.message.redis.AnnouncementHandler;
import mineplex.core.message.redis.MessageHandler; import mineplex.core.message.redis.MessageHandler;
import mineplex.core.message.redis.RedisMessage; import mineplex.core.message.redis.RedisMessage;
@ -44,6 +23,16 @@ import mineplex.core.punish.Punishment;
import mineplex.core.punish.PunishmentSentence; import mineplex.core.punish.PunishmentSentence;
import mineplex.serverdata.commands.AnnouncementCommand; import mineplex.serverdata.commands.AnnouncementCommand;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
public class MessageManager extends MiniClientPlugin<ClientMessage> public class MessageManager extends MiniClientPlugin<ClientMessage>
{ {
@ -531,7 +520,7 @@ public class MessageManager extends MiniClientPlugin<ClientMessage>
// If this is a message inside the server // If this is a message inside the server
if (to != null) if (to != null)
{ {
if (_incognitoManager.Get(to).Status) if (_incognitoManager.Get(to).Status && !_clientManager.Get(sender.getName()).GetRank().has(Rank.HELPER))
{ {
UtilPlayer.message(sender, F.main("Online Player Search", F.elem("0") + " matches for [" + F.elem(target) + "].")); UtilPlayer.message(sender, F.main("Online Player Search", F.elem("0") + " matches for [" + F.elem(target) + "]."));
return; return;

View File

@ -3,10 +3,11 @@ package mineplex.core.message;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class PrivateMessageEvent extends Event public class PrivateMessageEvent extends Event implements Cancellable
{ {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@ -32,11 +33,13 @@ public class PrivateMessageEvent extends Event
return handlers; return handlers;
} }
@Override
public void setCancelled(boolean cancel) public void setCancelled(boolean cancel)
{ {
_cancelled = cancel; _cancelled = cancel;
} }
@Override
public boolean isCancelled() public boolean isCancelled()
{ {
return _cancelled; return _cancelled;

View File

@ -1,16 +1,15 @@
package mineplex.core.message.commands; package mineplex.core.message.commands;
import org.bukkit.Sound;
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.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.message.MessageManager; import mineplex.core.message.MessageManager;
import mineplex.core.recharge.Recharge;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
public class AdminCommand extends CommandBase<MessageManager> public class AdminCommand extends CommandBase<MessageManager>
{ {
@ -46,15 +45,10 @@ public class AdminCommand extends CommandBase<MessageManager>
UtilPlayer.message(caller, F.rank(Plugin.GetClientManager().Get(caller).GetRank()) + " " + caller.getName() + " " + C.cPurple + message); UtilPlayer.message(caller, F.rank(Plugin.GetClientManager().Get(caller).GetRank()) + " " + caller.getName() + " " + C.cPurple + message);
//Send //Send
boolean staff = false;
for (Player to : UtilServer.getPlayers()) for (Player to : UtilServer.getPlayers())
{ {
if (Plugin.GetClientManager().Get(to).GetRank().has(Rank.HELPER)) if (Plugin.GetClientManager().Get(to).GetRank().has(Rank.HELPER))
{ {
if (Plugin.getIncognitoManager().Get(to).Status)
{
continue;
}
if (!to.equals(caller)) if (!to.equals(caller))
UtilPlayer.message(to, F.rank(Plugin.GetClientManager().Get(caller).GetRank()) + " " + caller.getName() + " " + C.cPurple + message); UtilPlayer.message(to, F.rank(Plugin.GetClientManager().Get(caller).GetRank()) + " " + caller.getName() + " " + C.cPurple + message);
@ -64,16 +58,17 @@ public class AdminCommand extends CommandBase<MessageManager>
if(Plugin.GetClientManager().Get(to).isDisguised() || !caller.canSee(to)) if(Plugin.GetClientManager().Get(to).isDisguised() || !caller.canSee(to))
continue; continue;
} }
staff = true;
//Sound //Sound
to.playSound(to.getLocation(), Sound.NOTE_PLING, 0.5f, 2f); to.playSound(to.getLocation(), Sound.NOTE_PLING, 0.5f, 2f);
} }
} }
if (!staff)
UtilPlayer.message(caller, F.main(Plugin.getName(), "There are no Staff Members online."));
if (!Plugin.GetClientManager().hasRank(caller, Rank.HELPER) && Recharge.Instance.use(caller, "AdminCommand.InformMsg", 60 * 1000, false, false))
{
UtilPlayer.message(caller, F.main(Plugin.getName(), "If there are any staff currently online, you will receive a reply shortly."));
}
//Log XXX //Log XXX
//Logger().logChat("Staff Chat", from, staff, message); //Logger().logChat("Staff Chat", from, staff, message);
} }

View File

@ -36,9 +36,9 @@ public class PreferencesManager extends MiniDbClientPlugin<UserPreferences>
private PreferencesRepository _repository; private PreferencesRepository _repository;
private PreferencesShop _shop; private PreferencesShop _shop;
private ExclusivePreferencesShop _exclusiveShop; private ExclusivePreferencesShop _exclusiveShop;
private IncognitoManager _incognitoManager; private IncognitoManager _incognitoManager;
private NautHashMap<String, UserPreferences> _saveBuffer = new NautHashMap<String, UserPreferences>(); private NautHashMap<String, UserPreferences> _saveBuffer = new NautHashMap<String, UserPreferences>();
public boolean GiveItem; public boolean GiveItem;
@ -50,9 +50,9 @@ public class PreferencesManager extends MiniDbClientPlugin<UserPreferences>
_repository = new PreferencesRepository(plugin); _repository = new PreferencesRepository(plugin);
_exclusiveShop = new ExclusivePreferencesShop(this, clientManager, donationManager); _exclusiveShop = new ExclusivePreferencesShop(this, clientManager, donationManager);
_shop = new PreferencesShop(this, clientManager, donationManager, _exclusiveShop); _shop = new PreferencesShop(this, clientManager, donationManager, _exclusiveShop);
_incognitoManager = incognito; _incognitoManager = incognito;
_exclusiveShop.setPreferencesShop(_shop); _exclusiveShop.setPreferencesShop(_shop);
addCommand(new PreferencesCommand(this)); addCommand(new PreferencesCommand(this));
@ -142,7 +142,7 @@ public class PreferencesManager extends MiniDbClientPlugin<UserPreferences>
@Override @Override
public String getQuery(int accountId, String uuid, String name) public String getQuery(int accountId, String uuid, String name)
{ {
return "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests, friendDisplayInventoryUI, clanTips, hubMusic, disableAds FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;"; return "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests, friendDisplayInventoryUI, clanTips, hubMusic, disableAds, showUserReports FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;";
} }
public IncognitoManager getIncognitoManager() public IncognitoManager getIncognitoManager()

View File

@ -23,9 +23,10 @@ public class PreferencesRepository extends MinecraftRepository
// privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL // privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL
// DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL // DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL
// DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL // DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL
// NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));"; // NOT NULL DEFAULT 0, showUserReports BOOL NOT NULL DEFAULT 0, PRIMARY
// KEY (id), UNIQUE INDEX uuid_index (uuid));";
private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;"; private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;";
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ?, clanTips = ?, hubMusic = ?, disableAds = ? WHERE uuid=?;"; private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ?, clanTips = ?, hubMusic = ?, disableAds = ?, showUserReports = ? WHERE uuid=?;";
public PreferencesRepository(JavaPlugin plugin) public PreferencesRepository(JavaPlugin plugin)
{ {
@ -37,7 +38,7 @@ public class PreferencesRepository extends MinecraftRepository
{ {
// executeUpdate(CREATE_ACCOUNT_TABLE); // executeUpdate(CREATE_ACCOUNT_TABLE);
} }
@Override @Override
protected void update() protected void update()
{ {
@ -64,12 +65,13 @@ public class PreferencesRepository extends MinecraftRepository
preparedStatement.setBoolean(13, entry.getValue().ClanTips); preparedStatement.setBoolean(13, entry.getValue().ClanTips);
preparedStatement.setBoolean(14, entry.getValue().HubMusic); preparedStatement.setBoolean(14, entry.getValue().HubMusic);
preparedStatement.setBoolean(15, entry.getValue().DisableAds); preparedStatement.setBoolean(15, entry.getValue().DisableAds);
preparedStatement.setBoolean(16, entry.getValue().ShowUserReports);
System.out.println(">> " + entry.getValue().ClanTips); System.out.println(">> " + entry.getValue().ClanTips);
preparedStatement.setString(16, entry.getKey()); preparedStatement.setString(17, entry.getKey());
preparedStatement.addBatch(); preparedStatement.addBatch();
} }
int[] rowsAffected = preparedStatement.executeBatch(); int[] rowsAffected = preparedStatement.executeBatch();
int i = 0; int i = 0;
@ -94,8 +96,9 @@ public class PreferencesRepository extends MinecraftRepository
preparedStatement.setBoolean(13, entry.getValue().ClanTips); preparedStatement.setBoolean(13, entry.getValue().ClanTips);
preparedStatement.setBoolean(14, entry.getValue().HubMusic); preparedStatement.setBoolean(14, entry.getValue().HubMusic);
preparedStatement.setBoolean(15, entry.getValue().DisableAds); preparedStatement.setBoolean(15, entry.getValue().DisableAds);
preparedStatement.setBoolean(16, entry.getValue().ShowUserReports);
System.out.println(">> " + entry.getValue().ClanTips); System.out.println(">> " + entry.getValue().ClanTips);
preparedStatement.setString(16, entry.getKey()); preparedStatement.setString(17, entry.getKey());
preparedStatement.execute(); preparedStatement.execute();
} }
@ -107,11 +110,11 @@ public class PreferencesRepository extends MinecraftRepository
exception.printStackTrace(); exception.printStackTrace();
} }
} }
public UserPreferences loadClientInformation(final ResultSet resultSet) throws SQLException public UserPreferences loadClientInformation(final ResultSet resultSet) throws SQLException
{ {
final UserPreferences preferences = new UserPreferences(); final UserPreferences preferences = new UserPreferences();
if (resultSet.next()) if (resultSet.next())
{ {
preferences.HubGames = resultSet.getBoolean(1); preferences.HubGames = resultSet.getBoolean(1);
@ -129,6 +132,7 @@ public class PreferencesRepository extends MinecraftRepository
preferences.ClanTips = resultSet.getBoolean(13); preferences.ClanTips = resultSet.getBoolean(13);
preferences.HubMusic = resultSet.getBoolean(14); preferences.HubMusic = resultSet.getBoolean(14);
preferences.DisableAds = resultSet.getBoolean(15); preferences.DisableAds = resultSet.getBoolean(15);
preferences.ShowUserReports = resultSet.getBoolean(16);
} }
return preferences; return preferences;

View File

@ -12,6 +12,7 @@ public class UserPreferences
public boolean Invisibility = false; public boolean Invisibility = false;
public boolean HubForcefield = false; public boolean HubForcefield = false;
public boolean ShowMacReports = false; public boolean ShowMacReports = false;
public boolean ShowUserReports = false;
public boolean IgnoreVelocity = false; public boolean IgnoreVelocity = false;
public boolean PendingFriendRequests = true; public boolean PendingFriendRequests = true;
public boolean friendDisplayInventoryUI = true; public boolean friendDisplayInventoryUI = true;

View File

@ -24,12 +24,14 @@ public class ExclusivePreferencesPage extends ShopPageBase<PreferencesManager, E
private IButton _toggleHubForcefield; private IButton _toggleHubForcefield;
private IButton _toggleHubIgnoreVelocity; private IButton _toggleHubIgnoreVelocity;
private IButton _toggleMacReports; private IButton _toggleMacReports;
private IButton _toggleUserReports;
private boolean _hubInvisibilityToggled; private boolean _hubInvisibilityToggled;
private boolean _hubForcefieldToggled; private boolean _hubForcefieldToggled;
private boolean _hubIgnoreVelocityToggled; private boolean _hubIgnoreVelocityToggled;
private boolean _macReportsToggled; private boolean _macReportsToggled;
private boolean _userReportsToggled;
private PreferencesShop _preferencesShop; private PreferencesShop _preferencesShop;
public ExclusivePreferencesPage(PreferencesManager plugin, ExclusivePreferencesShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, PreferencesShop preferencesShop) public ExclusivePreferencesPage(PreferencesManager plugin, ExclusivePreferencesShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, PreferencesShop preferencesShop)
@ -70,7 +72,16 @@ public class ExclusivePreferencesPage extends ShopPageBase<PreferencesManager, E
toggleMacReports(player); toggleMacReports(player);
} }
}; };
_toggleUserReports = new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
toggleUserReports(player);
}
};
_toggleHubIgnoreVelocity = new IButton() _toggleHubIgnoreVelocity = new IButton()
{ {
@Override @Override
@ -111,20 +122,21 @@ public class ExclusivePreferencesPage extends ShopPageBase<PreferencesManager, E
if (rank.has(Rank.ADMIN) || rank == Rank.JNR_DEV) if (rank.has(Rank.ADMIN) || rank == Rank.JNR_DEV)
{ {
int[] indices = UtilUI.getIndicesFor(4, 0, 2); int[] indices = UtilUI.getIndicesFor(5, 0, 2);
buildPreference(indices[0], Material.NETHER_STAR, "Hub Invisibility", userPreferences.Invisibility, _toggleHubInvisibility); buildPreference(indices[0], Material.NETHER_STAR, "Hub Invisibility", userPreferences.Invisibility, _toggleHubInvisibility);
buildPreference(indices[1], Material.SLIME_BALL, "Hub Forcefield", userPreferences.HubForcefield, _toggleHubForcefield); buildPreference(indices[1], Material.SLIME_BALL, "Hub Forcefield", userPreferences.HubForcefield, _toggleHubForcefield);
buildPreference(indices[2], Material.PAPER, "Mac Reports", userPreferences.ShowMacReports, _toggleMacReports); buildPreference(indices[2], Material.PAPER, "Mac Reports", userPreferences.ShowMacReports, _toggleMacReports);
buildPreference(indices[3], Material.SADDLE, "Hub Ignore Velocity", userPreferences.IgnoreVelocity, _toggleHubIgnoreVelocity); buildPreference(indices[3], Material.SADDLE, "Hub Ignore Velocity", userPreferences.IgnoreVelocity, _toggleHubIgnoreVelocity);
buildPreference(indices[4], Material.BOOK, "User Reports", userPreferences.ShowUserReports, _toggleUserReports);
} }
else if (rank.has(Rank.MODERATOR)) else if (rank.has(Rank.MODERATOR))
{ {
int[] indices = UtilUI.getIndicesFor(3, 0, 2); int[] indices = UtilUI.getIndicesFor(3, 0, 2);
buildPreference(indices[0], Material.NETHER_STAR, "Hub Invisibility", userPreferences.Invisibility, _toggleHubInvisibility); buildPreference(indices[0], Material.PAPER, "Mac Reports", userPreferences.ShowMacReports, _toggleMacReports);
buildPreference(indices[1], Material.PAPER, "Mac Reports", userPreferences.ShowMacReports, _toggleMacReports); buildPreference(indices[1], Material.SADDLE, "Hub Ignore Velocity", userPreferences.IgnoreVelocity, _toggleHubIgnoreVelocity);
buildPreference(indices[2], Material.SADDLE, "Hub Ignore Velocity", userPreferences.IgnoreVelocity, _toggleHubIgnoreVelocity); buildPreference(indices[2], Material.BOOK, "User Reports", userPreferences.ShowUserReports, _toggleUserReports);
} }
else if (rank == Rank.YOUTUBE || rank == Rank.TWITCH) else if (rank == Rank.YOUTUBE || rank == Rank.TWITCH)
{ {
@ -151,7 +163,7 @@ public class ExclusivePreferencesPage extends ShopPageBase<PreferencesManager, E
private void toggleHubInvisibility(org.bukkit.entity.Player player) private void toggleHubInvisibility(org.bukkit.entity.Player player)
{ {
if (getPlugin().getIncognitoManager() != null && getPlugin().getIncognitoManager().Get(player).Status) if (getPlugin().getIncognitoManager() != null && getPlugin().getIncognitoManager().Get(player).Status && /* Hub Invis & Incognito stuck prevention */ !getPlugin().Get(player).Invisibility)
{ {
UtilPlayer.message(player, F.main("Incognito", "You are not allowed to use Hub Visibility whilst in incognito mode.")); UtilPlayer.message(player, F.main("Incognito", "You are not allowed to use Hub Visibility whilst in incognito mode."));
return; return;
@ -180,7 +192,14 @@ public class ExclusivePreferencesPage extends ShopPageBase<PreferencesManager, E
_macReportsToggled = !_macReportsToggled; _macReportsToggled = !_macReportsToggled;
buildPage(); buildPage();
} }
private void toggleUserReports(org.bukkit.entity.Player player)
{
getPlugin().Get(player).ShowUserReports = !getPlugin().Get(player).ShowUserReports;
_userReportsToggled = !_userReportsToggled;
buildPage();
}
private void toggleHubIgnoreVelocity(org.bukkit.entity.Player player) private void toggleHubIgnoreVelocity(org.bukkit.entity.Player player)
{ {
getPlugin().Get(player).IgnoreVelocity = !getPlugin().Get(player).IgnoreVelocity; getPlugin().Get(player).IgnoreVelocity = !getPlugin().Get(player).IgnoreVelocity;
@ -203,6 +222,6 @@ public class ExclusivePreferencesPage extends ShopPageBase<PreferencesManager, E
public boolean preferencesChanged() public boolean preferencesChanged()
{ {
return _hubInvisibilityToggled || _macReportsToggled || _hubIgnoreVelocityToggled || _hubForcefieldToggled; return _hubInvisibilityToggled || _macReportsToggled || _hubIgnoreVelocityToggled || _hubForcefieldToggled || _userReportsToggled;
} }
} }

View File

@ -1,41 +1,99 @@
package mineplex.core.report; package mineplex.core.report;
import java.util.HashSet; import java.util.HashMap;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import mineplex.serverdata.data.Data; import mineplex.serverdata.data.Data;
import org.apache.commons.lang3.RandomStringUtils;
/**
* Contains data about a report.
* Active/open reports have their instances are stored in Redis for cross-server access.
*/
public class Report implements Data public class Report implements Data
{ {
private static final int TIMEOUT_MINS = 15;
private int _reportId; private int _reportId;
public int getReportId() { return _reportId; } public int getReportId() { return _reportId; }
private String _serverName; private String _serverName;
public String getServerName() { return _serverName; } public String getServerName() { return _serverName; }
private String _playerName; private UUID _suspect;
public String getPlayerName() { return _playerName; } public UUID getSuspect() { return _suspect; }
// Set of account ids of players who contributed to reporting this player // Set of player names and the reason they reported this player
private Set<String> _reporters; private Map<UUID, String> _reportReasons;
public Set<String> getReporters() { return _reporters; } public Map<UUID, String> getReportReasons() { return _reportReasons; }
public void addReporter(String reporter) { _reporters.add(reporter); } public Set<UUID> getReporters() { return _reportReasons.keySet(); }
public void addReporter(UUID reporter, String reason) { _reportReasons.put(reporter, reason); }
/**
* Class constructor private UUID _handler = null;
* @param reportId public void setHandler(UUID handler) { _handler = handler; }
* @param playerName public UUID getHandler() { return _handler; }
* @param serverName
*/ private ReportCategory _category;
public Report(int reportId, String playerName, String serverName) public ReportCategory getCategory() { return _category; }
private long _lastActivity;
public long getLastActivity() { return _lastActivity; }
private String _token = null;
public Report(int reportId, UUID suspect, String serverName, ReportCategory category)
{ {
_reportId = reportId; _reportId = reportId;
_playerName = playerName; _suspect = suspect;
_serverName = serverName; _serverName = serverName;
_reporters = new HashSet<String>(); _reportReasons = new HashMap<>();
_category = category;
updateLastActivity();
} }
/**
* Checks if a report is still active.
* This is determined by checking if the last activity was within the last 15 minutes.
*
* @return true if active, false if expired
*/
public boolean isActive()
{
return _lastActivity + TimeUnit.MINUTES.toMillis(TIMEOUT_MINS) >= System.currentTimeMillis();
}
public void updateLastActivity()
{
_lastActivity = System.currentTimeMillis();
}
public boolean hasToken()
{
return _token != null;
}
/**
* Gets a token in the format of reportId-randomCharacters.
* Currently this is only used for publishing chat abuse reports.
*
* @return the full token
*/
public String getToken()
{
// since we don't always use this, only generate a token when we need it
if (_token == null)
{
_token = RandomStringUtils.randomAlphabetic(8);
}
return _reportId + "-" + _token;
}
@Override @Override
public String getDataId() public String getDataId()
{ {

View File

@ -0,0 +1,77 @@
package mineplex.core.report;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import mineplex.core.common.util.C;
/**
* Contains the reasons a player can be reported for.
*/
public enum ReportCategory
{
// descriptions borrowed from PunishPage
HACKING(0, 3, Material.IRON_SWORD, C.cRedB + "Hacking", "X-ray, Forcefield, Speed, Fly etc"),
CHAT_ABUSE(1, 1, Material.BOOK_AND_QUILL, C.cDAquaB + "Chat Abuse", "Verbal Abuse, Spam, Harassment, Trolling, etc");
private int _id;
private int _notifyThreshold;
private Material _displayMaterial;
private String _title;
private List<String> _lore;
ReportCategory(int id, int notifyThreshold, Material displayMaterial, String title, String... lore)
{
_id = id;
_notifyThreshold = notifyThreshold;
_displayMaterial = displayMaterial;
_title = title;
_lore = new ArrayList<>();
// prefix are lore lines
for (String loreLine : lore) {
_lore.add(C.cGray + loreLine);
}
}
public int getId()
{
return _id;
}
public int getNotifyThreshold()
{
return _notifyThreshold;
}
public Material getItemMaterial()
{
return _displayMaterial;
}
public String getTitle()
{
return _title;
}
public List<String> getDescription()
{
return _lore;
}
public static ReportCategory fromId(int id)
{
for (ReportCategory category : values())
{
if (category.getId() == id)
{
return category;
}
}
return null;
}
}

View File

@ -1,21 +1,44 @@
package mineplex.core.report; package mineplex.core.report;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Set;
import java.util.UUID;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.chatsnap.Snapshot;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
import mineplex.core.command.CommandCenter; import mineplex.core.command.CommandCenter;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.Rank;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.report.command.ReportHandlerNotification;
import mineplex.core.report.command.ReportNotificationCallback;
import mineplex.core.report.command.ReportNotification; import mineplex.core.report.command.ReportNotification;
import mineplex.core.report.task.ReportHandlerMessageTask;
import mineplex.core.stats.PlayerStats;
import mineplex.core.stats.StatsManager;
import mineplex.serverdata.Region; import mineplex.serverdata.Region;
import mineplex.serverdata.Utility; import mineplex.serverdata.Utility;
import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.redis.RedisDataRepository; import mineplex.serverdata.redis.RedisDataRepository;
import org.bukkit.ChatColor; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
@ -24,282 +47,438 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
/** /**
* ReportManager hooks into a synchronized network-wide report system * ReportManager hooks into a synchronized network-wide report system
* with methods for updating/fetching/closing reports in real time. * with methods for updating/fetching/closing reports in real time.
* @author Ty
*
*/ */
public class ReportManager { public class ReportManager
{
private static ReportManager instance;
private static final String NAME = "Report";
// statistic constants
private static final String STAT_TOTAL_COUNT = "Global.TotalReportsCount";
private static final int ABUSE_BAN_THRESHOLD = 1;
private JavaPlugin _javaPlugin;
private PreferencesManager _preferencesManager;
private StatsManager _statsManager;
private SnapshotManager _snapshotManager;
private CoreClientManager _coreClientManager;
private String _serverName;
// Holds active/open reports in a synchronized database. // Holds active/open reports in a synchronized database.
private DataRepository<Report> reportRepository; private DataRepository<Report> _reportRepository;
private DataRepository<ReportProfile> reportProfiles;
// Stores/logs closed tickets, and various reporter/staff actions. // Stores/logs closed tickets, and various reporter/staff actions.
private ReportRepository reportSqlRepository; private ReportRepository _reportSqlRepository;
// A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server. // A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server.
private Map<String, Integer> activeReports; private Map<String, Integer> _activeReports;
/** public ReportManager(JavaPlugin javaPlugin, PreferencesManager preferencesManager, StatsManager statsManager,
* Private constructor to prevent non-singleton instances. SnapshotManager snapshotManager, CoreClientManager coreClientManager, String serverName)
*/
private ReportManager()
{ {
this.reportRepository = new RedisDataRepository<Report>(Region.ALL, Report.class, "reports"); _javaPlugin = javaPlugin;
this.reportProfiles = new RedisDataRepository<ReportProfile>(Region.ALL, ReportProfile.class, "reportprofiles"); _preferencesManager = preferencesManager;
this.activeReports = new HashMap<String, Integer>(); _statsManager = statsManager;
_snapshotManager = snapshotManager;
// TODO: Get JavaPlugin instance and locate ConnectionString from config? _coreClientManager = coreClientManager;
this.reportSqlRepository = new ReportRepository(ReportPlugin.getPluginInstance(), "CONNECTION STRING HERE"); _serverName = serverName;
reportSqlRepository.initialize(); _reportRepository = new RedisDataRepository<>(Region.ALL, Report.class, "reports");
_activeReports = new HashMap<>();
_reportSqlRepository = new ReportRepository(javaPlugin);
_reportSqlRepository.initialize();
ReportNotificationCallback callback = new ReportNotificationCallback(this);
ServerCommandManager.getInstance().registerCommandType("ReportNotification", ReportNotification.class, callback);
ServerCommandManager.getInstance().registerCommandType("ReportHandlerNotification", ReportHandlerNotification.class, callback);
} }
public void retrieveReportResult(int reportId, Player reportCloser, String reason)
{
// Prompt the report closer with a menu of options to determine the result
// of the report. When confirmation is received, THEN close report.
}
public void closeReport(int reportId, Player reportCloser, String reason)
{
retrieveReportResult(reportId, reportCloser, reason);
}
public void closeReport(int reportId, Player reportCloser, String reason, public void closeReport(int reportId, Player reportCloser, String reason,
ReportResult result) ReportResult result)
{ {
if (isActiveReport(reportId)) Report report = getReport(reportId);
if (report != null)
{ {
Report report = getReport(reportId); removeReport(reportId);
reportRepository.removeElement(String.valueOf(reportId)); // Remove report from redis database
removeActiveReport(reportId); int closerId = reportCloser != null ? _coreClientManager.Get(reportCloser).getAccountId() : -1;
String suspectName = Bukkit.getOfflinePlayer(report.getSuspect()).getName();
int closerId = getPlayerAccount(reportCloser).getAccountId(); int playerId = _coreClientManager.Get(suspectName).getAccountId();
String playerName = getReport(reportId).getPlayerName(); _reportSqlRepository.logReport(reportId, playerId, _serverName, closerId, result, reason);
int playerId = getPlayerAccount(playerName).getAccountId();
String server = null; // TODO: Get current server name
reportSqlRepository.logReport(reportId, playerId, server, closerId, result, reason);
// Update the reputation/profiles of all reporters on this closing report. // Update the reputation/profiles of all reporters on this closing report.
for (String reporterName : report.getReporters()) for (UUID reporterUUID : report.getReporters())
{ {
CoreClient reporterAccount = getPlayerAccount(reporterName); String reporterName = Bukkit.getOfflinePlayer(reporterUUID).getName();
ReportProfile reportProfile = getReportProfile(String.valueOf(reporterAccount.getAccountId())); incrementStat(reporterName, result);
reportProfile.onReportClose(result);
reportProfiles.addElement(reportProfile);
} }
if (reportCloser != null) if (reportCloser != null)
{ {
// Notify staff that the report was closed. // Notify staff that the report was closed.
sendReportNotification(String.format("[Report %d] %s closed this report. (%s).", reportId, sendStaffNotification(
reportCloser.getName(), result.toDisplayMessage())); F.main(getReportPrefix(reportId), String.format("%s closed the report for: %s (%s).",
reportCloser.getName(), reason, result.toDisplayMessage() + C.mBody)));
CommandCenter.Instance.OnPlayerCommandPreprocess(
new PlayerCommandPreprocessEvent(reportCloser, "/punish " + suspectName + " " + reason));
}
if (report.getCategory() == ReportCategory.CHAT_ABUSE) // only chat abuse reports have chat logs published
{
_snapshotManager.getSnapshotPublisher().unpublishChatLog(report.getToken());
} }
} }
} }
public void handleReport(int reportId, Player reportHandler) public void handleReport(int reportId, Player reportHandler)
{ {
if (reportRepository.elementExists(String.valueOf(reportId))) Report report = getReport(reportId);
if (report != null)
{ {
Report report = getReport(reportId); if (report.getHandler() != null) {
Portal.transferPlayer(reportHandler.getName(), report.getServerName()); reportHandler.sendMessage(F.main(getReportPrefix(reportId), String.format("%s is already handling this report.", report.getHandler())));
String handlerName = reportHandler.getName(); } else {
sendReportNotification(String.format("[Report %d] %s is handling this report.", reportId, handlerName)); String handlerName = reportHandler.getName();
report.setHandler(reportHandler.getUniqueId());
// TODO: Send display message to handler when they arrive on the server publishChatSnap(report, false); // so handler is displayed on the web side
// with info about the case/report. saveReport(report);
int handlerId = getPlayerAccount(reportHandler).getAccountId(); sendStaffNotification(F.main(getReportPrefix(reportId), String.format("%s is handling this report.", handlerName)));
reportSqlRepository.logReportHandling(reportId, handlerId); // Log handling into sql database Portal.transferPlayer(reportHandler.getName(), report.getServerName());
// Show user details of the report every x seconds
new ReportHandlerMessageTask(this, report).runTaskTimer(_javaPlugin, 20L * 10, 20L * 10);
}
} }
} }
public void reportPlayer(Player reporter, Player reportedPlayer, String reason) public boolean canReport(Player player)
{ {
int reporterId = getPlayerAccount(reporter).getAccountId(); PlayerStats playerStats = _statsManager.Get(player.getName());
ReportProfile reportProfile = getReportProfile(String.valueOf(reporterId)); long abusiveReportsCount = playerStats.getStat(ReportResult.ABUSIVE.getStatName());
return abusiveReportsCount < ABUSE_BAN_THRESHOLD;
if (reportProfile.canReport()) }
private void incrementTotalStat(String reporter)
{
int accountId = _coreClientManager.Get(reporter).getAccountId();
_statsManager.incrementStat(accountId, STAT_TOTAL_COUNT, 1);
}
private void incrementStat(String reporter, ReportResult reportResult)
{
String statName = reportResult.getStatName();
if (statName != null)
{ {
Report report = null; int accountId = _coreClientManager.Get(reporter).getAccountId();
_statsManager.incrementStat(accountId, statName, 1);
if (hasActiveReport(reportedPlayer)) }
}
public Report reportPlayer(Player reporter, Player reportedPlayer, ReportCategory category, String reason)
{
if (canReport(reportedPlayer))
{
Report report = getActiveReport(reportedPlayer.getName());
if (report != null && report.getCategory() == category)
{ {
int reportId = getActiveReport(reportedPlayer.getName()); report.addReporter(reporter.getUniqueId(), reason);
report = getReport(reportId);
report.addReporter(reporter.getName());
} }
else else
{ {
String serverName = null; // TODO: Fetch name of current server report = new Report(generateReportId(), reportedPlayer.getUniqueId(), _serverName, category);
int reportId = generateReportId(); report.addReporter(reporter.getUniqueId(), reason);
report = new Report(reportId, reportedPlayer.getName(), serverName); _activeReports.put(reportedPlayer.getName().toLowerCase(), report.getReportId());
report.addReporter(reporter.getName());
activeReports.put(reportedPlayer.getName().toLowerCase(), report.getReportId());
reportRepository.addElement(report);
} }
if (report != null) incrementTotalStat(reporter.getName());
// only start notifying staff when
if (report.getReporters().size() >= category.getNotifyThreshold())
{ {
// [Report 42] [MrTwiggy +7] [Cheater102 - 5 - Speed hacking] if (report.getCategory() == ReportCategory.CHAT_ABUSE)
String message = String.format("[Report %d] [%s %d] [%s - %d - %s]", report.getReportId(), {
reporter.getName(), reportProfile.getReputation(), publishChatSnap(report, true);
reportedPlayer.getName(), report.getReporters().size(), reason); }
sendReportNotification(message);
reportSqlRepository.logReportSending(report.getReportId(), reporterId, reason); int reportId = report.getReportId();
} String prefix = getReportPrefix(reportId);
String suspectName = Bukkit.getOfflinePlayer(report.getSuspect()).getName();
// Report #2 > iKeirNez - Flying around in arcade game (Hacking)
// Report #2 > Reported by Chiss.
// Report #2 > 5 total reporter(s).
JsonMessage message = new JsonMessage(F.main(prefix, String.format("%s - %s (%s)",
C.cGoldB + suspectName + C.mBody,
reason, C.cGoldB + report.getCategory().getTitle() + C.mBody))
+ "\n"
+ F.main(prefix, String.format("Reported by %s.", reporter.getName()))
+ "\n"
+ F.main(prefix, String.format("%d total reporter(s).", report.getReporters().size())));
if (report.getHandler() == null)
{
// this needs to be 'equals' otherwise we get errors when attempting to send this (due to incomplete JSON)
message = message.extra("\n" + F.main(prefix, "Click to handle this ticket."))
.click(ClickEvent.RUN_COMMAND, "/reporthandle " + reportId);
sendStaffNotification(message);
}
else
{
sendHandlerNotification(report, message);
}
}
// save later so that token is saved (if created)
saveReport(report);
return report;
} }
return null;
} }
public void onPlayerQuit(Player player) public void publishChatSnap(Report report, boolean updateChat)
{
SnapshotPublisher publisher = _snapshotManager.getSnapshotPublisher();
Gson gson = SnapshotPublisher.getGson();
Set<UUID> uuids = getUUIDs(report);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("timezone", SnapshotPublisher.getZoneId().getId());
jsonObject.add("generated", gson.toJsonTree(LocalDateTime.now()));
jsonObject.add("report", gson.toJsonTree(report));
if (updateChat)
{
Set<Snapshot> snapshots = _snapshotManager.getSnapshots(report.getSuspect());
uuids.addAll(publisher.getUUIDs(snapshots));
jsonObject.add("snapshots", gson.toJsonTree(snapshots));
}
Map<UUID, String> usernameMap = publisher.getUsernameMap(uuids);
jsonObject.add("usernames", gson.toJsonTree(usernameMap));
publisher.publishChatLog(report.getToken(), jsonObject);
}
private Set<UUID> getUUIDs(Report report)
{
Set<UUID> uuids = new HashSet<>(report.getReporters());
uuids.add(report.getSuspect());
if (report.getHandler() != null)
{
uuids.add(report.getHandler());
}
return uuids;
}
public void onPlayerJoin(Player player)
{ {
if (hasActiveReport(player)) if (hasActiveReport(player))
{ {
int reportId = getActiveReport(player.getName()); Report report = getActiveReport(player.getName());
this.closeReport(reportId, null, "Player Quit", ReportResult.UNDETERMINED); sendHandlerNotification(report, F.main(getReportPrefix(report), String.format("%s has re-joined the game.", player.getName())));
// TODO: Handle 'null' report closer in closeReport metohd for NPEs.
sendReportNotification(String.format("[Report %d] %s has left the game.", reportId, player.getName()));
} }
} }
public ReportProfile getReportProfile(String playerName) public void onPlayerQuit(Player player)
{ {
ReportProfile profile = reportProfiles.getElement(playerName); if (hasActiveReport(player))
if (profile == null)
{ {
profile = new ReportProfile(playerName, getAccountId(playerName)); Report report = getActiveReport(player.getName());
saveReportProfile(profile); sendHandlerNotification(report, F.main(getReportPrefix(report), String.format("%s has left the game.", player.getName())));
} }
return profile;
} }
private void saveReportProfile(ReportProfile profile)
{
reportProfiles.addElement(profile);
}
/** /**
* @return a uniquely generated report id. * @return a uniquely generated report id.
*/ */
public int generateReportId() public int generateReportId()
{ {
JedisPool pool = Utility.getPool(true); JedisPool pool = Utility.getPool(true);
Jedis jedis = pool.getResource();
long uniqueReportId = -1; long uniqueReportId = -1;
try (Jedis jedis = pool.getResource()) try
{ {
uniqueReportId = jedis.incr("reports.unique-id"); uniqueReportId = jedis.incr("reports.unique-id");
} }
catch (JedisConnectionException exception)
{
exception.printStackTrace();
pool.returnBrokenResource(jedis);
jedis = null;
}
finally
{
if (jedis != null)
{
pool.returnResource(jedis);
}
}
return (int) uniqueReportId; return (int) uniqueReportId;
} }
public Report getReport(int reportId) public Report getReport(int reportId)
{ {
return reportRepository.getElement(String.valueOf(reportId)); return _reportRepository.getElement(String.valueOf(reportId));
} }
private CoreClient getPlayerAccount(Player player) /**
* Updates the instance of a report in the repository.
* Also updates the last activity field.
*
* @param report the report to be saved
*/
public void saveReport(Report report)
{ {
return getPlayerAccount(player.getName()); report.updateLastActivity();
_reportRepository.addElement(report);
} }
private CoreClient getPlayerAccount(String playerName) public void removeReport(int reportId)
{ {
return CommandCenter.Instance.GetClientManager().Get(playerName); _reportRepository.removeElement(String.valueOf(reportId));
} }
private int getAccountId(String playerName)
{
return getPlayerAccount(playerName).getAccountId();
}
/** /**
* @param player - the player whose report notification settings are to be checked * @param player - the player whose report notification settings are to be checked
* @return true, if the player should receive report notifications, false otherwise. * @return true, if the player should receive report notifications, false otherwise.
*/ */
public boolean hasReportNotifications(Player player) public boolean hasReportNotifications(Player player)
{ {
// If player is not staff, return false. boolean isStaff = CommandCenter.Instance.GetClientManager().Get(player).GetRank().has(Rank.MODERATOR);
// If player is staff but has report notifications pref disabled, return false; boolean hasReportNotifications = _preferencesManager.Get(player).ShowUserReports;
// Else return true. return isStaff && hasReportNotifications;
return false;
} }
/** /**
* Send a network-wide {@link ReportNotification} to all online staff. * Send a network-wide {@link ReportNotification} to all online staff.
*
* @param message - the report notification message to send. * @param message - the report notification message to send.
*/ */
public void sendReportNotification(String message) public void sendStaffNotification(JsonMessage message)
{ {
ReportNotification reportNotification = new ReportNotification(message); ReportNotification reportNotification = new ReportNotification(message);
reportNotification.publish(); reportNotification.publish();
} }
/**
* Send a network-wide {@link ReportNotification} to all online staff.
*
* @param message - the report notification message to send.
*/
public void sendStaffNotification(String message)
{
ReportNotification reportNotification = new ReportNotification(message);
reportNotification.publish();
}
/**
* Send to the handler of a {@link Report}, regardless of whether or not the handler is currently on this server instance.
* If there is no handler for a report, it will be sent to all staff instead.
*
* @param report the report of which a message should be sent ot it's handler
* @param jsonMessage the report notification message to send
*/
public void sendHandlerNotification(Report report, JsonMessage jsonMessage)
{
if (report.getHandler() != null)
{
ReportHandlerNotification reportHandlerNotification = new ReportHandlerNotification(report, jsonMessage);
reportHandlerNotification.publish();
}
else
{
// If there is no report handler, send it to all staff
sendStaffNotification(jsonMessage);
}
}
/**
* Send to the handler of a {@link Report}, regardless of whether or not the handler is currently on this server instance.
* If there is no handler for a report, it will be sent to all staff instead.
*
* @param report the report of which a message should be sent ot it's handler
* @param message the report notification message to send
*/
public void sendHandlerNotification(Report report, String message)
{
sendHandlerNotification(report, new JsonMessage(message));
}
/** /**
* @param playerName - the name of the player whose active report id is being fetched * @param playerName - the name of the player whose active report id is being fetched
* @return the report id for the active report corresponding with playerName, if one * @return the report id for the active report corresponding with playerName, if one
* currently exists, -1 otherwise. * currently exists, -1 otherwise.
*/ */
public int getActiveReport(String playerName) public Report getActiveReport(String playerName)
{ {
if (activeReports.containsKey(playerName.toLowerCase())) Integer reportId = _activeReports.get(playerName.toLowerCase());
if (reportId != null)
{ {
return activeReports.get(playerName.toLowerCase()); return getReport(reportId);
} }
return -1; return null;
} }
public boolean hasActiveReport(Player player) public boolean hasActiveReport(Player player)
{ {
return getActiveReport(player.getName()) != -1; return getActiveReport(player.getName()) != null;
} }
public boolean isActiveReport(int reportId) public boolean isActiveReport(int reportId)
{ {
for (Entry<String, Integer> activeReport : activeReports.entrySet()) for (Map.Entry<String, Integer> activeReport : _activeReports.entrySet())
{ {
if (activeReport.getValue() == reportId) if (activeReport.getValue() == reportId)
{ {
return true; return true;
} }
} }
return false; return false;
} }
public boolean removeActiveReport(int reportId) public boolean removeActiveReport(int reportId)
{ {
for (Entry<String, Integer> activeReport : activeReports.entrySet()) for (Map.Entry<String, Integer> activeReport : _activeReports.entrySet())
{ {
if (activeReport.getValue() == reportId) if (activeReport.getValue() == reportId)
{ {
activeReports.remove(activeReport.getKey()); _activeReports.remove(activeReport.getKey());
return true; return true;
} }
} }
return false; return false;
} }
/** public Collection<Integer> getActiveReports()
* @return the singleton instance of {@link ReportManager}.
*/
public static ReportManager getInstance()
{ {
if (instance == null) return _activeReports.values();
{ }
instance = new ReportManager();
} /* STATIC HELPERS */
return instance; public static String getReportPrefix(Report report)
{
return getReportPrefix(report.getReportId());
}
public static String getReportPrefix(int reportId)
{
return NAME + " #" + reportId;
} }
} }

View File

@ -4,28 +4,60 @@ import mineplex.core.MiniPlugin;
import mineplex.core.report.command.ReportCloseCommand; import mineplex.core.report.command.ReportCloseCommand;
import mineplex.core.report.command.ReportCommand; import mineplex.core.report.command.ReportCommand;
import mineplex.core.report.command.ReportHandleCommand; import mineplex.core.report.command.ReportHandleCommand;
import mineplex.core.report.task.ReportPurgeTask;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
/**
* Main class for this module, handles initialization and disabling of the module.
*/
public class ReportPlugin extends MiniPlugin public class ReportPlugin extends MiniPlugin
{ {
private final ReportManager _reportManager;
private ReportPurgeTask _reportPurgeTask;
private static JavaPlugin instance; public ReportPlugin(JavaPlugin plugin, ReportManager reportManager)
public static JavaPlugin getPluginInstance() { return instance; }
public ReportPlugin(JavaPlugin plugin, String serverName)
{ {
super("ReportPlugin", plugin); super("Report", plugin);
instance = plugin; _reportManager = reportManager;
// purge old reports every minute
_reportPurgeTask = new ReportPurgeTask(_reportManager);
_reportPurgeTask.runTaskTimerAsynchronously(getPlugin(), 20L * 10, 20L * 60);
} }
@Override
public void disable()
{
_reportPurgeTask.cancel();
}
public ReportManager getReportManager()
{
return _reportManager;
}
@Override @Override
public void addCommands() public void addCommands()
{ {
addCommand(new ReportCommand(this)); addCommand(new ReportCommand(this));
addCommand(new ReportHandleCommand(this)); addCommand(new ReportHandleCommand(this));
addCommand(new ReportCloseCommand(this)); addCommand(new ReportCloseCommand(this));
//AddCommand(new ReportDebugCommand(this)); }
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e)
{
_reportManager.onPlayerJoin(e.getPlayer());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e)
{
_reportManager.onPlayerQuit(e.getPlayer());
} }
} }

View File

@ -1,61 +0,0 @@
package mineplex.core.report;
import mineplex.serverdata.data.Data;
public class ReportProfile implements Data
{
private String _playerName;
private int _playerId;
private int _totalReports;
private int _successfulReports;
private int _reputation;
public int getReputation() { return _reputation; }
private boolean _banned;
public ReportProfile(String playerName, int playerId)
{
_playerName = playerName;
_playerId = playerId;
_totalReports = 0;
_successfulReports = 0;
_reputation = 0;
_banned = false;
}
@Override
public String getDataId()
{
return String.valueOf(_playerId);
}
public boolean canReport()
{
return !_banned;
}
/**
* Called when a report made by this player is closed.
* @param result - the result of the closed report.
*/
public void onReportClose(ReportResult result)
{
_totalReports++;
if (result == ReportResult.MUTED || result == ReportResult.BANNED)
{
_successfulReports++;
_reputation++;
}
else if (result == ReportResult.ABUSE)
{
_reputation = -1;
_banned = true;
}
}
}

View File

@ -2,36 +2,22 @@ package mineplex.core.report;
import mineplex.core.database.MinecraftRepository; import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.DatabaseRunnable;
import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt; import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.serverdata.database.column.ColumnVarChar;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
/**
* Responsible for all database related operations for this module.
*/
public class ReportRepository extends MinecraftRepository public class ReportRepository extends MinecraftRepository
{ {
/* private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), FOREIGN KEY (playerId) REFERENCES accounts(id), FOREIGN KEY (closerId) REFERENCES accounts(id));";
* *ReportTicket
id, date, accountId reported player, server, accountId of staff who closed, result, reason
ReportSenders
id, date, reportId, accountId of Reporter, Reason for report
ReportHandlers
id, date, reportId, accountId of Staff
This will be used to determine if staff are handling
*/
private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, date LONG, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), INDEX playerIdIndex (playerId), INDEX closerIdIndex (closerId));";
private static String CREATE_HANDLER_TABLE = "CREATE TABLE IF NOT EXISTS reportHandlers (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, handlerId INT NOT NULL, PRIMARY KEY (id), INDEX handlerIdIndex (handlerId) );";
private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));";
private static String INSERT_TICKET = "INSERT INTO reportTickets (reportId, eventDate, playerId, server, closerId, result, reason) VALUES (?, now(), ?, ?, ?, ?, ?);"; private static String INSERT_TICKET = "INSERT INTO reportTickets (reportId, eventDate, playerId, server, closerId, result, reason) VALUES (?, now(), ?, ?, ?, ?, ?);";
private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);";
private static String INSERT_SENDER = "INSERT INTO reportSenders (eventDate, reportId, reporterId, reason) VALUES(now(), ?, ?, ?);";
public ReportRepository(JavaPlugin plugin, String connectionString) public ReportRepository(JavaPlugin plugin)
{ {
super(plugin, DBPool.getAccount()); super(plugin, DBPool.getAccount());
} }
@ -39,11 +25,7 @@ This will be used to determine if staff are handling
@Override @Override
protected void initialize() protected void initialize()
{ {
/* // executeUpdate(CREATE_TICKET_TABLE);
executeUpdate(CREATE_TICKET_TABLE);
executeUpdate(CREATE_HANDLER_TABLE);
executeUpdate(CREATE_REPORTERS_TABLE);
*/
} }
@Override @Override
@ -52,22 +34,17 @@ This will be used to determine if staff are handling
} }
public void logReportHandling(int reportId, int handlerId) public void logReport(final int reportId, final int playerId, final String server, final int closerId, final ReportResult result, final String reason)
{ {
executeUpdate(INSERT_HANDLER, new ColumnInt("reportId", reportId), new ColumnInt("handlerId", handlerId)); handleDatabaseCall(new DatabaseRunnable(new Runnable()
{
@Override
public void run()
{
executeUpdate(INSERT_TICKET, new ColumnInt("reportId", reportId), new ColumnInt("playerId", playerId),
new ColumnVarChar("server", 50, server), new ColumnInt("closerId", closerId),
new ColumnVarChar("result", 25, result.toString()), new ColumnVarChar("reason", 100, reason));
}
}), "Error logging result for report " + reportId + ".");
} }
public void logReportSending(int reportId, int reporterId, String reason)
{
executeUpdate(INSERT_SENDER, new ColumnInt("reportId", reportId), new ColumnInt("reporterId", reporterId),
new ColumnVarChar("reason", 100, reason));
}
public void logReport(int reportId, int playerId, String server, int closerId, ReportResult result, String reason)
{
executeUpdate(INSERT_TICKET, new ColumnInt("reportId", reportId), new ColumnInt("playerId", playerId),
new ColumnVarChar("server", 50, server), new ColumnInt("closerId", closerId),
new ColumnVarChar("result", 25, result.toString()), new ColumnVarChar("reason", 100, reason));
}
} }

View File

@ -2,24 +2,57 @@ package mineplex.core.report;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
/**
* Contains all possible outcomes for a report.
*/
public enum ReportResult public enum ReportResult
{ {
UNDETERMINED(ChatColor.WHITE, "Could not determine"), ACCEPTED("Global.AcceptedReportsCount", ChatColor.GREEN, "Accept Report (Punish Player)", "Accepted (Player Received Punishment)"),
MUTED(ChatColor.YELLOW, "Muted"), DENIED("Global.DeniedReportsCount", ChatColor.YELLOW, "Deny Report", "Denied"),
BANNED(ChatColor.RED, "Banned"), ABUSIVE("Global.AbusiveReportsCount", ChatColor.RED, "Mark Abusive Report", "Abusive Report");
ABUSE(ChatColor.DARK_RED, "Abuse of report system");
private final String _statName;
private ChatColor color; private final ChatColor _color;
private String displayMessage; private final String _actionMessage;
private final String _resultMessage;
private ReportResult(ChatColor color, String displayMessage) private final String[] _lore;
ReportResult(String statName, ChatColor color, String actionMessage, String resultMessage, String... lore)
{ {
this.color = color; _statName = statName;
this.displayMessage = displayMessage; _color = color;
_actionMessage = actionMessage;
_resultMessage = resultMessage;
_lore = lore;
} }
public String getStatName()
{
return _statName;
}
public ChatColor getColor()
{
return _color;
}
public String getActionMessage()
{
return _actionMessage;
}
public String getResultMessage()
{
return _resultMessage;
}
public String[] getLore()
{
return _lore;
}
public String toDisplayMessage() public String toDisplayMessage()
{ {
return color + displayMessage; return _color + _resultMessage;
} }
} }

View File

@ -3,12 +3,11 @@ package mineplex.core.report.command;
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.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.portal.Portal;
import mineplex.core.report.ReportManager; import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin; import mineplex.core.report.ReportPlugin;
import mineplex.core.report.ui.ReportResultPage;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -17,7 +16,7 @@ public class ReportCloseCommand extends CommandBase<ReportPlugin>
public ReportCloseCommand(ReportPlugin plugin) public ReportCloseCommand(ReportPlugin plugin)
{ {
super(plugin, Rank.ADMIN, "reportclose", "rc"); super(plugin, Rank.MODERATOR, "reportclose", "rc");
} }
@Override @Override
@ -32,8 +31,16 @@ public class ReportCloseCommand extends CommandBase<ReportPlugin>
{ {
int reportId = Integer.parseInt(args[0]); int reportId = Integer.parseInt(args[0]);
String reason = F.combine(args, 1, null, false); String reason = F.combine(args, 1, null, false);
ReportManager.getInstance().closeReport(reportId, player, reason); if (Plugin.getReportManager().isActiveReport(reportId))
{
ReportResultPage reportResultPage = new ReportResultPage(Plugin, reportId, player, reason);
reportResultPage.openInventory(); // report is closed when player selects the result
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "That report either does not exist or has been closed."));
}
} }
} }
} }

View File

@ -3,12 +3,10 @@ package mineplex.core.report.command;
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.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.portal.Portal;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin; import mineplex.core.report.ReportPlugin;
import mineplex.core.report.ui.ReportCategoryPage;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -22,11 +20,14 @@ public class ReportCommand extends CommandBase<ReportPlugin>
@Override @Override
public void Execute(final Player player, final String[] args) public void Execute(final Player player, final String[] args)
{ {
if(args == null || args.length < 2) if (!CommandCenter.GetClientManager().hasRank(player, Rank.ULTRA))
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "The report feature is currently in a trial phase for Ultra+ players"));
}
else if(args == null || args.length < 2)
{ {
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!")); UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
} }
else else
{ {
@ -36,7 +37,14 @@ public class ReportCommand extends CommandBase<ReportPlugin>
if (reportedPlayer != null) if (reportedPlayer != null)
{ {
ReportManager.getInstance().reportPlayer(player, reportedPlayer, reason); if (reportedPlayer == player)
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "You cannot report yourself."));
}
else
{
new ReportCategoryPage(Plugin, player, reportedPlayer, reason).openInventory();
}
} }
else else
{ {

View File

@ -3,10 +3,8 @@ package mineplex.core.report.command;
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.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.portal.Portal;
import mineplex.core.report.ReportManager; import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin; import mineplex.core.report.ReportPlugin;
@ -17,7 +15,7 @@ public class ReportHandleCommand extends CommandBase<ReportPlugin>
public ReportHandleCommand(ReportPlugin plugin) public ReportHandleCommand(ReportPlugin plugin)
{ {
super(plugin, Rank.ADMIN, "reporthandle", "rh"); super(plugin, Rank.MODERATOR, "reporthandle", "rh");
} }
@Override @Override
@ -26,13 +24,12 @@ public class ReportHandleCommand extends CommandBase<ReportPlugin>
if(args == null || args.length < 1) if(args == null || args.length < 1)
{ {
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!")); UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
} }
else else
{ {
int reportId = Integer.parseInt(args[0]); int reportId = Integer.parseInt(args[0]);
ReportManager.getInstance().handleReport(reportId, player); Plugin.getReportManager().handleReport(reportId, player);
} }
} }
} }

View File

@ -0,0 +1,42 @@
package mineplex.core.report.command;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.report.Report;
/**
* A message regarding a report which is sent only to the player handling the report.
*/
public class ReportHandlerNotification extends ReportNotification
{
private int _reportId;
private String _server; // the server the incident took place on
public ReportHandlerNotification(Report report, String notification)
{
this(report, new JsonMessage(notification));
}
public ReportHandlerNotification(Report report, JsonMessage notification)
{
super(notification);
if (report.getHandler() == null)
{
throw new IllegalStateException("Report has no handler.");
}
_reportId = report.getReportId();
_server = report.getServerName();
setTargetServers(_server);
}
public int getReportId()
{
return _reportId;
}
public String getServer()
{
return _server;
}
}

View File

@ -1,31 +1,33 @@
package mineplex.core.report.command; package mineplex.core.report.command;
import org.bukkit.entity.Player; import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.UtilServer;
import mineplex.core.report.ReportManager;
import mineplex.serverdata.commands.ServerCommand; import mineplex.serverdata.commands.ServerCommand;
/**
* A message regarding a report which should be sent to all moderators with report notifications enabled.
*/
public class ReportNotification extends ServerCommand public class ReportNotification extends ServerCommand
{ {
private String _notification; // in json format
// TODO: Encode in JSON-interactive chat message
private String notification;
public ReportNotification(String notification) public ReportNotification(String notification)
{ {
super(); // Send to all servers this(new JsonMessage(notification));
} }
public ReportNotification(JsonMessage notification)
{
super(); // Send to all servers
_notification = notification.toString();
}
public String getNotification()
{
return _notification;
}
public void run() public void run()
{ {
// Message all players that can receive report notifications. // Utilitizes a callback functionality to seperate dependencies
for (Player player : UtilServer.getPlayers())
{
if (ReportManager.getInstance().hasReportNotifications(player))
{
player.sendMessage(notification);
}
}
} }
} }

View File

@ -0,0 +1,70 @@
package mineplex.core.report.command;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilServer;
import mineplex.core.report.Report;
import mineplex.core.report.ReportManager;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
/**
* Handles receiving of report notifications.
*/
public class ReportNotificationCallback implements CommandCallback
{
private ReportManager _reportManager;
public ReportNotificationCallback(ReportManager reportManager)
{
_reportManager = reportManager;
}
@Override
public void run(ServerCommand command)
{
if (command instanceof ReportHandlerNotification)
{
ReportHandlerNotification reportNotification = (ReportHandlerNotification) command;
Report report = _reportManager.getReport(reportNotification.getReportId());
if (report != null)
{
UUID handlerUUID = report.getHandler();
if (handlerUUID != null)
{
Player handler = Bukkit.getPlayer(handlerUUID);
if (handler != null)
{
sendRawMessage(handler, reportNotification.getNotification());
}
}
}
}
else if (command instanceof ReportNotification)
{
ReportNotification reportNotification = (ReportNotification) command;
// Message all players that can receive report notifications.
for (Player player : UtilServer.getPlayers())
{
if (_reportManager.hasReportNotifications(player))
{
sendRawMessage(player, reportNotification.getNotification());
}
}
}
}
private void sendRawMessage(Player player, String rawMessage)
{
Server server = UtilServer.getServer();
server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + rawMessage);
}
}

View File

@ -0,0 +1,83 @@
package mineplex.core.report.task;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.report.Report;
import mineplex.core.report.ReportManager;
import mineplex.core.report.command.ReportHandlerNotification;
import org.apache.commons.lang3.StringUtils;
/**
* Displays a message containing up-to-date details of a report to it's handler.
*/
public class ReportHandlerMessageTask extends BukkitRunnable
{
private static final String DECORATION = C.cAqua + "------------------------------------";
private ReportManager _reportManager;
private Report _report;
public ReportHandlerMessageTask(ReportManager reportManager, Report report)
{
_reportManager = reportManager;
_report = report;
}
@Override
public void run()
{
int reportId = _report.getReportId();
if (_reportManager.isActiveReport(reportId))
{
String suspectName = Bukkit.getOfflinePlayer(_report.getSuspect()).getName();
JsonMessage jsonMessage = new JsonMessage(DECORATION)
.extra("\n")
.add(C.cAqua + "Reviewing Ticket " + C.cGold + "#" + reportId)
.add("\n\n")
.add(C.cPurple + StringUtils.join(getReportReasons(), "\n" + C.cPurple))
.add("\n\n")
.add(C.cAqua + "Suspect: " + C.cGold + suspectName)
.add("\n")
.add((_report.hasToken() ? C.cAqua + "Chat Log: " + C.cGold + "Click Here" + "\n" : ""))
.click(ClickEvent.OPEN_URL, SnapshotPublisher.getURL(_report.getToken()))
.add("\n")
.add(C.cAqua + "Type " + C.cGold + "/reportclose " + reportId + " <reason>" + C.cAqua + " to close this report.")
.click(ClickEvent.SUGGEST_COMMAND, "/reportclose " + reportId)
.add("\n")
.add(DECORATION);
new ReportHandlerNotification(_report, jsonMessage).publish();
}
else
{
// report has been closed, so this task should be cancelled
cancel();
}
}
public String[] getReportReasons()
{
Map<UUID, String> reportReasons = _report.getReportReasons();
String[] output = new String[reportReasons.size()];
int count = 0;
for (Map.Entry<UUID, String> entry : reportReasons.entrySet())
{
String reporterName = Bukkit.getOfflinePlayer(entry.getKey()).getName();
// triple backslashes so this translates to valid JSON
output[count++] = "\\\"" + entry.getValue() + "\\\" - " + reporterName;
}
return output;
}
}

View File

@ -0,0 +1,87 @@
package mineplex.core.report.task;
import java.util.ArrayList;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.report.Report;
import mineplex.core.report.ReportManager;
/**
* Checks reports "owned" by this instance for inactivity, purges inactive reports.
*/
public class ReportPurgeTask extends BukkitRunnable
{
private ReportManager _reportManager;
public ReportPurgeTask(ReportManager reportManager)
{
_reportManager = reportManager;
}
@Override
public void run()
{
for (int reportId : new ArrayList<>(_reportManager.getActiveReports())) // create copy as this will be run async
{
Report report = _reportManager.getReport(reportId);
if (report != null)
{
if (checkForPurge(report))
{
notifyHandler(report);
}
}
else
{
// report has been leftover for some reason
purgeReport(reportId);
}
}
}
/**
* Checks if a report should be purged and carries it out if so.
*
* @param report the report to check for purging (and act accordingly)
* @return true if the report was purged, false otherwise
*/
public boolean checkForPurge(Report report)
{
if (!report.isActive())
{
int reportId = report.getReportId();
purgeReport(reportId);
return true;
}
return false;
}
/**
* Purges a report.
*
* @param reportId the report id to purge
*/
public void purgeReport(int reportId)
{
_reportManager.removeReport(reportId);
_reportManager.removeActiveReport(reportId);
}
/**
* Notifies the handler of a report (if any) that the report was purged.
*
* @param report the report which was purged
*/
public void notifyHandler(Report report)
{
// would result in spam if many reports with no handlers are purged (causing each member of staff to receive a message for every purged report)
if (report.getHandler() != null)
{
_reportManager.sendHandlerNotification(report, ReportManager.getReportPrefix(report) + C.cRed + "Purging report due to inactivity.");
}
}
}

View File

@ -0,0 +1,34 @@
package mineplex.core.report.ui;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.gui.SimpleGuiItem;
import mineplex.core.report.ReportCategory;
/**
* Represents a clickable button in a {@link ReportCategoryPage} which determines the type of infraction a player has committed.
*/
public class ReportCategoryButton extends SimpleGuiItem
{
private ReportCategoryPage _reportCategoryPage;
private ReportCategory _category;
public ReportCategoryButton(ReportCategoryPage reportCategoryPage, ReportCategory category) {
super(category.getItemMaterial(), 1, (short) 0);
ItemMeta itemMeta = getItemMeta();
itemMeta.setDisplayName(category.getTitle());
itemMeta.setLore(category.getDescription());
setItemMeta(itemMeta);
this._reportCategoryPage = reportCategoryPage;
this._category = category;
}
@Override
public void click(ClickType clickType)
{
_reportCategoryPage.addReport(_category);
}
}

View File

@ -0,0 +1,67 @@
package mineplex.core.report.ui;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import mineplex.core.common.util.C;
import mineplex.core.gui.SimpleGui;
import mineplex.core.report.ReportCategory;
import mineplex.core.report.Report;
import mineplex.core.report.ReportPlugin;
/**
* User interface shown to a player when reporting another player.
*/
public class ReportCategoryPage extends SimpleGui
{
private static final Map<Integer, ReportCategory> CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap<Integer, ReportCategory>()
{{
int rowStartSlot = 9 * 2; // end of row 2
put(rowStartSlot + 3, ReportCategory.HACKING);
put(rowStartSlot + 5, ReportCategory.CHAT_ABUSE);
}});
private ReportPlugin _reportPlugin;
private Player _reportee;
private Player _offender;
private String _reason;
public ReportCategoryPage(ReportPlugin reportPlugin, Player reportee, Player offender, String reason)
{
super(reportPlugin.getPlugin(), reportee, "Report " + offender.getName(), 9 * 5);
this._reportPlugin = reportPlugin;
this._reportee = reportee;
this._offender = offender;
this._reason = reason;
buildPage();
}
private void buildPage()
{
for (Map.Entry<Integer, ReportCategory> entry : CATEGORY_SLOTS.entrySet())
{
ReportCategory category = entry.getValue();
setItem(entry.getKey(), new ReportCategoryButton(this, category));
}
}
public void addReport(ReportCategory category)
{
Report report = _reportPlugin.getReportManager().reportPlayer(_reportee, _offender, category, _reason);
_reportee.closeInventory();
unregisterListener();
_reportee.sendMessage(C.cGreen + "Report sent successfully (" + C.cGold + "#" + report.getReportId() + C.cGreen + ").");
}
public void unregisterListener()
{
HandlerList.unregisterAll(this);
}
}

View File

@ -0,0 +1,48 @@
package mineplex.core.report.ui;
import java.util.List;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.gui.SimpleGuiItem;
import mineplex.core.report.ReportResult;
/**
* Represents a button which can be clicked to determine the result of a report.
*/
public class ReportResultButton extends SimpleGuiItem
{
private ReportResultPage _reportResultPage;
private ReportResult _result;
public ReportResultButton(ReportResultPage reportResultPage, ReportResult result, ItemStack displayItem)
{
super(displayItem);
_reportResultPage = reportResultPage;
_result = result;
}
@Override
public void setup()
{
// replace all occurrences of "%suspect%" in the lore with the actual name
ItemMeta itemMeta = getItemMeta();
List<String> lore = itemMeta.getLore();
for (int i = 0; i < lore.size(); i++)
{
lore.set(i, lore.get(i).replace("%suspect%", _reportResultPage.getPlayer().getName()));
}
itemMeta.setLore(lore);
setItemMeta(itemMeta);
}
@Override
public void click(ClickType clickType)
{
_reportResultPage.setResult(_result);
}
}

View File

@ -0,0 +1,73 @@
package mineplex.core.report.ui;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.gui.SimpleGui;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.report.ReportResult;
/**
* User interface shown to a moderator when closing a report to determine the result of the report.
*/
public class ReportResultPage extends SimpleGui
{
private static final ItemStack ITEM_ACCEPT = new ItemBuilder(Material.WOOL)
.setData(DyeColor.GREEN.getData())
.setTitle(C.cGreen + "Accept Report")
.addLore("%suspect% is cheating without a doubt.")
.build();
private static final ItemStack ITEM_DENY = new ItemBuilder(Material.WOOL)
.setData(DyeColor.YELLOW.getData())
.setTitle(C.cYellow + "Deny Report")
.addLore("There is not enough evidence against %suspect%.")
.build();
private static final ItemStack ITEM_ABUSE = new ItemBuilder(Material.WOOL)
.setData(DyeColor.RED.getData())
.setTitle(C.cRed + "Flag Abuse")
.addLore("The reporter(s) were abusing the report system.")
.build();
private ReportManager _reportManager;
private int _reportId;
private Player _reportCloser;
private String _reason;
public ReportResultPage(ReportPlugin reportPlugin, int reportId, Player reportCloser, String reason)
{
super(reportPlugin.getPlugin(), reportCloser, "Report Result", 9 * 3);
_reportManager = reportPlugin.getReportManager();
_reportId = reportId;
_reportCloser = reportCloser;
_reason = reason;
buildPage();
}
private void buildPage()
{
setItem(11, new ReportResultButton(this, ReportResult.ACCEPTED, ITEM_ACCEPT));
setItem(13, new ReportResultButton(this, ReportResult.DENIED, ITEM_DENY));
setItem(15, new ReportResultButton(this, ReportResult.ABUSIVE, ITEM_ABUSE));
}
public void setResult(ReportResult result)
{
_reportCloser.closeInventory();
unregisterListener();
_reportManager.closeReport(_reportId, _reportCloser, _reason, result);
}
public void unregisterListener()
{
HandlerList.unregisterAll(this);
}
}

View File

@ -33,6 +33,8 @@ public class PlayerScoreboard
protected void addTeams(Player player) protected void addTeams(Player player)
{ {
_scoreboard.registerNewTeam("Vanished").setSuffix(C.cBlue + "*");
for (Rank rank : Rank.values()) for (Rank rank : Rank.values())
{ {
if (rank != Rank.ALL) if (rank != Rank.ALL)
@ -69,6 +71,16 @@ public class PlayerScoreboard
//Add Self to Other //Add Self to Other
otherPlayer.getScoreboard().getTeam(rankName).addPlayer(player); otherPlayer.getScoreboard().getTeam(rankName).addPlayer(player);
if (_manager.getIncognitoManager().Get(otherPlayer).Hidden)
{
_scoreboard.getTeam("Vanished").addPlayer(otherPlayer);
}
if (_manager.getIncognitoManager().Get(player).Hidden)
{
_scoreboard.getTeam("Vanished").addPlayer(player);
}
} }
} }

View File

@ -13,6 +13,7 @@ import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
@ -20,6 +21,7 @@ public class ScoreboardManager extends MiniPlugin
{ {
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
private DonationManager _donationManager; private DonationManager _donationManager;
private IncognitoManager _incognito;
//This stores current scoreboard for the player //This stores current scoreboard for the player
private HashMap<Player, PlayerScoreboard> _playerScoreboards = new HashMap<Player, PlayerScoreboard>(); private HashMap<Player, PlayerScoreboard> _playerScoreboards = new HashMap<Player, PlayerScoreboard>();
@ -32,12 +34,13 @@ public class ScoreboardManager extends MiniPlugin
private int _shineIndex; private int _shineIndex;
private boolean _shineDirection = true; private boolean _shineDirection = true;
public ScoreboardManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) public ScoreboardManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, IncognitoManager incognito)
{ {
super("Scoreboard Manager", plugin); super("Scoreboard Manager", plugin);
_clientManager = clientManager; _clientManager = clientManager;
_donationManager = donationManager; _donationManager = donationManager;
_incognito = incognito;
} }
public CoreClientManager getClients() public CoreClientManager getClients()
@ -169,4 +172,9 @@ public class ScoreboardManager extends MiniPlugin
_shineDirection = !_shineDirection; _shineDirection = !_shineDirection;
} }
} }
public IncognitoManager getIncognitoManager()
{
return _incognito;
}
} }

View File

@ -3,6 +3,8 @@ package mineplex.core.sponsorbranding;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.List; import java.util.List;
import mineplex.core.common.util.UtilMath;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -178,8 +180,31 @@ public class BrandingPost
if (set.getBlock().getType() == Material.STAINED_CLAY) if (set.getBlock().getType() == Material.STAINED_CLAY)
continue; continue;
set.getBlock().setType(Material.WOOD); if (UtilMath.offset2d(corner3.getBlock().getLocation(), set.getBlock().getLocation()) == 0 || UtilMath.offset2d(corner4.getBlock().getLocation(), set.getBlock().getLocation()) == 0)
set.getBlock().setData((byte)1); {
if (corner3.getBlockY() != set.getBlockY() && corner4.getBlockY() != set.getBlockY())
{
Material type = Material.COBBLE_WALL;
if (_center.getBlockY() == set.getBlockY())
{
type = Material.FENCE;
}
set.getBlock().setType(type);
continue;
}
}
Material type = Material.STEP;
byte data = (byte)5;
if (set.getBlockY() == corner4.getBlockY())
{
type = Material.SMOOTH_BRICK;
data = (byte)0;
}
set.getBlock().setType(type);
set.getBlock().setData(data);
} }
} }
} }

View File

@ -13,7 +13,9 @@ import mineplex.core.inventory.InventoryManager;
import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.IButton;
import mineplex.core.shop.page.ConfirmationPage; import mineplex.core.shop.page.ConfirmationPage;
import mineplex.core.treasure.ChestPackage; import mineplex.core.treasure.ChestPackage;
import mineplex.core.treasure.TreasureManager; import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
public class BuyChestButton implements IButton public class BuyChestButton implements IButton
{ {
@ -50,14 +52,10 @@ public class BuyChestButton implements IButton
UtilPlayer.message(player, F.main("Disguise", "You cant buy things while you are disguised!")); UtilPlayer.message(player, F.main("Disguise", "You cant buy things while you are disguised!"));
return; return;
} }
_page.getShop().openPageForPlayer(player, new ConfirmationPage<TreasureManager, TreasureShop>( _page.getShop().openPageForPlayer(player, new ConfirmationPage<>(
_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), new Runnable() _page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), () -> {
{ _inventoryManager.addItemToInventory(player, _chestName, 1);
public void run() _page.refresh();
{ }, _page, new ChestPackage(_chestName, _chestMat, _chestCost), CurrencyType.Coins, player));
_inventoryManager.addItemToInventory(player, _chestName, 1);
_page.refresh();
}
}, _page, new ChestPackage(_chestName, _chestMat, _chestCost), CurrencyType.Coins, player));
} }
} }

View File

@ -1,5 +1,10 @@
package mineplex.game.clans; package mineplex.game.clans;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.CustomTagFix; import mineplex.core.CustomTagFix;
import mineplex.core.FoodDupeFix; import mineplex.core.FoodDupeFix;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
@ -7,6 +12,9 @@ import mineplex.core.achievement.AchievementManager;
import mineplex.core.antihack.AntiHack; import mineplex.core.antihack.AntiHack;
import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.SnapshotPlugin;
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
import mineplex.core.command.CommandCenter; import mineplex.core.command.CommandCenter;
import mineplex.core.common.MinecraftVersion; import mineplex.core.common.MinecraftVersion;
import mineplex.core.common.Pair; import mineplex.core.common.Pair;
@ -31,6 +39,8 @@ import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager; import mineplex.core.preferences.PreferencesManager;
import mineplex.core.punish.Punish; import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.resourcepack.ResourcePackManager; import mineplex.core.resourcepack.ResourcePackManager;
import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.spawn.Spawn; import mineplex.core.spawn.Spawn;
@ -51,11 +61,6 @@ import mineplex.game.clans.spawn.travel.TravelShop;
import mineplex.game.clans.world.WorldManager; import mineplex.game.clans.world.WorldManager;
import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.MinecraftServer;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.plugin.java.JavaPlugin;
public class Clans extends JavaPlugin public class Clans extends JavaPlugin
{ {
public static final String VERSION = "Beta 1.0"; public static final String VERSION = "Beta 1.0";
@ -65,7 +70,7 @@ public class Clans extends JavaPlugin
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
private DonationManager _donationManager; private DonationManager _donationManager;
private ClansManager _clansManager; private ClansManager _clansManager;
@Override @Override
public void onEnable() public void onEnable()
{ {
@ -84,27 +89,27 @@ public class Clans extends JavaPlugin
CommandCenter.Instance.setClientManager(_clientManager); CommandCenter.Instance.setClientManager(_clientManager);
ItemStackFactory.Initialize(this, false); ItemStackFactory.Initialize(this, false);
DelayedTask.Initialize(this); DelayedTask.Initialize(this);
Recharge.Initialize(this); Recharge.Initialize(this);
VisibilityManager.Initialize(this); VisibilityManager.Initialize(this);
// new ProfileCacheManager(this); // new ProfileCacheManager(this);
_donationManager = new DonationManager(this, _clientManager, webServerAddress); _donationManager = new DonationManager(this, _clientManager, webServerAddress);
new FallingBlocks(this); new FallingBlocks(this);
new ServerConfiguration(this, _clientManager); new ServerConfiguration(this, _clientManager);
PacketHandler packetHandler = new PacketHandler(this); PacketHandler packetHandler = new PacketHandler(this);
IncognitoManager incognito = new IncognitoManager(this, _clientManager, packetHandler); IncognitoManager incognito = new IncognitoManager(this, _clientManager, packetHandler);
PreferencesManager preferenceManager = new PreferencesManager(this, incognito, _clientManager, _donationManager); PreferencesManager preferenceManager = new PreferencesManager(this, incognito, _clientManager, _donationManager);
incognito.setPreferencesManager(preferenceManager); incognito.setPreferencesManager(preferenceManager);
ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager)); ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager));
// TODO: Add spawn locations to a configuration file of some sort? // TODO: Add spawn locations to a configuration file of some sort?
new Spawn(this, serverStatusManager.getCurrentServerName()); new Spawn(this, serverStatusManager.getCurrentServerName());
Give.Initialize(this); Give.Initialize(this);
@ -122,10 +127,10 @@ public class Clans extends JavaPlugin
BlockRestore blockRestore = new BlockRestore(this); BlockRestore blockRestore = new BlockRestore(this);
IgnoreManager ignoreManager = new IgnoreManager(this, _clientManager, preferenceManager, portal); IgnoreManager ignoreManager = new IgnoreManager(this, _clientManager, preferenceManager, portal);
StatsManager statsManager = new StatsManager(this, _clientManager); StatsManager statsManager = new StatsManager(this, _clientManager);
EloManager eloManager = new EloManager(this, _clientManager); EloManager eloManager = new EloManager(this, _clientManager);
AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, _donationManager, eloManager); AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, _donationManager, incognito, eloManager);
Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName());
new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, _clientManager, preferenceManager, portal), chat); new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, _clientManager, preferenceManager, portal), chat);
@ -134,12 +139,16 @@ public class Clans extends JavaPlugin
new Explosion(this, blockRestore); new Explosion(this, blockRestore);
new InventoryManager(this, _clientManager); new InventoryManager(this, _clientManager);
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://file.mineplex.com/ResClans.zip"), Pair.create(MinecraftVersion.Version1_8, "http://file.mineplex.com/ResClans.zip"),
Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResClans19.zip") Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResClans19.zip")
}, true); }, true);
//SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this));
//new SnapshotPlugin(this, snapshotManager);
//new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, snapshotManager, CommandCenter.Instance.GetClientManager(), serverStatusManager.getCurrentServerName()));
// Enable custom-gear related managers // Enable custom-gear related managers
new CustomTagFix(this, packetHandler); new CustomTagFix(this, packetHandler);
GearManager customGear = new GearManager(this, packetHandler, _clientManager, _donationManager); GearManager customGear = new GearManager(this, packetHandler, _clientManager, _donationManager);
@ -154,7 +163,7 @@ public class Clans extends JavaPlugin
new TravelShop(_clansManager, _clientManager, _donationManager); new TravelShop(_clansManager, _clientManager, _donationManager);
new MiningShop(_clansManager, _clientManager, _donationManager); new MiningShop(_clansManager, _clientManager, _donationManager);
new WorldManager(this); new WorldManager(this);
// Disable spigot item merging // Disable spigot item merging
for (World world : getServer().getWorlds()) for (World world : getServer().getWorlds())
{ {
@ -172,13 +181,13 @@ public class Clans extends JavaPlugin
{ {
String name = ""; String name = "";
String[] words = material.toString().split("_"); String[] words = material.toString().split("_");
for (String word : words) for (String word : words)
{ {
word = word.toLowerCase(); word = word.toLowerCase();
name += word.substring(0, 1).toUpperCase() + word.substring(1) + " "; name += word.substring(0, 1).toUpperCase() + word.substring(1) + " ";
} }
return name; return name;
} }
@ -188,7 +197,7 @@ public class Clans extends JavaPlugin
// Need to notify WorldEventManager of server shutdown, this seemed like // Need to notify WorldEventManager of server shutdown, this seemed like
// the only decent way to do it // the only decent way to do it
_clansManager.onDisable(); _clansManager.onDisable();
getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); getServer().getPluginManager().callEvent(new ServerShutdownEvent(this));
} }

View File

@ -1,42 +1,7 @@
package mineplex.game.clans.clans; package mineplex.game.clans.clans;
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 org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Horse;
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.SignChangeEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
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.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
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 com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import mineplex.core.MiniClientPlugin; import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager; import mineplex.core.achievement.AchievementManager;
@ -45,13 +10,7 @@ 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.events.PlayerMessageEvent;
import mineplex.core.common.util.C; import mineplex.core.common.util.*;
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.Creature;
import mineplex.core.creature.event.CreatureSpawnCustomEvent; import mineplex.core.creature.event.CreatureSpawnCustomEvent;
import mineplex.core.disguise.DisguiseManager; import mineplex.core.disguise.DisguiseManager;
@ -81,14 +40,7 @@ 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.ban.ClansBanManager;
import mineplex.game.clans.clans.commands.ClanManagementCommand; import mineplex.game.clans.clans.commands.*;
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.QueryCommand;
import mineplex.game.clans.clans.commands.RegionsCommand;
import mineplex.game.clans.clans.data.PlayerClan; import mineplex.game.clans.clans.data.PlayerClan;
import mineplex.game.clans.clans.event.ClansPlayerDeathEvent; import mineplex.game.clans.clans.event.ClansPlayerDeathEvent;
import mineplex.game.clans.clans.gui.ClanShop; import mineplex.game.clans.clans.gui.ClanShop;
@ -140,6 +92,28 @@ import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire; import mineplex.minecraft.game.core.fire.Fire;
import mineplex.minecraft.game.core.mechanics.Weapon; import mineplex.minecraft.game.core.mechanics.Weapon;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Horse;
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.SignChangeEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
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.vehicle.VehicleEnterEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.*;
public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelation public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelation
{ {
@ -328,6 +302,14 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
skillManager.RemoveSkill("Dwarf Toss", "Block Toss"); skillManager.RemoveSkill("Dwarf Toss", "Block Toss");
skillManager.removeSkill("Whirlwind Axe"); skillManager.removeSkill("Whirlwind Axe");
skillManager.removeSkill("Shield Smash"); skillManager.removeSkill("Shield Smash");
// Check if any Ice Prison blocks will be placed inside a safe zone
// fixme Is there any way of checking the destination beforehand?
// Although if the user is trying to launch an Ice Prison into a safezone they should know better
skillManager.GetSkill("Ice Prison").setLocationFilter(location ->
{
ClanTerritory territory = _clanUtility.getClaim(location);
return territory == null || !territory.Safe;
});
_worldEvent.setFactory(skillManager); _worldEvent.setFactory(skillManager);
_classManager = new ClassManager(plugin, _clientManager, donationManager, skillManager, itemFactory, webServerAddress); _classManager = new ClassManager(plugin, _clientManager, donationManager, skillManager, itemFactory, webServerAddress);
@ -337,7 +319,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
ServerCommandManager.getInstance().registerCommandType(ClanLoadCommand.class, new ClanLoadCommandHandler()); ServerCommandManager.getInstance().registerCommandType(ClanLoadCommand.class, new ClanLoadCommandHandler());
EloManager eloManager = new EloManager(plugin, _clientManager); EloManager eloManager = new EloManager(plugin, _clientManager);
AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, donationManager, eloManager); AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, donationManager, incognitoManager, eloManager);
ClassShopManager shopManager = new ClassShopManager(plugin, _classManager, skillManager, itemFactory, achievementManager, _clientManager); ClassShopManager shopManager = new ClassShopManager(plugin, _classManager, skillManager, itemFactory, achievementManager, _clientManager);
_classShop = new ClassCombatShop(shopManager, _clientManager, donationManager, true, "Class Shop"); _classShop = new ClassCombatShop(shopManager, _clientManager, donationManager, true, "Class Shop");
@ -599,39 +581,27 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
UtilServer.broadcast(F.sys("Join", event.getPlayer().getName())); UtilServer.broadcast(F.sys("Join", event.getPlayer().getName()));
} }
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void Join(PlayerJoinEvent event) public void Join(PlayerJoinEvent event)
{ {
event.setJoinMessage(null); event.setJoinMessage(null);
if (_clansBans.willBeKicked(event.getPlayer()))
{
return;
}
if (_incognitoManager.Get(event.getPlayer()).Status) if (_incognitoManager.Get(event.getPlayer()).Status)
{ {
return; return;
} }
_clansBans.runAfterLoad(event.getPlayer().getName(), () -> { for (Player other : UtilServer.getPlayers())
if (_clansBans.Get(event.getPlayer().getName()).isBanned()) {
{ if (_tutorial.inTutorial(other))
return; {
} // Don't display join message if player in tutorial.
continue;
for (Player other : UtilServer.getPlayers()) }
{
if (_tutorial.inTutorial(other)) other.sendMessage(F.sys("Join", event.getPlayer().getName()));
{ }
// Don't display join message if player in tutorial.
continue;
}
other.sendMessage(F.sys("Join", event.getPlayer().getName()));
}
});
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
@ -644,11 +614,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return; return;
} }
if (_clansBans.Get(event.getPlayer().getName()) != null && _clansBans.Get(event.getPlayer().getName()).isBanned())
{
return;
}
for (Player other : UtilServer.getPlayers()) for (Player other : UtilServer.getPlayers())
{ {
if (_tutorial.inTutorial(other)) if (_tutorial.inTutorial(other))
@ -661,42 +626,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
} }
} }
@EventHandler(priority = EventPriority.HIGHEST)
public void Kick(PlayerKickEvent event)
{
if (_incognitoManager.Get(event.getPlayer()).Status)
{
event.setLeaveMessage(null);
return;
}
if (_clansBans.willBeKicked(event.getPlayer()))
{
return;
}
if (event.getReason().contains("banned from Clans"))
{
return;
}
if (event.getLeaveMessage() != null)
{
event.setLeaveMessage(null);
for (Player other : UtilServer.getPlayers())
{
if (_tutorial.inTutorial(other))
{
// Don't display leave message if player in tutorial.
continue;
}
other.sendMessage(F.sys("Leave", event.getPlayer().getName()));
}
}
}
@EventHandler @EventHandler
public void disableEnderpeal(PlayerInteractEvent event) public void disableEnderpeal(PlayerInteractEvent event)
{ {
@ -891,7 +820,17 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
recipients.clear(); recipients.clear();
} }
@EventHandler
public void disableObsidian(BlockBreakEvent event)
{
if(event.getBlock().getType().equals(Material.OBSIDIAN))
{
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
}
}
@EventHandler @EventHandler
public void onSignChange(SignChangeEvent event) public void onSignChange(SignChangeEvent event)
{ {

View File

@ -1,6 +1,8 @@
package mineplex.game.clans.clans.ban; package mineplex.game.clans.clans.ban;
import java.util.List;
import java.util.Set; import java.util.Set;
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;
@ -10,20 +12,18 @@ import mineplex.core.common.util.UtilTime;
*/ */
public class ClansBanClient public class ClansBanClient
{ {
public String Name; public final UUID _uuid;
public String UUID; public final List<ClansBan> _bans;
public Set<ClansBan> Bans;
public ClansBanClient(String name, String uuid, Set<ClansBan> bans) public ClansBanClient(UUID uuid, List<ClansBan> bans)
{ {
Name = name; _uuid = uuid;
UUID = uuid; _bans = bans;
Bans = bans;
} }
public boolean isBanned() public boolean isBanned()
{ {
for (ClansBan ban : Bans) for (ClansBan ban : _bans)
{ {
if (ban.isActive()) if (ban.isActive())
{ {
@ -38,7 +38,7 @@ public class ClansBanClient
{ {
long time = 0; long time = 0;
for (ClansBan ban : Bans) for (ClansBan ban : _bans)
{ {
if (!ban.isActive()) if (!ban.isActive())
{ {
@ -67,7 +67,7 @@ public class ClansBanClient
{ {
ClansBan longest = null; ClansBan longest = null;
for (ClansBan ban : Bans) for (ClansBan ban : _bans)
{ {
if (!ban.isActive()) if (!ban.isActive())
{ {

View File

@ -1,52 +1,24 @@
package mineplex.game.clans.clans.ban; package mineplex.game.clans.clans.ban;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor;
import mineplex.core.common.DefaultHashMap;
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.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;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ban.commands.ClansBanCommand; import mineplex.game.clans.clans.ban.commands.ClansBanCommand;
import mineplex.game.clans.clans.ban.ui.ClansBanShop; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class ClansBanManager extends MiniPlugin implements ILoginProcessor public class ClansBanManager extends MiniPlugin
{ {
private CoreClientManager _clientManager; private final CoreClientManager _clientManager;
private ClansBanRepository _repository; private final DonationManager _donationManager;
private Map<String, ClansBanClient> _clients; private final ClansBanRepository _repository;
private Map<String, ClansBanCache> _cache;
private DefaultHashMap<String, List<Runnable>> _runAfterLoad;
private ClansBanShop _shop;
private Map<String, String> _toKick = new HashMap<>();
private Object _lock = new Object();
public ClansBanManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) public ClansBanManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
{ {
super("Blacklist", plugin); super("Blacklist", plugin);
@ -54,13 +26,8 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
_clientManager = clientManager; _clientManager = clientManager;
_repository = new ClansBanRepository(plugin); _repository = new ClansBanRepository(plugin);
_clients = new HashMap<>(); _donationManager = donationManager;
_cache = new HashMap<>();
_runAfterLoad = new DefaultHashMap<>(name -> new ArrayList<>());
_shop = new ClansBanShop(this, clientManager, donationManager);
clientManager.addStoredProcedureLoginProcessor(this);
} }
@Override @Override
@ -68,202 +35,56 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
{ {
addCommand(new ClansBanCommand(this)); addCommand(new ClansBanCommand(this));
} }
@EventHandler
public void clearOldClients(UpdateEvent event)
{
if (event.getType().equals(UpdateType.SEC))
{
_toKick.forEach((name, reason) -> {
Player player = UtilPlayer.searchExact(name);
if (player == null)
{
return;
}
player.kickPlayer(reason);
runSyncLater(() -> {
_toKick.remove(name);
}, 20l);
});
}
if (event.getType().equals(UpdateType.MIN_01))
{
synchronized (_lock)
{
UtilStreams.ToList(_clients.keySet().stream().filter(UtilServer::IsOnline)).forEach(this::UnloadClient);
}
}
}
public void ban(ClansBanClient client, String admin, long time, String reason, Callback<ClansBanClient> callback)
{
runAsync(() -> {
_repository.ban(UUID.fromString(client.UUID), admin, time, reason, time == -1, ban -> {
client.Bans.add(ban);
callback.run(client);
});
});
}
public CoreClientManager getClientManager() public CoreClientManager getClientManager()
{ {
return _clientManager; return _clientManager;
} }
public ClansBanRepository GetRepository() public DonationManager getDonationManager()
{
return _donationManager;
}
public ClansBanRepository getRepository()
{ {
return _repository; return _repository;
} }
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerQuit(PlayerQuitEvent event)
{
if (Get(event.getPlayer().getName()) == null)
{
return;
}
if (Get(event.getPlayer().getName()).isBanned())
{
event.setQuitMessage(null);
}
UnloadClient(Get(event.getPlayer().getName()));
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerKicked(PlayerKickEvent event)
{
if (Get(event.getPlayer().getName()) == null)
{
return;
}
if (Get(event.getPlayer().getName()).isBanned())
{
event.setLeaveMessage(null);
}
UnloadClient(Get(event.getPlayer().getName()));
}
public void UnloadClient(ClansBanClient client) @EventHandler(priority = EventPriority.HIGHEST)
public void onLogin(AsyncPlayerPreLoginEvent event)
{ {
UnloadClient(client.Name); try
}
public void UnloadClient(String name)
{
synchronized (_lock)
{ {
_clients.remove(name); ClansBanClient client = _repository.loadClient(event.getUniqueId()).get();
}
}
public void LoadClient(String name, Callback<ClansBanClient> callback)
{
if (_clients.containsKey(name))
{
System.out.println("Clans Bans> Soft Warning: Loading client even though client is already loaded.");
_clients.remove(name);
}
GetRepository().loadClient(name, client -> {
synchronized (_lock)
{
_clients.put(name.toLowerCase(), client);
System.out.println("> CLIENTS: " + _clients);
if (callback != null)
{
callback.run(client);
}
}
});
}
public ClansBanClient Get(String name)
{
synchronized (_lock)
{
return _clients.get(name.toLowerCase());
}
}
public ClansBanShop getShop()
{
return _shop;
}
public void cache(Player player, String victim, String reason)
{
_cache.put(player.getName(), new ClansBanCache(victim, reason));
}
public ClansBanCache getCachedData(Player player)
{
return _cache.get(player.getName());
}
public void clearCachedName(String name)
{
_cache.remove(name);
}
public void unban(ClansBanClient target, ClansBan ban, Callback<ClansBanClient> callback)
{
if (!target.UUID.equals(ban.getUUID().toString()))
{
return;
}
ban.remove();
_repository.removeBan(ban);
callback.run(target);
}
public boolean willBeKicked(Player player)
{
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
{
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); event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, reason);
} }
}); } catch (Exception ignored) {}
} }
public String getQuery(int accountId, String uuid, String name) public void unban(ClansBanClient target, ClansBan ban, Callback<ClansBanClient> callback)
{ {
return "SELECT * FROM clanBans WHERE uuid = '" + uuid + "';"; if (!target._uuid.equals(ban.getUUID()))
} {
return;
}
public void runAfterLoad(String playerName, Runnable run) ban.remove();
{ _repository.removeBan(ban);
_runAfterLoad.get(playerName).add(run);
callback.run(target);
} }
} }

View File

@ -1,21 +1,17 @@
package mineplex.game.clans.clans.ban; package mineplex.game.clans.clans.ban;
import java.sql.Timestamp;
import java.util.Set;
import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Sets;
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;
import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.column.ColumnBoolean;
import mineplex.serverdata.database.column.ColumnInt; import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnTimestamp; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.serverdata.database.column.ColumnVarChar;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class ClansBanRepository extends MinecraftRepository public class ClansBanRepository extends MinecraftRepository
{ {
@ -27,71 +23,107 @@ public class ClansBanRepository extends MinecraftRepository
{ {
super(plugin, DBPool.getAccount()); super(plugin, DBPool.getAccount());
} }
public void ban(UUID uuid, String admin, long time, String reason, boolean permanent, Callback<ClansBan> callback)
{
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("admin", 16, admin),
new ColumnVarChar("reason", 128, reason),
new ColumnTimestamp("banTime", banTime),
new ColumnTimestamp("unbanTime", unbanTime),
new ColumnBoolean("permanent", permanent),
new ColumnBoolean("removed", false)
);
}
public void loadClient(String name, final Callback<ClansBanClient> callback)
{
String uuid = UUIDFetcher.getUUIDOf(name).toString();
executeQuery(GET_ALL_BANS, resultSet -> {
final Set<ClansBan> bans = Sets.newConcurrentHashSet();
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);
bans.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed)); public CompletableFuture<Optional<ClansBan>> ban(UUID uuid, String admin, long time, String reason)
}
if (callback != null)
{
callback.run(new ClansBanClient(name, uuid, bans));
}
}, new ColumnVarChar("uuid", 36, uuid));
}
@Override
protected void initialize()
{ {
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
Timestamp banTime = new Timestamp(System.currentTimeMillis());
Timestamp unbanTime = new Timestamp(System.currentTimeMillis() + time);
PreparedStatement stmt = conn.prepareStatement(BAN_PLAYER, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, uuid.toString());
stmt.setString(2, admin);
stmt.setString(3, reason);
stmt.setTimestamp(4, banTime);
stmt.setTimestamp(5, unbanTime);
stmt.setBoolean(6, time == -1);
stmt.setBoolean(7, false);
stmt.executeUpdate();
ResultSet resultSet = stmt.getGeneratedKeys();
if (resultSet.next())
{
int id = resultSet.getInt(1);
return Optional.of(new ClansBan(id, uuid, admin, reason, banTime, unbanTime, time == -1, false));
} else
{
return Optional.empty();
}
} catch (Exception e) {
e.printStackTrace();
return Optional.empty();
}
});
}
public CompletableFuture<ClansBanClient> loadClient(UUID uuid) {
return CompletableFuture.supplyAsync(() ->
{
try (Connection conn = DBPool.getAccount().getConnection())
{
PreparedStatement stmt = conn.prepareStatement(GET_ALL_BANS);
stmt.setString(1, uuid.toString());
List<ClansBan> bans = new ArrayList<>();
ResultSet resultSet = stmt.executeQuery();
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);
bans.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed));
}
return new ClansBanClient(uuid, bans);
} catch (Exception e) {
e.printStackTrace();
return new ClansBanClient(uuid, new ArrayList<>());
}
});
}
/**
* @deprecated This invokes a mojang UUID query and should be replaced.
* It's called infrequently enough (i.e., only when a moderator
* invokes /cban), so not entirely pressing.
*/
@Deprecated
public CompletableFuture<Optional<ClansBanClient>> loadClient(String name)
{
// Yes, this is garbage.
// Yes, it would be better implemented in a functional language.
return CompletableFuture.supplyAsync(() -> UUIDFetcher.getUUIDOf(name))
.thenCompose(uuid ->
{
if (uuid == null)
{
CompletableFuture<Optional<ClansBanClient>> future = new CompletableFuture<>();
future.complete(Optional.empty());
return future;
} else {
return loadClient(uuid).thenApply(Optional::of);
}
});
} }
@Override @Override
protected void update() protected void initialize() {}
{
} @Override
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

@ -1,5 +1,6 @@
package mineplex.game.clans.clans.ban.commands; package mineplex.game.clans.clans.ban.commands;
import mineplex.game.clans.clans.ban.ui.ClansBanShop;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
@ -15,6 +16,7 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
super(plugin, Rank.CMOD, "cbans", "cb", "cban", "cp", "cpunish", "clanspunish", "clanpunish"); super(plugin, Rank.CMOD, "cbans", "cb", "cban", "cp", "cpunish", "clanspunish", "clanpunish");
} }
@SuppressWarnings("deprecation")
@Override @Override
public void Execute(final Player caller, String[] args) public void Execute(final Player caller, String[] args)
{ {
@ -34,11 +36,19 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
} }
final String finalReason = reason; final String finalReason = reason;
Plugin.LoadClient(playerName, client -> { Plugin.getRepository().loadClient(playerName)
Plugin.cache(caller, playerName, finalReason); .thenAccept(maybeClient ->
Plugin.getShop().attemptShopOpen(caller); Plugin.runSync(() ->
}); {
if (!maybeClient.isPresent())
{
UtilPlayer.message(caller, C.cRed + "Could not find player with name " + C.cYellow + " " + playerName);
} else
{
new ClansBanShop(Plugin, playerName, maybeClient.get(), finalReason).attemptShopOpen(caller);
}
}));
} }
else else
{ {

View File

@ -1,5 +1,14 @@
package mineplex.game.clans.clans.ban.ui; package mineplex.game.clans.clans.ban.ui;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ban.ClansBan;
import mineplex.game.clans.clans.ban.ClansBanClient;
import mineplex.game.clans.clans.ban.ClansBanManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -7,37 +16,25 @@ 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.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ban.ClansBan;
import mineplex.game.clans.clans.ban.ClansBanClient;
import mineplex.game.clans.clans.ban.ClansBanManager;
public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop> public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop>
{ {
private long _time; private long _time;
private boolean _permanent; private boolean _permanent;
private String _victimName;
private ClansBanClient _victimClient; private ClansBanClient _victimClient;
private String _victim;
private String _reason; 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 String name, final Player player, String victimName, ClansBanClient client, String reason)
{ {
super(banManager, shop, clientManager, donationManager, name, player); super(banManager, shop, banManager.getClientManager(), banManager.getDonationManager(), name, player);
_victim = getPlugin().getCachedData(player).getVictim(); _reason = reason;
_reason = getPlugin().getCachedData(player).getReason();
_victimName = victimName;
_victimClient = getPlugin().Get(_victim); _victimClient = client;
buildPage(); buildPage();
} }
@ -50,8 +47,8 @@ public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop>
// Middle of first row // Middle of first row
addButton(4, new ItemBuilder(Material.SKULL_ITEM) addButton(4, new ItemBuilder(Material.SKULL_ITEM)
.setData((short) 3) .setData((short) 3)
.setPlayerHead(_victim) .setPlayerHead(_victimName)
.setTitle(C.cDGreenB + _victim) .setTitle(C.cDGreenB + _victimName)
.addLore(" ") .addLore(" ")
.addLore(C.cYellow + _reason).build(), (player, click) -> {}); .addLore(C.cYellow + _reason).build(), (player, click) -> {});
@ -67,7 +64,7 @@ public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop>
.setTitle(C.cRedB + "Ban Player") .setTitle(C.cRedB + "Ban Player")
.setLore( .setLore(
" ", " ",
C.cGray + "Player: " + F.elem(_victim), C.cGray + "Player: " + F.elem(_victimName),
C.cGray + "Reason: " + F.elem(_reason), C.cGray + "Reason: " + F.elem(_reason),
C.cGray + "Time: " + F.elem(_permanent ? "Permanent" : UtilTime.MakeStr(_time)), C.cGray + "Time: " + F.elem(_permanent ? "Permanent" : UtilTime.MakeStr(_time)),
"", "",
@ -86,7 +83,7 @@ public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop>
} }
}); });
for (ClansBan ban : _victimClient.Bans) for (ClansBan ban : _victimClient._bans)
{ {
ItemStack item = new ItemBuilder(ban.isActive() ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK) 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")
@ -118,20 +115,24 @@ public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop>
private void performBan() private void performBan()
{ {
getPlugin().runAsync(() -> { getPlugin().getRepository().ban(_victimClient._uuid, getPlayer().getName(), _permanent ? -1 : _time, _reason)
getPlugin().ban(_victimClient, getPlayer().getName(), _permanent ? -1 : _time, _reason, client -> { .thenAccept(maybeBan -> getPlugin().runSync(() ->
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() + "."); if (maybeBan.isPresent())
} {
_victimClient._bans.add(maybeBan.get());
refresh();
}); String banTimeFormatted = _victimClient.getBanTimeFormatted();
}); UtilPlayer.message(getPlayer(), F.main("Clans", F.elem(_victimName) + " is now banned " + banTimeFormatted + "."));
Player target = Bukkit.getPlayer(_victimClient._uuid);
target.kickPlayer(C.cRedB + "You have been banned from Clans " + banTimeFormatted + ".");
refresh();
} else
{
F.main("Clans", C.cRed + "An issue occurred when trying to ban " + F.elem(_victimName));
}
}));
} }
private void addTimeAdjuster(int index, long time) private void addTimeAdjuster(int index, long time)

View File

@ -1,24 +1,30 @@
package mineplex.game.clans.clans.ban.ui; package mineplex.game.clans.clans.ban.ui;
import mineplex.game.clans.clans.ban.ClansBanClient;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase; import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ban.ClansBanManager; import mineplex.game.clans.clans.ban.ClansBanManager;
public class ClansBanShop extends ShopBase<ClansBanManager> public class ClansBanShop extends ShopBase<ClansBanManager>
{ {
public ClansBanShop(final ClansBanManager plugin, final CoreClientManager clientManager, final DonationManager donationManager) private final String _clientName;
private final ClansBanClient _client;
private final String _reason;
public ClansBanShop(final ClansBanManager plugin, String victimName, ClansBanClient client, String reason)
{ {
super(plugin, clientManager, donationManager, "Clans Punish"); super(plugin, plugin.getClientManager(), plugin.getDonationManager(), "Clans Punish");
_clientName = victimName;
_client = client;
_reason = reason;
} }
@Override @Override
protected ShopPageBase<ClansBanManager, ? extends ShopBase<ClansBanManager>> buildPagesFor(final Player player) protected ShopPageBase<ClansBanManager, ? extends ShopBase<ClansBanManager>> buildPagesFor(final Player player)
{ {
return new ClansBanPage(getPlugin(), this, getClientManager(), getDonationManager(), "Clans Punish", player); return new ClansBanPage(getPlugin(), this, "Clans Punish", player, _clientName, _client, _reason);
} }
} }

View File

@ -1,15 +1,14 @@
package mineplex.game.clans.clans.invsee.commands; package mineplex.game.clans.clans.invsee.commands;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.game.clans.clans.invsee.Invsee; import mineplex.game.clans.clans.invsee.Invsee;
import mineplex.game.clans.clans.invsee.ui.InvseeInventory; import mineplex.game.clans.clans.invsee.ui.InvseeInventory;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class InvseeCommand extends CommandBase<Invsee> public class InvseeCommand extends CommandBase<Invsee>
{ {
@ -18,31 +17,28 @@ public class InvseeCommand extends CommandBase<Invsee>
super(plugin, Rank.ADMIN, "invsee"); super(plugin, Rank.ADMIN, "invsee");
} }
@SuppressWarnings("deprecation")
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
{ {
if (args.length == 0) if (args.length == 0)
{ {
UtilPlayer.message(caller, F.help("/invsee <Player>", "View a player's inventory", Rank.ADMIN));
} }
else else
{ {
String name = args[0]; String name = args[0];
OfflinePlayer player; OfflinePlayer player = Bukkit.getServer().getPlayer(name);
if (UtilServer.IsOnline(name)) if (player == null)
{ {
player = UtilServer.GetPlayer(name); player = Bukkit.getServer().getOfflinePlayer(name);
}
else
{
player = UtilServer.GetOffline(name);
} }
if (player == null) if (player == null)
{ {
UtilPlayer.message(caller, F.main("Clans", "Specified player is neither online nor is offline. Perhaps they changed their name?")); UtilPlayer.message(caller, F.main("Clans", "Specified player is neither online nor offline. Perhaps they changed their name?"));
return; return;
} }

View File

@ -32,7 +32,7 @@ public class ClansScoreboardManager extends ScoreboardManager
public ClansScoreboardManager(JavaPlugin plugin, ClansManager clansManager, WarManager warManager, WorldEventManager worldEvent, TutorialManager tutorial, CoreClientManager clientManager, DonationManager donationManager) public ClansScoreboardManager(JavaPlugin plugin, ClansManager clansManager, WarManager warManager, WorldEventManager worldEvent, TutorialManager tutorial, CoreClientManager clientManager, DonationManager donationManager)
{ {
super(plugin, clientManager, donationManager); super(plugin, clientManager, donationManager, clansManager.getIncognitoManager());
_clansManager = clansManager; _clansManager = clansManager;
_warManager = warManager; _warManager = warManager;

View File

@ -164,7 +164,7 @@ public class MeridianScepter extends LegendaryItem
continue; continue;
} }
if (ClansManager.getInstance().getIncognitoManager().Get(closest).Status) if (ClansManager.getInstance().getIncognitoManager().Get(closest).Hidden)
{ {
continue; continue;
} }

View File

@ -8,6 +8,9 @@ import mineplex.core.antihack.AntiHack;
import mineplex.core.aprilfools.AprilFoolsManager; import mineplex.core.aprilfools.AprilFoolsManager;
import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.SnapshotPlugin;
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
import mineplex.core.command.CommandCenter; import mineplex.core.command.CommandCenter;
import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.common.events.ServerShutdownEvent;
import mineplex.core.creature.Creature; import mineplex.core.creature.Creature;
@ -40,6 +43,8 @@ import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.projectile.ProjectileManager; import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish; import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.resourcepack.ResourcePackManager; import mineplex.core.resourcepack.ResourcePackManager;
import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.sponsorbranding.BrandingManager; import mineplex.core.sponsorbranding.BrandingManager;
@ -135,16 +140,16 @@ public class Hub extends JavaPlugin implements IRelation
StatsManager statsManager = new StatsManager(this, clientManager); StatsManager statsManager = new StatsManager(this, clientManager);
EloManager eloManager = new EloManager(this, clientManager); EloManager eloManager = new EloManager(this, clientManager);
AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, eloManager); AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager);
PartyManager partyManager = new PartyManager(this, portal, clientManager, preferenceManager); PartyManager partyManager = new PartyManager(this, portal, clientManager, preferenceManager);
SkillConditionManager conditionManager = new SkillConditionManager(this); SkillConditionManager conditionManager = new SkillConditionManager(this);
CustomDataManager customDataManager = new CustomDataManager(this, clientManager); CustomDataManager customDataManager = new CustomDataManager(this, clientManager);
PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager); PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager);
HubManager hubManager = new HubManager(this, blockRestore, clientManager, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, customDataManager); HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, customDataManager);
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this, clientManager), partyManager); QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this, clientManager), partyManager);
@ -219,4 +224,4 @@ public class Hub extends JavaPlugin implements IRelation
{ {
return true; return true;
} }
} }

View File

@ -73,6 +73,7 @@ import mineplex.core.gadget.event.GadgetCollideEntityEvent;
import mineplex.core.gadget.event.GadgetEnableEvent; import mineplex.core.gadget.event.GadgetEnableEvent;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.hologram.HologramManager; import mineplex.core.hologram.HologramManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.incognito.events.IncognitoHidePlayerEvent; import mineplex.core.incognito.events.IncognitoHidePlayerEvent;
import mineplex.core.inventory.InventoryManager; import mineplex.core.inventory.InventoryManager;
import mineplex.core.message.PrivateMessageEvent; import mineplex.core.message.PrivateMessageEvent;
@ -163,6 +164,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
private PlayerCountManager _playerCountManager; private PlayerCountManager _playerCountManager;
private CustomDataManager _customDataManager; private CustomDataManager _customDataManager;
private Punish _punishManager; private Punish _punishManager;
private IncognitoManager _incognito;
private ValentinesManager _valentinesManager; private ValentinesManager _valentinesManager;
private BonusManager _bonusManager; private BonusManager _bonusManager;
// private HalloweenSpookinessManager _halloweenManager; // private HalloweenSpookinessManager _halloweenManager;
@ -187,10 +189,12 @@ public class HubManager extends MiniClientPlugin<HubClient>
// private final String[] _songNames = {"JingleBells.nbs", "TheFirstNoel.nbs", "Hark.nbs", "DeckTheHalls.nbs", "Joy.nbs", "MerryChristmas.nbs"}; // private final String[] _songNames = {"JingleBells.nbs", "TheFirstNoel.nbs", "Hark.nbs", "DeckTheHalls.nbs", "Joy.nbs", "MerryChristmas.nbs"};
private final ArrayList<NoteSong> _songs; private final ArrayList<NoteSong> _songs;
public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, CustomDataManager customDataManager) public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, IncognitoManager incognito, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, CustomDataManager customDataManager)
{ {
super("Hub Manager", plugin); super("Hub Manager", plugin);
_incognito = incognito;
_blockRestore = blockRestore; _blockRestore = blockRestore;
_clientManager = clientManager; _clientManager = clientManager;
_conditionManager = conditionManager; _conditionManager = conditionManager;
@ -452,8 +456,14 @@ public class HubManager extends MiniClientPlugin<HubClient>
{ {
// Give developers operator on their servers // Give developers operator on their servers
boolean testServer = _plugin.getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing"); boolean testServer = _plugin.getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
if (_clientManager.Get(event.getPlayer()).GetRank().has(Rank.OWNER) || (testServer && (_clientManager.Get(event.getPlayer()).GetRank().has(Rank.DEVELOPER) || _clientManager.Get(event.getPlayer()).GetRank() == Rank.JNR_DEV))) Rank minimum = Rank.OWNER;
if (testServer)
{
minimum = Rank.JNR_DEV;
}
if (_clientManager.Get(event.getPlayer()).GetRank().has(minimum))
event.getPlayer().setOp(true); event.getPlayer().setOp(true);
else else
event.getPlayer().setOp(false); event.getPlayer().setOp(false);
@ -462,7 +472,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
@EventHandler @EventHandler
public void PlayerRespawn(PlayerRespawnEvent event) public void PlayerRespawn(PlayerRespawnEvent event)
{ {
event.setRespawnLocation(GetSpawn().add(0, 10, 0)); event.setRespawnLocation(GetSpawn());
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
@ -486,7 +496,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
// } // }
//Teleport //Teleport
player.teleport(GetSpawn().add(0, 10, 0)); player.teleport(GetSpawn());
//Survival //Survival
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
@ -605,8 +615,6 @@ public class HubManager extends MiniClientPlugin<HubClient>
if(GetClients().Get(player).isDisguised()) if(GetClients().Get(player).isDisguised())
rank = GetClients().Get(player).getDisguisedRank(); rank = GetClients().Get(player).getDisguisedRank();
boolean ownsUltra = _donationManager.Get(player.getName()).OwnsUltraPackage();
//Level Prefix //Level Prefix
String levelStr = _achievementManager.getMineplexLevel(player, rank); String levelStr = _achievementManager.getMineplexLevel(player, rank);
@ -614,10 +622,6 @@ public class HubManager extends MiniClientPlugin<HubClient>
String rankStr = ""; String rankStr = "";
if (rank != Rank.ALL) if (rank != Rank.ALL)
rankStr = rank.getTag(true, true) + " "; rankStr = rank.getTag(true, true) + " ";
if (ownsUltra && !rank.has(Rank.ULTRA))
rankStr = Rank.ULTRA.getTag(true, true) + " ";
//Party Chat //Party Chat
if (event.getMessage().charAt(0) == '@') if (event.getMessage().charAt(0) == '@')
{ {
@ -1103,4 +1107,9 @@ public class HubManager extends MiniClientPlugin<HubClient>
} }
} }
} }
public IncognitoManager getIncognitoManager()
{
return _incognito;
}
} }

View File

@ -31,7 +31,7 @@ public class BillboardManager extends MiniPlugin
private void generateBoards() private void generateBoards()
{ {
_branding.createPost(new Location(Bukkit.getWorld("world"), -2, 77, -33), BlockFace.SOUTH, "logitech.jpg"); _branding.createPost(new Location(Bukkit.getWorld("world"), -6, 78, -35), BlockFace.SOUTH, "logitech.jpg");
} }
@EventHandler @EventHandler

View File

@ -21,7 +21,7 @@ public class HubScoreboardManager extends MiniPlugin
{ {
super("Hub Scoreboard Manager", manager.getPlugin()); super("Hub Scoreboard Manager", manager.getPlugin());
_scoreboardManager = new ScoreboardManager(manager.getPlugin(), clientManager, donationManager); _scoreboardManager = new ScoreboardManager(manager.getPlugin(), clientManager, donationManager, manager.getIncognitoManager());
init(); init();
} }

View File

@ -179,15 +179,15 @@ public class KothManager extends MiniPlugin
_active.add(player); _active.add(player);
if (color == null) if (color == null)
UtilPlayer.message(player, F.main("Parkour", "You have entered " + F.elem("KOTH Mode") + ".")); UtilPlayer.message(player, F.main("KOTH", "You have entered " + F.elem("KOTH Mode") + "."));
else if (color == Color.RED) else if (color == Color.RED)
UtilPlayer.message(player, F.main("Parkour", "You have joined " + F.elem(C.cRed + "Red KOTH Team") + ".")); UtilPlayer.message(player, F.main("KOTH", "You have joined " + F.elem(C.cRed + "Red KOTH Team") + "."));
else if (color == Color.AQUA) else if (color == Color.AQUA)
UtilPlayer.message(player, F.main("Parkour", "You have joined " + F.elem(C.cAqua + "Blue KOTH Team") + ".")); UtilPlayer.message(player, F.main("KOTH", "You have joined " + F.elem(C.cAqua + "Blue KOTH Team") + "."));
else if (color == Color.LIME) else if (color == Color.LIME)
UtilPlayer.message(player, F.main("Parkour", "You have joined " + F.elem(C.cGreen + "Green KOTH Team") + ".")); UtilPlayer.message(player, F.main("KOTH", "You have joined " + F.elem(C.cGreen + "Green KOTH Team") + "."));
else if (color == Color.YELLOW) else if (color == Color.YELLOW)
UtilPlayer.message(player, F.main("Parkour", "You have joined " + F.elem(C.cYellow + "Yellow KOTH Team") + ".")); UtilPlayer.message(player, F.main("KOTH", "You have joined " + F.elem(C.cYellow + "Yellow KOTH Team") + "."));
ArrayList<String> outfit = new ArrayList<String>(); ArrayList<String> outfit = new ArrayList<String>();
outfit.add("Team Helmet"); outfit.add("Team Helmet");
@ -204,7 +204,7 @@ public class KothManager extends MiniPlugin
{ {
_kothSword.Disable(player); _kothSword.Disable(player);
_active.remove(player); _active.remove(player);
UtilPlayer.message(player, F.main("Parkour", "You have exited " + F.elem("KOTH Mode") + ".")); UtilPlayer.message(player, F.main("KOTH", "You have exited " + F.elem("KOTH Mode") + "."));
} }
} }

View File

@ -461,11 +461,11 @@ public class SoccerManager extends MiniPlugin
_active.add(player); _active.add(player);
if (color == null) if (color == null)
UtilPlayer.message(player, F.main("Parkour", "You have entered " + F.elem("Slimeball Mode") + ".")); UtilPlayer.message(player, F.main("Slimeball", "You have entered " + F.elem("Slimeball Mode") + "."));
else if (color == Color.RED) else if (color == Color.RED)
UtilPlayer.message(player, F.main("Parkour", "You have joined " + F.elem(C.cRed + "Red Slimeball Team") + ".")); UtilPlayer.message(player, F.main("Slimeball", "You have joined " + F.elem(C.cRed + "Red Slimeball Team") + "."));
else if (color == Color.AQUA) else if (color == Color.AQUA)
UtilPlayer.message(player, F.main("Parkour", "You have joined " + F.elem(C.cAqua + "Blue Slimeball Team") + ".")); UtilPlayer.message(player, F.main("Slimeball", "You have joined " + F.elem(C.cAqua + "Blue Slimeball Team") + "."));
ArrayList<String> outfit = new ArrayList<String>(); ArrayList<String> outfit = new ArrayList<String>();
outfit.add("Team Helmet"); outfit.add("Team Helmet");

View File

@ -39,4 +39,7 @@ public interface ISkill
int getMaxLevel(); int getMaxLevel();
boolean isAchievementSkill(); boolean isAchievementSkill();
void setLocationFilter(LocationFilter locationFilter);
LocationFilter getLocationFilter();
} }

View File

@ -0,0 +1,18 @@
package mineplex.minecraft.game.classcombat.Skill;
import org.bukkit.Location;
/*
* Determines whether a location is acceptable for an action to be performed
*/
public interface LocationFilter
{
LocationFilter ACCEPT_ALL = location -> true;
/*
* Check if the given location is acceptable
* @param location The location to check
* @return Whether the location is valid, or invalid
*/
boolean accept(Location location);
}

View File

@ -1,6 +1,8 @@
package mineplex.minecraft.game.classcombat.Skill.Mage; package mineplex.minecraft.game.classcombat.Skill.Mage;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Material; import org.bukkit.Material;
@ -118,6 +120,9 @@ public class IcePrison extends SkillActive implements IThrown
//Sphere //Sphere
HashMap<Block, Double> blocks = UtilBlock.getInRadius(block, 3.8d); HashMap<Block, Double> blocks = UtilBlock.getInRadius(block, 3.8d);
// To save having to calculate everything again
Set<Block> acceptable = new HashSet<>();
boolean failed = false;
for (Block cur : blocks.keySet()) for (Block cur : blocks.keySet())
{ {
if (!UtilBlock.airFoliage(cur)) if (!UtilBlock.airFoliage(cur))
@ -129,8 +134,28 @@ public class IcePrison extends SkillActive implements IThrown
//Leave roof hole //Leave roof hole
if (cur.getX() == block.getX() && cur.getZ() == block.getZ() && cur.getY() > block.getY()) if (cur.getX() == block.getX() && cur.getZ() == block.getZ() && cur.getY() > block.getY())
continue; continue;
FreezeBlock(cur, block, level); if (getLocationFilter().accept(cur.getLocation()))
{
acceptable.add(cur);
}
else
{
failed = true;
break;
}
}
if (!failed)
{
for (Block cur : acceptable)
{
FreezeBlock(cur, block, level);
}
}
else
{
UtilPlayer.message(player, F.main("Skill", "You cannot use " + F.skill(GetName()) + " here."));
} }
/* /*

View File

@ -12,7 +12,6 @@ import mineplex.core.common.util.UtilTextBottom;
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType; import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
import mineplex.minecraft.game.classcombat.Skill.repository.token.SkillToken; import mineplex.minecraft.game.classcombat.Skill.repository.token.SkillToken;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -43,6 +42,8 @@ public abstract class Skill implements ISkill, Listener
private boolean _isAchievementSkill = false; private boolean _isAchievementSkill = false;
private LocationFilter _locationFilter = LocationFilter.ACCEPT_ALL;
public SkillFactory Factory; public SkillFactory Factory;
public Skill(SkillFactory skills, String name, ClassType classType, SkillType skillType, int cost, int maxLevel) public Skill(SkillFactory skills, String name, ClassType classType, SkillType skillType, int cost, int maxLevel)
@ -357,4 +358,16 @@ public abstract class Skill implements ISkill, Listener
{ {
return _isAchievementSkill; return _isAchievementSkill;
} }
@Override
public void setLocationFilter(LocationFilter filter)
{
this._locationFilter = filter;
}
@Override
public LocationFilter getLocationFilter()
{
return this._locationFilter;
}
} }

View File

@ -0,0 +1,62 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mineplex</groupId>
<artifactId>mineplex-app</artifactId>
<version>dev-SNAPSHOT</version>
<relativePath>../app.xml</relativePath>
</parent>
<name>ReportServer</name>
<artifactId>mineplex-reportserver</artifactId>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.mineplex</groupId>
<artifactId>mineplex-serverdata</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Main-Class>mineplex.reportserver.ReportServer</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,57 @@
package mineplex.reportserver;
import java.io.File;
import java.io.FileFilter;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.apache.commons.lang3.Validate;
/**
* Class responsible for deleting old files (file age is determined by the "last modified" value).
*/
public class FilePurger implements Runnable
{
private static final FileFilter FILE_FILTER = file -> file.isFile() && file.getName().endsWith(".json");
private final File _dataDir;
private final Logger _logger;
public FilePurger(File dataDir, Logger logger)
{
_dataDir = dataDir;
_logger = logger;
Validate.notNull(_dataDir, "Data directory cannot be null.");
Validate.isTrue(_dataDir.exists() && dataDir.isDirectory(), "Path non-existent or not a directory: %s", _dataDir.getAbsolutePath());
Validate.notNull(_logger, "Logger cannot be null.");
}
@Override
public void run()
{
int purgeCount = 0;
for (File file : _dataDir.listFiles(FILE_FILTER))
{
long lastModified = file.lastModified();
long timeSince = System.currentTimeMillis() - lastModified;
int days = (int) TimeUnit.MILLISECONDS.toDays(timeSince);
if (days >= 15) // keep files for 15 days
{
if (!file.delete())
{
_logger.warning("Cannot delete file: " + file.getAbsolutePath());
}
else
{
purgeCount++;
}
}
}
_logger.info("Purged " + purgeCount + " old chat snapshots.");
}
}

View File

@ -0,0 +1,142 @@
package mineplex.reportserver;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.lang3.Validate;
import redis.clients.jedis.JedisPubSub;
/**
* Listens for commands from Redis (such as "deploy" or "destroy") and executes them.
*/
public class RedisCommandHandler extends JedisPubSub
{
private static final Gson _gson = new GsonBuilder()
.setPrettyPrinting()
.create();
private static final JsonParser _jsonParser = new JsonParser();
private final File _directory;
private final Logger _logger;
private final ExecutorService _executorService = Executors.newCachedThreadPool();
public RedisCommandHandler(File directory, Logger logger)
{
_directory = directory;
_logger = logger;
Validate.notNull(_directory, "Directory cannot be null.");
Validate.isTrue(directory.exists() && directory.isDirectory(), "Path non-existent or not a directory: %s", directory.getPath());
Validate.notNull(_logger, "Logger cannot be null.");
}
@Override
public void onMessage(String channel, String dataString)
{
try
{
if (channel.equals(ReportServer.CHANNEL_DEPLOY))
{
String json = dataString;
JsonObject jsonObject = _jsonParser.parse(json).getAsJsonObject();
String token = jsonObject.get("token").getAsString();
File target = new File(_directory, token + ".json");
_logger.info("Chat snapshot received [" + token + "], writing to file.");
if (target.exists() && !jsonObject.has("snapshots"))
{
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(target)))
{
JsonObject originalJsonObject = _jsonParser.parse(bufferedReader).getAsJsonObject();
JsonObject usernamesObject = jsonObject.get("usernames").getAsJsonObject();
// retrieve snapshots from original file and add to jsonObject
jsonObject.add("snapshots", originalJsonObject.get("snapshots").getAsJsonArray());
// add new UUID->Usernames, update existing usernames
for (Map.Entry<String, JsonElement> entry : originalJsonObject.get("usernames").getAsJsonObject().entrySet())
{
usernamesObject.addProperty(entry.getKey(), entry.getValue().getAsJsonPrimitive().getAsString());
}
// re-write json after updating
json = _gson.toJson(jsonObject);
}
catch (Exception e)
{
_logger.log(Level.SEVERE, "Exception whilst updating an original snapshot.", e);
}
}
writeFile(target, json);
}
else if (channel.equals(ReportServer.CHANNEL_DESTROY))
{
// dataString = token
File target = new File(_directory, dataString + ".json");
_logger.info("Destroy command received [" + dataString + "].");
if (target.exists() && !target.delete())
{
_logger.warning("Failed to delete: " + target.getPath());
}
}
}
catch (Exception e)
{
_logger.log(Level.SEVERE, "Error whilst receiving redis message.", e);
}
}
private void writeFile(File file, String json)
{
_executorService.submit(() -> Files.write(file.toPath(), Arrays.asList(json.split("\n"))));
}
@Override
public void onPMessage(String s, String s1, String s2)
{
}
@Override
public void onSubscribe(String s, int i)
{
}
@Override
public void onUnsubscribe(String s, int i)
{
}
@Override
public void onPUnsubscribe(String s, int i)
{
}
@Override
public void onPSubscribe(String s, int i)
{
}
}

View File

@ -0,0 +1,106 @@
package mineplex.reportserver;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.time.DurationFormatUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
/**
* Establishes and maintains a connection to Redis.
*/
public class RedisConnectionHandler implements Runnable
{
private final String _name;
private final JedisPool _jedisPool;
private final RedisCommandHandler _handler;
private final String[] _channels;
private final Logger _logger;
private long _lastConnectionMillis = -1;
private Throwable _lastThrowable = null;
public RedisConnectionHandler(String name, JedisPool jedisPool, RedisCommandHandler handler, String[] channels, Logger logger)
{
_name = name;
_jedisPool = jedisPool;
_handler = handler;
_channels = channels;
_logger = logger;
Validate.isTrue(channels.length > 0, "Must provide at least one channel.");
}
@Override
public void run()
{
while (!Thread.interrupted())
{
try
{
registerChannelHandlers();
}
catch (Throwable e)
{
// Only log new errors (prevents same error being spammed)
if (_lastThrowable == null || !e.getClass().equals(_lastThrowable.getClass()))
{
if (_lastThrowable == null) // connection just failed
{
_lastConnectionMillis = System.currentTimeMillis();
}
_logger.log(Level.SEVERE, prefixMessage(
"Exception in Redis connection"
+ (_lastConnectionMillis != -1 ? " (no connection for " + getLastConnectionDuration() + ")" : "")
+ ", attempting to regain connection."
), e);
_lastThrowable = e;
}
try
{
Thread.sleep(1000 * 5);
}
catch (InterruptedException ignored) {}
}
}
_jedisPool.destroy();
_logger.warning("Thread interrupted, end of connection.");
}
private void registerChannelHandlers()
{
try (Jedis jedis = _jedisPool.getResource())
{
connectionEstablished();
jedis.subscribe(_handler, _channels);
}
}
private void connectionEstablished()
{
// subscribe blocks so we need to do all this before
_logger.info(
_lastThrowable == null
? prefixMessage("Connected.")
: prefixMessage(String.format("Connected after %s.", getLastConnectionDuration()))
);
_lastThrowable = null;
}
private String prefixMessage(String message)
{
return String.format("[%s] %s", _name, message);
}
private String getLastConnectionDuration()
{
return DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - _lastConnectionMillis, true, true);
}
}

View File

@ -0,0 +1,112 @@
package mineplex.reportserver;
import java.io.File;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import mineplex.serverdata.Utility;
import mineplex.serverdata.redis.RedisConfig;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ServerManager;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.Validate;
import redis.clients.jedis.JedisPool;
/**
* Main class for the Report server, parses command line arguments and initializes the Report server.
*/
public class ReportServer
{
public static final String CHANNEL_DEPLOY = "reportserver:deploy";
public static final String CHANNEL_DESTROY = "reportserver:destroy";
private static final String[] CHANNELS = new String[]{CHANNEL_DEPLOY, CHANNEL_DESTROY};
public static void main(String[] args)
{
System.setProperty("java.util.logging.SimpleFormatter.format", "%4$s: %5$s%6$s%n"); // Nicer log output
Logger logger = Logger.getLogger("ReportServer");
logger.info("Starting report server.");
Options options = new Options();
Option dirOption = Option.builder("dataDir")
.hasArg()
.longOpt("dataDirectory")
.desc("Sets the data directory where the JSON files will be stored.")
.type(File.class)
.build();
options.addOption(dirOption);
try
{
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
File dataDirectory = (File) cmd.getParsedOptionValue(dirOption.getOpt());
if (dataDirectory == null)
{
dataDirectory = new File("data");
}
new ReportServer(ServerManager.getDefaultConfig(), dataDirectory, logger);
}
catch (ParseException e)
{
logger.log(Level.SEVERE, "Failed to parse arguments.", e);
}
}
private final File _dataDirectory;
private final Logger _logger;
private final RedisCommandHandler _handler;
private final ScheduledExecutorService _executorService = Executors.newScheduledThreadPool(1);
public ReportServer(RedisConfig redisConfig, File dataDirectory, Logger logger)
{
_dataDirectory = dataDirectory;
_logger = logger;
Validate.notNull(_dataDirectory, "Data directory cannot be null.");
// thrown if path exists but is not a directory
Validate.isTrue(!_dataDirectory.exists() || _dataDirectory.isDirectory(), "Not a directory: %s", _dataDirectory.getPath());
// throws if directory doesn't exist and cannot be created
Validate.isTrue(_dataDirectory.exists() || _dataDirectory.mkdir(), "Unable to create directory: " + _dataDirectory.getPath());
_handler = new RedisCommandHandler(_dataDirectory, _logger);
initializeConnectionsConfig(redisConfig);
schedulePurgeTask();
}
private void initializeConnectionsConfig(RedisConfig redisConfig)
{
redisConfig.getConnections(false, null).forEach(this::initializeConnection);
}
private void initializeConnection(ConnectionData connectionData)
{
JedisPool jedisPool = Utility.generatePool(connectionData);
String connectionName = connectionData.getName();
Thread thread = new Thread(new RedisConnectionHandler(connectionName, jedisPool, _handler, CHANNELS, _logger), connectionName + " - Redis PubSub Thread");
thread.setDaemon(true);
thread.start();
}
private void schedulePurgeTask()
{
_executorService.scheduleAtFixedRate(new FilePurger(_dataDirectory, _logger), 0, 30, TimeUnit.MINUTES);
}
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,118 @@
@font-face {
font-family: 'Minecraftia';
src: url('Minecraftia.ttf');
}
h2,h3,h4,h5,h6 {
font-family: 'Oswald', sans-serif;
}
#wrapper {
}
#header {
padding-top: 20px;
padding-left: 20%;
padding-right: 20%;
background-color: #fa8144;
height: 175px;
text-align: center;
font-family: 'Crete Round', serif;
background-image: url("../img/bg.png");
background-position: -40px -40px;
}
#header h1 {
font-size: 55px;
text-shadow: 4px 3px 0px rgba(255, 255, 255, 0.55), 9px 8px 0px rgba(0,0,0,0.15);
}
#search {
padding: 5px 30%;
background-color: rgb(186, 85, 28);
}
#content {
padding-top: 10px;
padding-left: 20%;
padding-right: 20%;
min-height: 500px;
}
#footer {
border-top: solid 2px rgba(204, 204, 204, 0.64);
padding-left: 20%;
padding-right: 20%;
background-color: rgba(243, 243, 243, 0.64);
height: 100px;
padding-top: 20px;
}
#footer img {
opacity: 0.35;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
/* ...and now for the proper property */
transition:.5s;
}
#footer img:hover {
opacity: 0.7;
}
#footer a:hover {
text-decoration: none;
}
.name {
font-family: 'Minecraftia';
}
.label-staff {
background-color: #FFAA00;
}
.label-ultra {
background-color: #55FFFF;
}
#log {
font-family: 'Minecraftia';
font-size: 14px;
}
.black {
color: black;
}
.chat {
font-size: 13px;
}
.pm {
padding-left: 10px;
padding-right: 10px;
}
#test-bar {
align-content: center;
padding-top: 20px;
background-image: url("../img/bg.png");
min-height: 750px;
font-family: 'Crete Round', serif;
}
#test-bar h1 {
font-size: 48px;
text-shadow: 4px 3px 0px rgba(255, 255, 255, 0.55), 9px 8px 0px rgba(0,0,0,0.15);
}
.error-oh-no {
text-shadow: 4px 3px 0px rgba(255, 255, 255, 0.55), 9px 8px 0px rgba(0,0,0,0.15);
color: #d9534f;
font-family: Minecraftia;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 971 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
require('./umd/util.js')
require('./umd/alert.js')
require('./umd/button.js')
require('./umd/carousel.js')
require('./umd/collapse.js')
require('./umd/dropdown.js')
require('./umd/modal.js')
require('./umd/scrollspy.js')
require('./umd/tab.js')
require('./umd/tooltip.js')
require('./umd/popover.js')

View File

@ -0,0 +1,211 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module', './util'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module, require('./util'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod, global.Util);
global.alert = mod.exports;
}
})(this, function (exports, module, _util) {
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _Util = _interopRequireDefault(_util);
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.2): alert.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var Alert = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'alert';
var VERSION = '4.0.0-alpha';
var DATA_KEY = 'bs.alert';
var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var TRANSITION_DURATION = 150;
var Selector = {
DISMISS: '[data-dismiss="alert"]'
};
var Event = {
CLOSE: 'close' + EVENT_KEY,
CLOSED: 'closed' + EVENT_KEY,
CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
};
var ClassName = {
ALERT: 'alert',
FADE: 'fade',
IN: 'in'
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var Alert = (function () {
function Alert(element) {
_classCallCheck(this, Alert);
this._element = element;
}
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
// getters
_createClass(Alert, [{
key: 'close',
// public
value: function close(element) {
element = element || this._element;
var rootElement = this._getRootElement(element);
var customEvent = this._triggerCloseEvent(rootElement);
if (customEvent.isDefaultPrevented()) {
return;
}
this._removeElement(rootElement);
}
}, {
key: 'dispose',
value: function dispose() {
$.removeData(this._element, DATA_KEY);
this._element = null;
}
// private
}, {
key: '_getRootElement',
value: function _getRootElement(element) {
var selector = _Util['default'].getSelectorFromElement(element);
var parent = false;
if (selector) {
parent = $(selector)[0];
}
if (!parent) {
parent = $(element).closest('.' + ClassName.ALERT)[0];
}
return parent;
}
}, {
key: '_triggerCloseEvent',
value: function _triggerCloseEvent(element) {
var closeEvent = $.Event(Event.CLOSE);
$(element).trigger(closeEvent);
return closeEvent;
}
}, {
key: '_removeElement',
value: function _removeElement(element) {
$(element).removeClass(ClassName.IN);
if (!_Util['default'].supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) {
this._destroyElement(element);
return;
}
$(element).one(_Util['default'].TRANSITION_END, $.proxy(this._destroyElement, this, element)).emulateTransitionEnd(TRANSITION_DURATION);
}
}, {
key: '_destroyElement',
value: function _destroyElement(element) {
$(element).detach().trigger(Event.CLOSED).remove();
}
// static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
var $element = $(this);
var data = $element.data(DATA_KEY);
if (!data) {
data = new Alert(this);
$element.data(DATA_KEY, data);
}
if (config === 'close') {
data[config](this);
}
});
}
}, {
key: '_handleDismiss',
value: function _handleDismiss(alertInstance) {
return function (event) {
if (event) {
event.preventDefault();
}
alertInstance.close(this);
};
}
}, {
key: 'VERSION',
get: function get() {
return VERSION;
}
}]);
return Alert;
})();
$(document).on(Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert()));
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Alert._jQueryInterface;
$.fn[NAME].Constructor = Alert;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Alert._jQueryInterface;
};
return Alert;
})(jQuery);
module.exports = Alert;
});

View File

@ -0,0 +1,187 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module);
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod);
global.button = mod.exports;
}
})(this, function (exports, module) {
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.2): button.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var Button = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'button';
var VERSION = '4.0.0-alpha';
var DATA_KEY = 'bs.button';
var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var ClassName = {
ACTIVE: 'active',
BUTTON: 'btn',
FOCUS: 'focus'
};
var Selector = {
DATA_TOGGLE_CARROT: '[data-toggle^="button"]',
DATA_TOGGLE: '[data-toggle="buttons"]',
INPUT: 'input',
ACTIVE: '.active',
BUTTON: '.btn'
};
var Event = {
CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY,
FOCUS_BLUR_DATA_API: 'focus' + EVENT_KEY + DATA_API_KEY + ' ' + ('blur' + EVENT_KEY + DATA_API_KEY)
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var Button = (function () {
function Button(element) {
_classCallCheck(this, Button);
this._element = element;
}
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
// getters
_createClass(Button, [{
key: 'toggle',
// public
value: function toggle() {
var triggerChangeEvent = true;
var rootElement = $(this._element).closest(Selector.DATA_TOGGLE)[0];
if (rootElement) {
var input = $(this._element).find(Selector.INPUT)[0];
if (input) {
if (input.type === 'radio') {
if (input.checked && $(this._element).hasClass(ClassName.ACTIVE)) {
triggerChangeEvent = false;
} else {
var activeElement = $(rootElement).find(Selector.ACTIVE)[0];
if (activeElement) {
$(activeElement).removeClass(ClassName.ACTIVE);
}
}
}
if (triggerChangeEvent) {
input.checked = !$(this._element).hasClass(ClassName.ACTIVE);
$(this._element).trigger('change');
}
}
} else {
this._element.setAttribute('aria-pressed', !$(this._element).hasClass(ClassName.ACTIVE));
}
if (triggerChangeEvent) {
$(this._element).toggleClass(ClassName.ACTIVE);
}
}
}, {
key: 'dispose',
value: function dispose() {
$.removeData(this._element, DATA_KEY);
this._element = null;
}
// static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
if (!data) {
data = new Button(this);
$(this).data(DATA_KEY, data);
}
if (config === 'toggle') {
data[config]();
}
});
}
}, {
key: 'VERSION',
get: function get() {
return VERSION;
}
}]);
return Button;
})();
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
event.preventDefault();
var button = event.target;
if (!$(button).hasClass(ClassName.BUTTON)) {
button = $(button).closest(Selector.BUTTON);
}
Button._jQueryInterface.call($(button), 'toggle');
}).on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
var button = $(event.target).closest(Selector.BUTTON)[0];
$(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type));
});
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Button._jQueryInterface;
$.fn[NAME].Constructor = Button;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Button._jQueryInterface;
};
return Button;
})(jQuery);
module.exports = Button;
});

View File

@ -0,0 +1,497 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module', './util'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module, require('./util'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod, global.Util);
global.carousel = mod.exports;
}
})(this, function (exports, module, _util) {
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _Util = _interopRequireDefault(_util);
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.2): carousel.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var Carousel = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'carousel';
var VERSION = '4.0.0-alpha';
var DATA_KEY = 'bs.carousel';
var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var TRANSITION_DURATION = 600;
var Default = {
interval: 5000,
keyboard: true,
slide: false,
pause: 'hover',
wrap: true
};
var DefaultType = {
interval: '(number|boolean)',
keyboard: 'boolean',
slide: '(boolean|string)',
pause: '(string|boolean)',
wrap: 'boolean'
};
var Direction = {
NEXT: 'next',
PREVIOUS: 'prev'
};
var Event = {
SLIDE: 'slide' + EVENT_KEY,
SLID: 'slid' + EVENT_KEY,
KEYDOWN: 'keydown' + EVENT_KEY,
MOUSEENTER: 'mouseenter' + EVENT_KEY,
MOUSELEAVE: 'mouseleave' + EVENT_KEY,
LOAD_DATA_API: 'load' + EVENT_KEY + DATA_API_KEY,
CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
};
var ClassName = {
CAROUSEL: 'carousel',
ACTIVE: 'active',
SLIDE: 'slide',
RIGHT: 'right',
LEFT: 'left',
ITEM: 'carousel-item'
};
var Selector = {
ACTIVE: '.active',
ACTIVE_ITEM: '.active.carousel-item',
ITEM: '.carousel-item',
NEXT_PREV: '.next, .prev',
INDICATORS: '.carousel-indicators',
DATA_SLIDE: '[data-slide], [data-slide-to]',
DATA_RIDE: '[data-ride="carousel"]'
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var Carousel = (function () {
function Carousel(element, config) {
_classCallCheck(this, Carousel);
this._items = null;
this._interval = null;
this._activeElement = null;
this._isPaused = false;
this._isSliding = false;
this._config = this._getConfig(config);
this._element = $(element)[0];
this._indicatorsElement = $(this._element).find(Selector.INDICATORS)[0];
this._addEventListeners();
}
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
// getters
_createClass(Carousel, [{
key: 'next',
// public
value: function next() {
if (!this._isSliding) {
this._slide(Direction.NEXT);
}
}
}, {
key: 'nextWhenVisible',
value: function nextWhenVisible() {
// Don't call next when the page isn't visible
if (!document.hidden) {
this.next();
}
}
}, {
key: 'prev',
value: function prev() {
if (!this._isSliding) {
this._slide(Direction.PREVIOUS);
}
}
}, {
key: 'pause',
value: function pause(event) {
if (!event) {
this._isPaused = true;
}
if ($(this._element).find(Selector.NEXT_PREV)[0] && _Util['default'].supportsTransitionEnd()) {
_Util['default'].triggerTransitionEnd(this._element);
this.cycle(true);
}
clearInterval(this._interval);
this._interval = null;
}
}, {
key: 'cycle',
value: function cycle(event) {
if (!event) {
this._isPaused = false;
}
if (this._interval) {
clearInterval(this._interval);
this._interval = null;
}
if (this._config.interval && !this._isPaused) {
this._interval = setInterval($.proxy(document.visibilityState ? this.nextWhenVisible : this.next, this), this._config.interval);
}
}
}, {
key: 'to',
value: function to(index) {
var _this = this;
this._activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0];
var activeIndex = this._getItemIndex(this._activeElement);
if (index > this._items.length - 1 || index < 0) {
return;
}
if (this._isSliding) {
$(this._element).one(Event.SLID, function () {
return _this.to(index);
});
return;
}
if (activeIndex === index) {
this.pause();
this.cycle();
return;
}
var direction = index > activeIndex ? Direction.NEXT : Direction.PREVIOUS;
this._slide(direction, this._items[index]);
}
}, {
key: 'dispose',
value: function dispose() {
$(this._element).off(EVENT_KEY);
$.removeData(this._element, DATA_KEY);
this._items = null;
this._config = null;
this._element = null;
this._interval = null;
this._isPaused = null;
this._isSliding = null;
this._activeElement = null;
this._indicatorsElement = null;
}
// private
}, {
key: '_getConfig',
value: function _getConfig(config) {
config = $.extend({}, Default, config);
_Util['default'].typeCheckConfig(NAME, config, DefaultType);
return config;
}
}, {
key: '_addEventListeners',
value: function _addEventListeners() {
if (this._config.keyboard) {
$(this._element).on(Event.KEYDOWN, $.proxy(this._keydown, this));
}
if (this._config.pause === 'hover' && !('ontouchstart' in document.documentElement)) {
$(this._element).on(Event.MOUSEENTER, $.proxy(this.pause, this)).on(Event.MOUSELEAVE, $.proxy(this.cycle, this));
}
}
}, {
key: '_keydown',
value: function _keydown(event) {
event.preventDefault();
if (/input|textarea/i.test(event.target.tagName)) {
return;
}
switch (event.which) {
case 37:
this.prev();break;
case 39:
this.next();break;
default:
return;
}
}
}, {
key: '_getItemIndex',
value: function _getItemIndex(element) {
this._items = $.makeArray($(element).parent().find(Selector.ITEM));
return this._items.indexOf(element);
}
}, {
key: '_getItemByDirection',
value: function _getItemByDirection(direction, activeElement) {
var isNextDirection = direction === Direction.NEXT;
var isPrevDirection = direction === Direction.PREVIOUS;
var activeIndex = this._getItemIndex(activeElement);
var lastItemIndex = this._items.length - 1;
var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex;
if (isGoingToWrap && !this._config.wrap) {
return activeElement;
}
var delta = direction === Direction.PREVIOUS ? -1 : 1;
var itemIndex = (activeIndex + delta) % this._items.length;
return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
}
}, {
key: '_triggerSlideEvent',
value: function _triggerSlideEvent(relatedTarget, directionalClassname) {
var slideEvent = $.Event(Event.SLIDE, {
relatedTarget: relatedTarget,
direction: directionalClassname
});
$(this._element).trigger(slideEvent);
return slideEvent;
}
}, {
key: '_setActiveIndicatorElement',
value: function _setActiveIndicatorElement(element) {
if (this._indicatorsElement) {
$(this._indicatorsElement).find(Selector.ACTIVE).removeClass(ClassName.ACTIVE);
var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)];
if (nextIndicator) {
$(nextIndicator).addClass(ClassName.ACTIVE);
}
}
}
}, {
key: '_slide',
value: function _slide(direction, element) {
var _this2 = this;
var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0];
var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
var isCycling = Boolean(this._interval);
var directionalClassName = direction === Direction.NEXT ? ClassName.LEFT : ClassName.RIGHT;
if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) {
this._isSliding = false;
return;
}
var slideEvent = this._triggerSlideEvent(nextElement, directionalClassName);
if (slideEvent.isDefaultPrevented()) {
return;
}
if (!activeElement || !nextElement) {
// some weirdness is happening, so we bail
return;
}
this._isSliding = true;
if (isCycling) {
this.pause();
}
this._setActiveIndicatorElement(nextElement);
var slidEvent = $.Event(Event.SLID, {
relatedTarget: nextElement,
direction: directionalClassName
});
if (_Util['default'].supportsTransitionEnd() && $(this._element).hasClass(ClassName.SLIDE)) {
$(nextElement).addClass(direction);
_Util['default'].reflow(nextElement);
$(activeElement).addClass(directionalClassName);
$(nextElement).addClass(directionalClassName);
$(activeElement).one(_Util['default'].TRANSITION_END, function () {
$(nextElement).removeClass(directionalClassName).removeClass(direction);
$(nextElement).addClass(ClassName.ACTIVE);
$(activeElement).removeClass(ClassName.ACTIVE).removeClass(direction).removeClass(directionalClassName);
_this2._isSliding = false;
setTimeout(function () {
return $(_this2._element).trigger(slidEvent);
}, 0);
}).emulateTransitionEnd(TRANSITION_DURATION);
} else {
$(activeElement).removeClass(ClassName.ACTIVE);
$(nextElement).addClass(ClassName.ACTIVE);
this._isSliding = false;
$(this._element).trigger(slidEvent);
}
if (isCycling) {
this.cycle();
}
}
// static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
var _config = $.extend({}, Default, $(this).data());
if (typeof config === 'object') {
$.extend(_config, config);
}
var action = typeof config === 'string' ? config : _config.slide;
if (!data) {
data = new Carousel(this, _config);
$(this).data(DATA_KEY, data);
}
if (typeof config === 'number') {
data.to(config);
} else if (typeof action === 'string') {
if (data[action] === undefined) {
throw new Error('No method named "' + action + '"');
}
data[action]();
} else if (_config.interval) {
data.pause();
data.cycle();
}
});
}
}, {
key: '_dataApiClickHandler',
value: function _dataApiClickHandler(event) {
var selector = _Util['default'].getSelectorFromElement(this);
if (!selector) {
return;
}
var target = $(selector)[0];
if (!target || !$(target).hasClass(ClassName.CAROUSEL)) {
return;
}
var config = $.extend({}, $(target).data(), $(this).data());
var slideIndex = this.getAttribute('data-slide-to');
if (slideIndex) {
config.interval = false;
}
Carousel._jQueryInterface.call($(target), config);
if (slideIndex) {
$(target).data(DATA_KEY).to(slideIndex);
}
event.preventDefault();
}
}, {
key: 'VERSION',
get: function get() {
return VERSION;
}
}, {
key: 'Default',
get: function get() {
return Default;
}
}]);
return Carousel;
})();
$(document).on(Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler);
$(window).on(Event.LOAD_DATA_API, function () {
$(Selector.DATA_RIDE).each(function () {
var $carousel = $(this);
Carousel._jQueryInterface.call($carousel, $carousel.data());
});
});
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Carousel._jQueryInterface;
$.fn[NAME].Constructor = Carousel;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Carousel._jQueryInterface;
};
return Carousel;
})(jQuery);
module.exports = Carousel;
});

View File

@ -0,0 +1,383 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module', './util'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module, require('./util'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod, global.Util);
global.collapse = mod.exports;
}
})(this, function (exports, module, _util) {
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _Util = _interopRequireDefault(_util);
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.2): collapse.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var Collapse = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'collapse';
var VERSION = '4.0.0-alpha';
var DATA_KEY = 'bs.collapse';
var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var TRANSITION_DURATION = 600;
var Default = {
toggle: true,
parent: ''
};
var DefaultType = {
toggle: 'boolean',
parent: 'string'
};
var Event = {
SHOW: 'show' + EVENT_KEY,
SHOWN: 'shown' + EVENT_KEY,
HIDE: 'hide' + EVENT_KEY,
HIDDEN: 'hidden' + EVENT_KEY,
CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
};
var ClassName = {
IN: 'in',
COLLAPSE: 'collapse',
COLLAPSING: 'collapsing',
COLLAPSED: 'collapsed'
};
var Dimension = {
WIDTH: 'width',
HEIGHT: 'height'
};
var Selector = {
ACTIVES: '.panel > .in, .panel > .collapsing',
DATA_TOGGLE: '[data-toggle="collapse"]'
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var Collapse = (function () {
function Collapse(element, config) {
_classCallCheck(this, Collapse);
this._isTransitioning = false;
this._element = element;
this._config = this._getConfig(config);
this._triggerArray = $.makeArray($('[data-toggle="collapse"][href="#' + element.id + '"],' + ('[data-toggle="collapse"][data-target="#' + element.id + '"]')));
this._parent = this._config.parent ? this._getParent() : null;
if (!this._config.parent) {
this._addAriaAndCollapsedClass(this._element, this._triggerArray);
}
if (this._config.toggle) {
this.toggle();
}
}
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
// getters
_createClass(Collapse, [{
key: 'toggle',
// public
value: function toggle() {
if ($(this._element).hasClass(ClassName.IN)) {
this.hide();
} else {
this.show();
}
}
}, {
key: 'show',
value: function show() {
var _this = this;
if (this._isTransitioning || $(this._element).hasClass(ClassName.IN)) {
return;
}
var actives = undefined;
var activesData = undefined;
if (this._parent) {
actives = $.makeArray($(Selector.ACTIVES));
if (!actives.length) {
actives = null;
}
}
if (actives) {
activesData = $(actives).data(DATA_KEY);
if (activesData && activesData._isTransitioning) {
return;
}
}
var startEvent = $.Event(Event.SHOW);
$(this._element).trigger(startEvent);
if (startEvent.isDefaultPrevented()) {
return;
}
if (actives) {
Collapse._jQueryInterface.call($(actives), 'hide');
if (!activesData) {
$(actives).data(DATA_KEY, null);
}
}
var dimension = this._getDimension();
$(this._element).removeClass(ClassName.COLLAPSE).addClass(ClassName.COLLAPSING);
this._element.style[dimension] = 0;
this._element.setAttribute('aria-expanded', true);
if (this._triggerArray.length) {
$(this._triggerArray).removeClass(ClassName.COLLAPSED).attr('aria-expanded', true);
}
this.setTransitioning(true);
var complete = function complete() {
$(_this._element).removeClass(ClassName.COLLAPSING).addClass(ClassName.COLLAPSE).addClass(ClassName.IN);
_this._element.style[dimension] = '';
_this.setTransitioning(false);
$(_this._element).trigger(Event.SHOWN);
};
if (!_Util['default'].supportsTransitionEnd()) {
complete();
return;
}
var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
var scrollSize = 'scroll' + capitalizedDimension;
$(this._element).one(_Util['default'].TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
this._element.style[dimension] = this._element[scrollSize] + 'px';
}
}, {
key: 'hide',
value: function hide() {
var _this2 = this;
if (this._isTransitioning || !$(this._element).hasClass(ClassName.IN)) {
return;
}
var startEvent = $.Event(Event.HIDE);
$(this._element).trigger(startEvent);
if (startEvent.isDefaultPrevented()) {
return;
}
var dimension = this._getDimension();
var offsetDimension = dimension === Dimension.WIDTH ? 'offsetWidth' : 'offsetHeight';
this._element.style[dimension] = this._element[offsetDimension] + 'px';
_Util['default'].reflow(this._element);
$(this._element).addClass(ClassName.COLLAPSING).removeClass(ClassName.COLLAPSE).removeClass(ClassName.IN);
this._element.setAttribute('aria-expanded', false);
if (this._triggerArray.length) {
$(this._triggerArray).addClass(ClassName.COLLAPSED).attr('aria-expanded', false);
}
this.setTransitioning(true);
var complete = function complete() {
_this2.setTransitioning(false);
$(_this2._element).removeClass(ClassName.COLLAPSING).addClass(ClassName.COLLAPSE).trigger(Event.HIDDEN);
};
this._element.style[dimension] = 0;
if (!_Util['default'].supportsTransitionEnd()) {
complete();
return;
}
$(this._element).one(_Util['default'].TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
}
}, {
key: 'setTransitioning',
value: function setTransitioning(isTransitioning) {
this._isTransitioning = isTransitioning;
}
}, {
key: 'dispose',
value: function dispose() {
$.removeData(this._element, DATA_KEY);
this._config = null;
this._parent = null;
this._element = null;
this._triggerArray = null;
this._isTransitioning = null;
}
// private
}, {
key: '_getConfig',
value: function _getConfig(config) {
config = $.extend({}, Default, config);
config.toggle = Boolean(config.toggle); // coerce string values
_Util['default'].typeCheckConfig(NAME, config, DefaultType);
return config;
}
}, {
key: '_getDimension',
value: function _getDimension() {
var hasWidth = $(this._element).hasClass(Dimension.WIDTH);
return hasWidth ? Dimension.WIDTH : Dimension.HEIGHT;
}
}, {
key: '_getParent',
value: function _getParent() {
var _this3 = this;
var parent = $(this._config.parent)[0];
var selector = '[data-toggle="collapse"][data-parent="' + this._config.parent + '"]';
$(parent).find(selector).each(function (i, element) {
_this3._addAriaAndCollapsedClass(Collapse._getTargetFromElement(element), [element]);
});
return parent;
}
}, {
key: '_addAriaAndCollapsedClass',
value: function _addAriaAndCollapsedClass(element, triggerArray) {
if (element) {
var isOpen = $(element).hasClass(ClassName.IN);
element.setAttribute('aria-expanded', isOpen);
if (triggerArray.length) {
$(triggerArray).toggleClass(ClassName.COLLAPSED, !isOpen).attr('aria-expanded', isOpen);
}
}
}
// static
}], [{
key: '_getTargetFromElement',
value: function _getTargetFromElement(element) {
var selector = _Util['default'].getSelectorFromElement(element);
return selector ? $(selector)[0] : null;
}
}, {
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
var $this = $(this);
var data = $this.data(DATA_KEY);
var _config = $.extend({}, Default, $this.data(), typeof config === 'object' && config);
if (!data && _config.toggle && /show|hide/.test(config)) {
_config.toggle = false;
}
if (!data) {
data = new Collapse(this, _config);
$this.data(DATA_KEY, data);
}
if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error('No method named "' + config + '"');
}
data[config]();
}
});
}
}, {
key: 'VERSION',
get: function get() {
return VERSION;
}
}, {
key: 'Default',
get: function get() {
return Default;
}
}]);
return Collapse;
})();
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
event.preventDefault();
var target = Collapse._getTargetFromElement(this);
var data = $(target).data(DATA_KEY);
var config = data ? 'toggle' : $(this).data();
Collapse._jQueryInterface.call($(target), config);
});
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Collapse._jQueryInterface;
$.fn[NAME].Constructor = Collapse;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Collapse._jQueryInterface;
};
return Collapse;
})(jQuery);
module.exports = Collapse;
});

View File

@ -0,0 +1,312 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module', './util'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module, require('./util'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod, global.Util);
global.dropdown = mod.exports;
}
})(this, function (exports, module, _util) {
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _Util = _interopRequireDefault(_util);
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.2): dropdown.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var Dropdown = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'dropdown';
var VERSION = '4.0.0-alpha';
var DATA_KEY = 'bs.dropdown';
var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var Event = {
HIDE: 'hide' + EVENT_KEY,
HIDDEN: 'hidden' + EVENT_KEY,
SHOW: 'show' + EVENT_KEY,
SHOWN: 'shown' + EVENT_KEY,
CLICK: 'click' + EVENT_KEY,
CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY,
KEYDOWN_DATA_API: 'keydown' + EVENT_KEY + DATA_API_KEY
};
var ClassName = {
BACKDROP: 'dropdown-backdrop',
DISABLED: 'disabled',
OPEN: 'open'
};
var Selector = {
BACKDROP: '.dropdown-backdrop',
DATA_TOGGLE: '[data-toggle="dropdown"]',
FORM_CHILD: '.dropdown form',
ROLE_MENU: '[role="menu"]',
ROLE_LISTBOX: '[role="listbox"]',
NAVBAR_NAV: '.navbar-nav',
VISIBLE_ITEMS: '[role="menu"] li:not(.disabled) a, ' + '[role="listbox"] li:not(.disabled) a'
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var Dropdown = (function () {
function Dropdown(element) {
_classCallCheck(this, Dropdown);
this._element = element;
this._addEventListeners();
}
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
// getters
_createClass(Dropdown, [{
key: 'toggle',
// public
value: function toggle() {
if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {
return false;
}
var parent = Dropdown._getParentFromElement(this);
var isActive = $(parent).hasClass(ClassName.OPEN);
Dropdown._clearMenus();
if (isActive) {
return false;
}
if ('ontouchstart' in document.documentElement && !$(parent).closest(Selector.NAVBAR_NAV).length) {
// if mobile we use a backdrop because click events don't delegate
var dropdown = document.createElement('div');
dropdown.className = ClassName.BACKDROP;
$(dropdown).insertBefore(this);
$(dropdown).on('click', Dropdown._clearMenus);
}
var relatedTarget = { relatedTarget: this };
var showEvent = $.Event(Event.SHOW, relatedTarget);
$(parent).trigger(showEvent);
if (showEvent.isDefaultPrevented()) {
return false;
}
this.focus();
this.setAttribute('aria-expanded', 'true');
$(parent).toggleClass(ClassName.OPEN);
$(parent).trigger($.Event(Event.SHOWN, relatedTarget));
return false;
}
}, {
key: 'dispose',
value: function dispose() {
$.removeData(this._element, DATA_KEY);
$(this._element).off(EVENT_KEY);
this._element = null;
}
// private
}, {
key: '_addEventListeners',
value: function _addEventListeners() {
$(this._element).on(Event.CLICK, this.toggle);
}
// static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
if (!data) {
$(this).data(DATA_KEY, data = new Dropdown(this));
}
if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error('No method named "' + config + '"');
}
data[config].call(this);
}
});
}
}, {
key: '_clearMenus',
value: function _clearMenus(event) {
if (event && event.which === 3) {
return;
}
var backdrop = $(Selector.BACKDROP)[0];
if (backdrop) {
backdrop.parentNode.removeChild(backdrop);
}
var toggles = $.makeArray($(Selector.DATA_TOGGLE));
for (var i = 0; i < toggles.length; i++) {
var _parent = Dropdown._getParentFromElement(toggles[i]);
var relatedTarget = { relatedTarget: toggles[i] };
if (!$(_parent).hasClass(ClassName.OPEN)) {
continue;
}
if (event && event.type === 'click' && /input|textarea/i.test(event.target.tagName) && $.contains(_parent, event.target)) {
continue;
}
var hideEvent = $.Event(Event.HIDE, relatedTarget);
$(_parent).trigger(hideEvent);
if (hideEvent.isDefaultPrevented()) {
continue;
}
toggles[i].setAttribute('aria-expanded', 'false');
$(_parent).removeClass(ClassName.OPEN).trigger($.Event(Event.HIDDEN, relatedTarget));
}
}
}, {
key: '_getParentFromElement',
value: function _getParentFromElement(element) {
var parent = undefined;
var selector = _Util['default'].getSelectorFromElement(element);
if (selector) {
parent = $(selector)[0];
}
return parent || element.parentNode;
}
}, {
key: '_dataApiKeydownHandler',
value: function _dataApiKeydownHandler(event) {
if (!/(38|40|27|32)/.test(event.which) || /input|textarea/i.test(event.target.tagName)) {
return;
}
event.preventDefault();
event.stopPropagation();
if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {
return;
}
var parent = Dropdown._getParentFromElement(this);
var isActive = $(parent).hasClass(ClassName.OPEN);
if (!isActive && event.which !== 27 || isActive && event.which === 27) {
if (event.which === 27) {
var toggle = $(parent).find(Selector.DATA_TOGGLE)[0];
$(toggle).trigger('focus');
}
$(this).trigger('click');
return;
}
var items = $.makeArray($(Selector.VISIBLE_ITEMS));
items = items.filter(function (item) {
return item.offsetWidth || item.offsetHeight;
});
if (!items.length) {
return;
}
var index = items.indexOf(event.target);
if (event.which === 38 && index > 0) {
// up
index--;
}
if (event.which === 40 && index < items.length - 1) {
// down
index++;
}
if (! ~index) {
index = 0;
}
items[index].focus();
}
}, {
key: 'VERSION',
get: function get() {
return VERSION;
}
}]);
return Dropdown;
})();
$(document).on(Event.KEYDOWN_DATA_API, Selector.DATA_TOGGLE, Dropdown._dataApiKeydownHandler).on(Event.KEYDOWN_DATA_API, Selector.ROLE_MENU, Dropdown._dataApiKeydownHandler).on(Event.KEYDOWN_DATA_API, Selector.ROLE_LISTBOX, Dropdown._dataApiKeydownHandler).on(Event.CLICK_DATA_API, Dropdown._clearMenus).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, Dropdown.prototype.toggle).on(Event.CLICK_DATA_API, Selector.FORM_CHILD, function (e) {
e.stopPropagation();
});
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Dropdown._jQueryInterface;
$.fn[NAME].Constructor = Dropdown;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Dropdown._jQueryInterface;
};
return Dropdown;
})(jQuery);
module.exports = Dropdown;
});

View File

@ -0,0 +1,555 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module', './util'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module, require('./util'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod, global.Util);
global.modal = mod.exports;
}
})(this, function (exports, module, _util) {
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _Util = _interopRequireDefault(_util);
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.2): modal.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var Modal = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'modal';
var VERSION = '4.0.0-alpha';
var DATA_KEY = 'bs.modal';
var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var TRANSITION_DURATION = 300;
var BACKDROP_TRANSITION_DURATION = 150;
var Default = {
backdrop: true,
keyboard: true,
focus: true,
show: true
};
var DefaultType = {
backdrop: '(boolean|string)',
keyboard: 'boolean',
focus: 'boolean',
show: 'boolean'
};
var Event = {
HIDE: 'hide' + EVENT_KEY,
HIDDEN: 'hidden' + EVENT_KEY,
SHOW: 'show' + EVENT_KEY,
SHOWN: 'shown' + EVENT_KEY,
FOCUSIN: 'focusin' + EVENT_KEY,
RESIZE: 'resize' + EVENT_KEY,
CLICK_DISMISS: 'click.dismiss' + EVENT_KEY,
KEYDOWN_DISMISS: 'keydown.dismiss' + EVENT_KEY,
MOUSEUP_DISMISS: 'mouseup.dismiss' + EVENT_KEY,
MOUSEDOWN_DISMISS: 'mousedown.dismiss' + EVENT_KEY,
CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
};
var ClassName = {
SCROLLBAR_MEASURER: 'modal-scrollbar-measure',
BACKDROP: 'modal-backdrop',
OPEN: 'modal-open',
FADE: 'fade',
IN: 'in'
};
var Selector = {
DIALOG: '.modal-dialog',
DATA_TOGGLE: '[data-toggle="modal"]',
DATA_DISMISS: '[data-dismiss="modal"]',
FIXED_CONTENT: '.navbar-fixed-top, .navbar-fixed-bottom, .is-fixed'
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var Modal = (function () {
function Modal(element, config) {
_classCallCheck(this, Modal);
this._config = this._getConfig(config);
this._element = element;
this._dialog = $(element).find(Selector.DIALOG)[0];
this._backdrop = null;
this._isShown = false;
this._isBodyOverflowing = false;
this._ignoreBackdropClick = false;
this._originalBodyPadding = 0;
this._scrollbarWidth = 0;
}
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
// getters
_createClass(Modal, [{
key: 'toggle',
// public
value: function toggle(relatedTarget) {
return this._isShown ? this.hide() : this.show(relatedTarget);
}
}, {
key: 'show',
value: function show(relatedTarget) {
var _this = this;
var showEvent = $.Event(Event.SHOW, {
relatedTarget: relatedTarget
});
$(this._element).trigger(showEvent);
if (this._isShown || showEvent.isDefaultPrevented()) {
return;
}
this._isShown = true;
this._checkScrollbar();
this._setScrollbar();
$(document.body).addClass(ClassName.OPEN);
this._setEscapeEvent();
this._setResizeEvent();
$(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, $.proxy(this.hide, this));
$(this._dialog).on(Event.MOUSEDOWN_DISMISS, function () {
$(_this._element).one(Event.MOUSEUP_DISMISS, function (event) {
if ($(event.target).is(_this._element)) {
_this._ignoreBackdropClick = true;
}
});
});
this._showBackdrop($.proxy(this._showElement, this, relatedTarget));
}
}, {
key: 'hide',
value: function hide(event) {
if (event) {
event.preventDefault();
}
var hideEvent = $.Event(Event.HIDE);
$(this._element).trigger(hideEvent);
if (!this._isShown || hideEvent.isDefaultPrevented()) {
return;
}
this._isShown = false;
this._setEscapeEvent();
this._setResizeEvent();
$(document).off(Event.FOCUSIN);
$(this._element).removeClass(ClassName.IN);
$(this._element).off(Event.CLICK_DISMISS);
$(this._dialog).off(Event.MOUSEDOWN_DISMISS);
if (_Util['default'].supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) {
$(this._element).one(_Util['default'].TRANSITION_END, $.proxy(this._hideModal, this)).emulateTransitionEnd(TRANSITION_DURATION);
} else {
this._hideModal();
}
}
}, {
key: 'dispose',
value: function dispose() {
$.removeData(this._element, DATA_KEY);
$(window).off(EVENT_KEY);
$(document).off(EVENT_KEY);
$(this._element).off(EVENT_KEY);
$(this._backdrop).off(EVENT_KEY);
this._config = null;
this._element = null;
this._dialog = null;
this._backdrop = null;
this._isShown = null;
this._isBodyOverflowing = null;
this._ignoreBackdropClick = null;
this._originalBodyPadding = null;
this._scrollbarWidth = null;
}
// private
}, {
key: '_getConfig',
value: function _getConfig(config) {
config = $.extend({}, Default, config);
_Util['default'].typeCheckConfig(NAME, config, DefaultType);
return config;
}
}, {
key: '_showElement',
value: function _showElement(relatedTarget) {
var _this2 = this;
var transition = _Util['default'].supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE);
if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
// don't move modals dom position
document.body.appendChild(this._element);
}
this._element.style.display = 'block';
this._element.scrollTop = 0;
if (transition) {
_Util['default'].reflow(this._element);
}
$(this._element).addClass(ClassName.IN);
if (this._config.focus) {
this._enforceFocus();
}
var shownEvent = $.Event(Event.SHOWN, {
relatedTarget: relatedTarget
});
var transitionComplete = function transitionComplete() {
if (_this2._config.focus) {
_this2._element.focus();
}
$(_this2._element).trigger(shownEvent);
};
if (transition) {
$(this._dialog).one(_Util['default'].TRANSITION_END, transitionComplete).emulateTransitionEnd(TRANSITION_DURATION);
} else {
transitionComplete();
}
}
}, {
key: '_enforceFocus',
value: function _enforceFocus() {
var _this3 = this;
$(document).off(Event.FOCUSIN) // guard against infinite focus loop
.on(Event.FOCUSIN, function (event) {
if (_this3._element !== event.target && !$(_this3._element).has(event.target).length) {
_this3._element.focus();
}
});
}
}, {
key: '_setEscapeEvent',
value: function _setEscapeEvent() {
var _this4 = this;
if (this._isShown && this._config.keyboard) {
$(this._element).on(Event.KEYDOWN_DISMISS, function (event) {
if (event.which === 27) {
_this4.hide();
}
});
} else if (!this._isShown) {
$(this._element).off(Event.KEYDOWN_DISMISS);
}
}
}, {
key: '_setResizeEvent',
value: function _setResizeEvent() {
if (this._isShown) {
$(window).on(Event.RESIZE, $.proxy(this._handleUpdate, this));
} else {
$(window).off(Event.RESIZE);
}
}
}, {
key: '_hideModal',
value: function _hideModal() {
var _this5 = this;
this._element.style.display = 'none';
this._showBackdrop(function () {
$(document.body).removeClass(ClassName.OPEN);
_this5._resetAdjustments();
_this5._resetScrollbar();
$(_this5._element).trigger(Event.HIDDEN);
});
}
}, {
key: '_removeBackdrop',
value: function _removeBackdrop() {
if (this._backdrop) {
$(this._backdrop).remove();
this._backdrop = null;
}
}
}, {
key: '_showBackdrop',
value: function _showBackdrop(callback) {
var _this6 = this;
var animate = $(this._element).hasClass(ClassName.FADE) ? ClassName.FADE : '';
if (this._isShown && this._config.backdrop) {
var doAnimate = _Util['default'].supportsTransitionEnd() && animate;
this._backdrop = document.createElement('div');
this._backdrop.className = ClassName.BACKDROP;
if (animate) {
$(this._backdrop).addClass(animate);
}
$(this._backdrop).appendTo(document.body);
$(this._element).on(Event.CLICK_DISMISS, function (event) {
if (_this6._ignoreBackdropClick) {
_this6._ignoreBackdropClick = false;
return;
}
if (event.target !== event.currentTarget) {
return;
}
if (_this6._config.backdrop === 'static') {
_this6._element.focus();
} else {
_this6.hide();
}
});
if (doAnimate) {
_Util['default'].reflow(this._backdrop);
}
$(this._backdrop).addClass(ClassName.IN);
if (!callback) {
return;
}
if (!doAnimate) {
callback();
return;
}
$(this._backdrop).one(_Util['default'].TRANSITION_END, callback).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION);
} else if (!this._isShown && this._backdrop) {
$(this._backdrop).removeClass(ClassName.IN);
var callbackRemove = function callbackRemove() {
_this6._removeBackdrop();
if (callback) {
callback();
}
};
if (_Util['default'].supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) {
$(this._backdrop).one(_Util['default'].TRANSITION_END, callbackRemove).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION);
} else {
callbackRemove();
}
} else if (callback) {
callback();
}
}
// ----------------------------------------------------------------------
// the following methods are used to handle overflowing modals
// todo (fat): these should probably be refactored out of modal.js
// ----------------------------------------------------------------------
}, {
key: '_handleUpdate',
value: function _handleUpdate() {
this._adjustDialog();
}
}, {
key: '_adjustDialog',
value: function _adjustDialog() {
var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
if (!this._isBodyOverflowing && isModalOverflowing) {
this._element.style.paddingLeft = this._scrollbarWidth + 'px';
}
if (this._isBodyOverflowing && !isModalOverflowing) {
this._element.style.paddingRight = this._scrollbarWidth + 'px~';
}
}
}, {
key: '_resetAdjustments',
value: function _resetAdjustments() {
this._element.style.paddingLeft = '';
this._element.style.paddingRight = '';
}
}, {
key: '_checkScrollbar',
value: function _checkScrollbar() {
var fullWindowWidth = window.innerWidth;
if (!fullWindowWidth) {
// workaround for missing window.innerWidth in IE8
var documentElementRect = document.documentElement.getBoundingClientRect();
fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);
}
this._isBodyOverflowing = document.body.clientWidth < fullWindowWidth;
this._scrollbarWidth = this._getScrollbarWidth();
}
}, {
key: '_setScrollbar',
value: function _setScrollbar() {
var bodyPadding = parseInt($(Selector.FIXED_CONTENT).css('padding-right') || 0, 10);
this._originalBodyPadding = document.body.style.paddingRight || '';
if (this._isBodyOverflowing) {
document.body.style.paddingRight = bodyPadding + this._scrollbarWidth + 'px';
}
}
}, {
key: '_resetScrollbar',
value: function _resetScrollbar() {
document.body.style.paddingRight = this._originalBodyPadding;
}
}, {
key: '_getScrollbarWidth',
value: function _getScrollbarWidth() {
// thx d.walsh
var scrollDiv = document.createElement('div');
scrollDiv.className = ClassName.SCROLLBAR_MEASURER;
document.body.appendChild(scrollDiv);
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
document.body.removeChild(scrollDiv);
return scrollbarWidth;
}
// static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config, relatedTarget) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
var _config = $.extend({}, Modal.Default, $(this).data(), typeof config === 'object' && config);
if (!data) {
data = new Modal(this, _config);
$(this).data(DATA_KEY, data);
}
if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error('No method named "' + config + '"');
}
data[config](relatedTarget);
} else if (_config.show) {
data.show(relatedTarget);
}
});
}
}, {
key: 'VERSION',
get: function get() {
return VERSION;
}
}, {
key: 'Default',
get: function get() {
return Default;
}
}]);
return Modal;
})();
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
var _this7 = this;
var target = undefined;
var selector = _Util['default'].getSelectorFromElement(this);
if (selector) {
target = $(selector)[0];
}
var config = $(target).data(DATA_KEY) ? 'toggle' : $.extend({}, $(target).data(), $(this).data());
if (this.tagName === 'A') {
event.preventDefault();
}
var $target = $(target).one(Event.SHOW, function (showEvent) {
if (showEvent.isDefaultPrevented()) {
// only register focus restorer if modal will actually get shown
return;
}
$target.one(Event.HIDDEN, function () {
if ($(_this7).is(':visible')) {
_this7.focus();
}
});
});
Modal._jQueryInterface.call($(target), config, this);
});
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Modal._jQueryInterface;
$.fn[NAME].Constructor = Modal;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Modal._jQueryInterface;
};
return Modal;
})(jQuery);
module.exports = Modal;
});

View File

@ -0,0 +1,220 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module', './tooltip'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module, require('./tooltip'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod, global.Tooltip);
global.popover = mod.exports;
}
})(this, function (exports, module, _tooltip) {
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _Tooltip2 = _interopRequireDefault(_tooltip);
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.2): popover.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var Popover = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'popover';
var VERSION = '4.0.0-alpha';
var DATA_KEY = 'bs.popover';
var EVENT_KEY = '.' + DATA_KEY;
var JQUERY_NO_CONFLICT = $.fn[NAME];
var Default = $.extend({}, _Tooltip2['default'].Default, {
placement: 'right',
trigger: 'click',
content: '',
template: '<div class="popover" role="tooltip">' + '<div class="popover-arrow"></div>' + '<h3 class="popover-title"></h3>' + '<div class="popover-content"></div></div>'
});
var DefaultType = $.extend({}, _Tooltip2['default'].DefaultType, {
content: '(string|element|function)'
});
var ClassName = {
FADE: 'fade',
IN: 'in'
};
var Selector = {
TITLE: '.popover-title',
CONTENT: '.popover-content',
ARROW: '.popover-arrow'
};
var Event = {
HIDE: 'hide' + EVENT_KEY,
HIDDEN: 'hidden' + EVENT_KEY,
SHOW: 'show' + EVENT_KEY,
SHOWN: 'shown' + EVENT_KEY,
INSERTED: 'inserted' + EVENT_KEY,
CLICK: 'click' + EVENT_KEY,
FOCUSIN: 'focusin' + EVENT_KEY,
FOCUSOUT: 'focusout' + EVENT_KEY,
MOUSEENTER: 'mouseenter' + EVENT_KEY,
MOUSELEAVE: 'mouseleave' + EVENT_KEY
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var Popover = (function (_Tooltip) {
_inherits(Popover, _Tooltip);
function Popover() {
_classCallCheck(this, Popover);
_get(Object.getPrototypeOf(Popover.prototype), 'constructor', this).apply(this, arguments);
}
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
_createClass(Popover, [{
key: 'isWithContent',
// overrides
value: function isWithContent() {
return this.getTitle() || this._getContent();
}
}, {
key: 'getTipElement',
value: function getTipElement() {
return this.tip = this.tip || $(this.config.template)[0];
}
}, {
key: 'setContent',
value: function setContent() {
var $tip = $(this.getTipElement());
// we use append for html objects to maintain js events
this.setElementContent($tip.find(Selector.TITLE), this.getTitle());
this.setElementContent($tip.find(Selector.CONTENT), this._getContent());
$tip.removeClass(ClassName.FADE).removeClass(ClassName.IN);
this.cleanupTether();
}
// private
}, {
key: '_getContent',
value: function _getContent() {
return this.element.getAttribute('data-content') || (typeof this.config.content === 'function' ? this.config.content.call(this.element) : this.config.content);
}
// static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
var _config = typeof config === 'object' ? config : null;
if (!data && /destroy|hide/.test(config)) {
return;
}
if (!data) {
data = new Popover(this, _config);
$(this).data(DATA_KEY, data);
}
if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error('No method named "' + config + '"');
}
data[config]();
}
});
}
}, {
key: 'VERSION',
// getters
get: function get() {
return VERSION;
}
}, {
key: 'Default',
get: function get() {
return Default;
}
}, {
key: 'NAME',
get: function get() {
return NAME;
}
}, {
key: 'DATA_KEY',
get: function get() {
return DATA_KEY;
}
}, {
key: 'Event',
get: function get() {
return Event;
}
}, {
key: 'EVENT_KEY',
get: function get() {
return EVENT_KEY;
}
}, {
key: 'DefaultType',
get: function get() {
return DefaultType;
}
}]);
return Popover;
})(_Tooltip2['default']);
$.fn[NAME] = Popover._jQueryInterface;
$.fn[NAME].Constructor = Popover;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Popover._jQueryInterface;
};
return Popover;
})(jQuery);
module.exports = Popover;
});

View File

@ -0,0 +1,339 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module', './util'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module, require('./util'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod, global.Util);
global.scrollspy = mod.exports;
}
})(this, function (exports, module, _util) {
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _Util = _interopRequireDefault(_util);
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.2): scrollspy.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var ScrollSpy = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'scrollspy';
var VERSION = '4.0.0-alpha';
var DATA_KEY = 'bs.scrollspy';
var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var Default = {
offset: 10,
method: 'auto',
target: ''
};
var DefaultType = {
offset: 'number',
method: 'string',
target: '(string|element)'
};
var Event = {
ACTIVATE: 'activate' + EVENT_KEY,
SCROLL: 'scroll' + EVENT_KEY,
LOAD_DATA_API: 'load' + EVENT_KEY + DATA_API_KEY
};
var ClassName = {
DROPDOWN_ITEM: 'dropdown-item',
DROPDOWN_MENU: 'dropdown-menu',
NAV_LINK: 'nav-link',
NAV: 'nav',
ACTIVE: 'active'
};
var Selector = {
DATA_SPY: '[data-spy="scroll"]',
ACTIVE: '.active',
LIST_ITEM: '.list-item',
LI: 'li',
LI_DROPDOWN: 'li.dropdown',
NAV_LINKS: '.nav-link',
DROPDOWN: '.dropdown',
DROPDOWN_ITEMS: '.dropdown-item',
DROPDOWN_TOGGLE: '.dropdown-toggle'
};
var OffsetMethod = {
OFFSET: 'offset',
POSITION: 'position'
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var ScrollSpy = (function () {
function ScrollSpy(element, config) {
_classCallCheck(this, ScrollSpy);
this._element = element;
this._scrollElement = element.tagName === 'BODY' ? window : element;
this._config = this._getConfig(config);
this._selector = this._config.target + ' ' + Selector.NAV_LINKS + ',' + (this._config.target + ' ' + Selector.DROPDOWN_ITEMS);
this._offsets = [];
this._targets = [];
this._activeTarget = null;
this._scrollHeight = 0;
$(this._scrollElement).on(Event.SCROLL, $.proxy(this._process, this));
this.refresh();
this._process();
}
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
// getters
_createClass(ScrollSpy, [{
key: 'refresh',
// public
value: function refresh() {
var _this = this;
var autoMethod = this._scrollElement !== this._scrollElement.window ? OffsetMethod.POSITION : OffsetMethod.OFFSET;
var offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method;
var offsetBase = offsetMethod === OffsetMethod.POSITION ? this._getScrollTop() : 0;
this._offsets = [];
this._targets = [];
this._scrollHeight = this._getScrollHeight();
var targets = $.makeArray($(this._selector));
targets.map(function (element) {
var target = undefined;
var targetSelector = _Util['default'].getSelectorFromElement(element);
if (targetSelector) {
target = $(targetSelector)[0];
}
if (target && (target.offsetWidth || target.offsetHeight)) {
// todo (fat): remove sketch reliance on jQuery position/offset
return [$(target)[offsetMethod]().top + offsetBase, targetSelector];
}
}).filter(function (item) {
return item;
}).sort(function (a, b) {
return a[0] - b[0];
}).forEach(function (item) {
_this._offsets.push(item[0]);
_this._targets.push(item[1]);
});
}
}, {
key: 'dispose',
value: function dispose() {
$.removeData(this._element, DATA_KEY);
$(this._scrollElement).off(EVENT_KEY);
this._element = null;
this._scrollElement = null;
this._config = null;
this._selector = null;
this._offsets = null;
this._targets = null;
this._activeTarget = null;
this._scrollHeight = null;
}
// private
}, {
key: '_getConfig',
value: function _getConfig(config) {
config = $.extend({}, Default, config);
if (typeof config.target !== 'string') {
var id = $(config.target).attr('id');
if (!id) {
id = _Util['default'].getUID(NAME);
$(config.target).attr('id', id);
}
config.target = '#' + id;
}
_Util['default'].typeCheckConfig(NAME, config, DefaultType);
return config;
}
}, {
key: '_getScrollTop',
value: function _getScrollTop() {
return this._scrollElement === window ? this._scrollElement.scrollY : this._scrollElement.scrollTop;
}
}, {
key: '_getScrollHeight',
value: function _getScrollHeight() {
return this._scrollElement.scrollHeight || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}
}, {
key: '_process',
value: function _process() {
var scrollTop = this._getScrollTop() + this._config.offset;
var scrollHeight = this._getScrollHeight();
var maxScroll = this._config.offset + scrollHeight - this._scrollElement.offsetHeight;
if (this._scrollHeight !== scrollHeight) {
this.refresh();
}
if (scrollTop >= maxScroll) {
var target = this._targets[this._targets.length - 1];
if (this._activeTarget !== target) {
this._activate(target);
}
}
if (this._activeTarget && scrollTop < this._offsets[0]) {
this._activeTarget = null;
this._clear();
return;
}
for (var i = this._offsets.length; i--;) {
var isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] && (this._offsets[i + 1] === undefined || scrollTop < this._offsets[i + 1]);
if (isActiveTarget) {
this._activate(this._targets[i]);
}
}
}
}, {
key: '_activate',
value: function _activate(target) {
this._activeTarget = target;
this._clear();
var queries = this._selector.split(',');
queries = queries.map(function (selector) {
return selector + '[data-target="' + target + '"],' + (selector + '[href="' + target + '"]');
});
var $link = $(queries.join(','));
if ($link.hasClass(ClassName.DROPDOWN_ITEM)) {
$link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE);
$link.addClass(ClassName.ACTIVE);
} else {
// todo (fat) this is kinda sus…
// recursively add actives to tested nav-links
$link.parents(Selector.LI).find(Selector.NAV_LINKS).addClass(ClassName.ACTIVE);
}
$(this._scrollElement).trigger(Event.ACTIVATE, {
relatedTarget: target
});
}
}, {
key: '_clear',
value: function _clear() {
$(this._selector).filter(Selector.ACTIVE).removeClass(ClassName.ACTIVE);
}
// static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
var _config = typeof config === 'object' && config || null;
if (!data) {
data = new ScrollSpy(this, _config);
$(this).data(DATA_KEY, data);
}
if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error('No method named "' + config + '"');
}
data[config]();
}
});
}
}, {
key: 'VERSION',
get: function get() {
return VERSION;
}
}, {
key: 'Default',
get: function get() {
return Default;
}
}]);
return ScrollSpy;
})();
$(window).on(Event.LOAD_DATA_API, function () {
var scrollSpys = $.makeArray($(Selector.DATA_SPY));
for (var i = scrollSpys.length; i--;) {
var $spy = $(scrollSpys[i]);
ScrollSpy._jQueryInterface.call($spy, $spy.data());
}
});
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = ScrollSpy._jQueryInterface;
$.fn[NAME].Constructor = ScrollSpy;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return ScrollSpy._jQueryInterface;
};
return ScrollSpy;
})(jQuery);
module.exports = ScrollSpy;
});

View File

@ -0,0 +1,282 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module', './util'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module, require('./util'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod, global.Util);
global.tab = mod.exports;
}
})(this, function (exports, module, _util) {
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _Util = _interopRequireDefault(_util);
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.2): tab.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var Tab = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'tab';
var VERSION = '4.0.0-alpha';
var DATA_KEY = 'bs.tab';
var EVENT_KEY = '.' + DATA_KEY;
var DATA_API_KEY = '.data-api';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var TRANSITION_DURATION = 150;
var Event = {
HIDE: 'hide' + EVENT_KEY,
HIDDEN: 'hidden' + EVENT_KEY,
SHOW: 'show' + EVENT_KEY,
SHOWN: 'shown' + EVENT_KEY,
CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
};
var ClassName = {
DROPDOWN_MENU: 'dropdown-menu',
ACTIVE: 'active',
FADE: 'fade',
IN: 'in'
};
var Selector = {
A: 'a',
LI: 'li',
DROPDOWN: '.dropdown',
UL: 'ul:not(.dropdown-menu)',
FADE_CHILD: '> .nav-item .fade, > .fade',
ACTIVE: '.active',
ACTIVE_CHILD: '> .nav-item > .active, > .active',
DATA_TOGGLE: '[data-toggle="tab"], [data-toggle="pill"]',
DROPDOWN_TOGGLE: '.dropdown-toggle',
DROPDOWN_ACTIVE_CHILD: '> .dropdown-menu .active'
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var Tab = (function () {
function Tab(element) {
_classCallCheck(this, Tab);
this._element = element;
}
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
// getters
_createClass(Tab, [{
key: 'show',
// public
value: function show() {
var _this = this;
if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).hasClass(ClassName.ACTIVE)) {
return;
}
var target = undefined;
var previous = undefined;
var ulElement = $(this._element).closest(Selector.UL)[0];
var selector = _Util['default'].getSelectorFromElement(this._element);
if (ulElement) {
previous = $.makeArray($(ulElement).find(Selector.ACTIVE));
previous = previous[previous.length - 1];
}
var hideEvent = $.Event(Event.HIDE, {
relatedTarget: this._element
});
var showEvent = $.Event(Event.SHOW, {
relatedTarget: previous
});
if (previous) {
$(previous).trigger(hideEvent);
}
$(this._element).trigger(showEvent);
if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) {
return;
}
if (selector) {
target = $(selector)[0];
}
this._activate(this._element, ulElement);
var complete = function complete() {
var hiddenEvent = $.Event(Event.HIDDEN, {
relatedTarget: _this._element
});
var shownEvent = $.Event(Event.SHOWN, {
relatedTarget: previous
});
$(previous).trigger(hiddenEvent);
$(_this._element).trigger(shownEvent);
};
if (target) {
this._activate(target, target.parentNode, complete);
} else {
complete();
}
}
}, {
key: 'dispose',
value: function dispose() {
$.removeClass(this._element, DATA_KEY);
this._element = null;
}
// private
}, {
key: '_activate',
value: function _activate(element, container, callback) {
var active = $(container).find(Selector.ACTIVE_CHILD)[0];
var isTransitioning = callback && _Util['default'].supportsTransitionEnd() && (active && $(active).hasClass(ClassName.FADE) || Boolean($(container).find(Selector.FADE_CHILD)[0]));
var complete = $.proxy(this._transitionComplete, this, element, active, isTransitioning, callback);
if (active && isTransitioning) {
$(active).one(_Util['default'].TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
} else {
complete();
}
if (active) {
$(active).removeClass(ClassName.IN);
}
}
}, {
key: '_transitionComplete',
value: function _transitionComplete(element, active, isTransitioning, callback) {
if (active) {
$(active).removeClass(ClassName.ACTIVE);
var dropdownChild = $(active).find(Selector.DROPDOWN_ACTIVE_CHILD)[0];
if (dropdownChild) {
$(dropdownChild).removeClass(ClassName.ACTIVE);
}
active.setAttribute('aria-expanded', false);
}
$(element).addClass(ClassName.ACTIVE);
element.setAttribute('aria-expanded', true);
if (isTransitioning) {
_Util['default'].reflow(element);
$(element).addClass(ClassName.IN);
} else {
$(element).removeClass(ClassName.FADE);
}
if (element.parentNode && $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) {
var dropdownElement = $(element).closest(Selector.DROPDOWN)[0];
if (dropdownElement) {
$(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE);
}
element.setAttribute('aria-expanded', true);
}
if (callback) {
callback();
}
}
// static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
var $this = $(this);
var data = $this.data(DATA_KEY);
if (!data) {
data = data = new Tab(this);
$this.data(DATA_KEY, data);
}
if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error('No method named "' + config + '"');
}
data[config]();
}
});
}
}, {
key: 'VERSION',
get: function get() {
return VERSION;
}
}]);
return Tab;
})();
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
event.preventDefault();
Tab._jQueryInterface.call($(this), 'show');
});
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Tab._jQueryInterface;
$.fn[NAME].Constructor = Tab;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Tab._jQueryInterface;
};
return Tab;
})(jQuery);
module.exports = Tab;
});

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