Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Mark LangUtils as depends, compatible with Essentials (not X)
Browse files Browse the repository at this point in the history
  • Loading branch information
Librazy committed Mar 30, 2018
1 parent e80b86c commit 9dc9144
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ deploy:
file: ./NyaaUtils-v$VERSION_STRING.jar
on:
tags: false
all_branches: true
18 changes: 17 additions & 1 deletion src/main/java/cat/nyaa/nyaautils/NyaaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import cat.nyaa.nyaautils.timer.TimerListener;
import cat.nyaa.nyaautils.timer.TimerManager;
import cat.nyaa.nyaautils.vote.VoteTask;
import com.earth2me.essentials.ISettings;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import net.ess3.api.IEssentials;
import org.bukkit.command.TabCompleter;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;

import java.lang.reflect.InvocationTargetException;

public class NyaaUtils extends JavaPlugin {
public static NyaaUtils instance;
public ISystemBalance systemBalance = null;
Expand Down Expand Up @@ -82,7 +85,20 @@ public void onEnable() {
particleListener = new ParticleListener(this);
signEditListener = new SignEditListener(this);
mentionListener = new MentionListener(this);
esschatListener = new EsschatListener(this);
try {
ISettings settings = ess.getSettings();
Class<? extends ISettings> essSettingsClass = settings.getClass();
Long timeout = (Long) essSettingsClass.getMethod("getLastMessageReplyRecipientTimeout").invoke(settings);
// TODO: sort out reply recipient when isLastMessageReplyRecipient set to false instead disabling it
Boolean allow = (Boolean) essSettingsClass.getMethod("isLastMessageReplyRecipient").invoke(settings);
esschatListener = new EsschatListener(this, allow, timeout);
} catch (NoSuchMethodException e) {
getLogger().warning("EssentialsX not available, not enabling mention notify in /reply commands");
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
getLogger().warning("Unexpected error when enabling mention notify in EssentialsX commands");
}

voteTask = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cat.nyaa.nyaautils.mention.MentionListener;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import net.ess3.api.IEssentials;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -19,40 +18,41 @@
import java.util.stream.Stream;

public class EsschatListener implements Listener {
private final IEssentials ess;
private final NyaaUtils plugin;
private final boolean allowMentionReply;
private final Cache<UUID, UUID> r;

public EsschatListener(NyaaUtils pl) {
public EsschatListener(NyaaUtils pl, boolean allowMentionReply, long timeout) {
this.plugin = pl;
this.ess = (IEssentials) plugin.getServer().getPluginManager().getPlugin("Essentials");
this.allowMentionReply = allowMentionReply;
if (plugin.cfg.mention_enable) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
r = CacheBuilder.newBuilder().expireAfterWrite(ess.getSettings().getLastMessageReplyRecipientTimeout(), TimeUnit.SECONDS).build();
r = CacheBuilder.newBuilder().expireAfterWrite(timeout, TimeUnit.SECONDS).build();
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCommandPreProcess(PlayerCommandPreprocessEvent e) throws ExecutionException {
if (plugin.cfg.mention_enable) {
String cmd = e.getMessage().toLowerCase().trim();
if(Stream.of("/msg ", "/tell ", "/m ", "/t ", "/whisper ").parallel().anyMatch(cmd::startsWith)){
if (Stream.of("/msg ", "/tell ", "/m ", "/t ", "/whisper ").parallel().anyMatch(cmd::startsWith)) {
String[] split = cmd.split(" ", 3);
if(split.length != 3) return;
if (split.length != 3) return;
String recipient = split[1];
String raw = split[2];
Player p = Bukkit.getPlayer(recipient);
if(p == null)return;
if (p == null) return;
MentionListener.notify(e.getPlayer(), raw, Collections.singleton(p), plugin);
r.put(e.getPlayer().getUniqueId(), p.getUniqueId());
r.get(p.getUniqueId(), e.getPlayer()::getUniqueId);
}

if(Stream.of("/r ", "/reply ").parallel().anyMatch(cmd::startsWith) && ess.getSettings().isLastMessageReplyRecipient() && r.getIfPresent(e.getPlayer().getUniqueId()) != null){
if (Stream.of("/r ", "/reply ").parallel().anyMatch(cmd::startsWith) && allowMentionReply && r.getIfPresent(e.getPlayer().getUniqueId()) != null) {
r.put(e.getPlayer().getUniqueId(), r.getIfPresent(e.getPlayer().getUniqueId()));
String[] split = cmd.split(" ", 2);
if(split.length != 2) return;
if (split.length != 2) return;
Player p = Bukkit.getPlayer(r.getIfPresent(e.getPlayer().getUniqueId()));
if(p == null)return;
if (p == null) return;
MentionListener.notify(e.getPlayer(), null, Collections.singleton(p), plugin);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: NyaaUtils
main: cat.nyaa.nyaautils.NyaaUtils
description: "Helper/utilities plugin for Nyaacat Minecraft Server"
version: 4.0-dev
depend: [WorldEdit,Essentials,NyaaCore]
depend: [WorldEdit,Essentials,NyaaCore,LangUtils]
softdepend: [LockettePro,HamsterEcoHelper]
authors: [RecursiveG,Cylin,Librazy]
website: "https://github.com/NyaaCat/nyaautils"
Expand Down

0 comments on commit 9dc9144

Please sign in to comment.