This commit is contained in:
Norbi Peti 2016-06-27 19:56:12 +02:00
parent c6ffdf1868
commit 4ca1c6a2d7
4 changed files with 117 additions and 119 deletions

View file

@ -24,7 +24,7 @@ commands:
yeehaw:
description: This command makes you yeehaw.
author: NorbiPeti
depend: [Essentials, Towny, Minigames, Votifier, WorldGuard, WorldEdit, ProtocolLib, FastLogin, Vault, AuthMe]
depend: [Essentials, Towny, Minigames, Votifier, WorldGuard, WorldEdit, ProtocolLib, Vault]
permissions:
tbmc.admin:
description: Gives access to /un- commands and /u admin commands

View file

@ -5,6 +5,8 @@ import io.github.norbipeti.thebuttonmcchat.commands.UnlolCommand;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
@ -72,8 +74,7 @@ public class ChatProcessing {
colormode = ChatFormatter.Color.Green;
// If greentext, ignore channel or player colors
formatters.add(new ChatFormatter(Pattern.compile(".+"), colormode,
""));
formatters.add(new ChatFormatter(Pattern.compile(".+"), colormode, ""));
String formattedmessage = message;
formattedmessage = formattedmessage.replace("\\", "\\\\");
@ -98,17 +99,45 @@ public class ChatProcessing {
formatters.add(new ChatFormatter(Pattern
.compile("http[\\w:/?=$\\-_.+!*'(),]+"),
ChatFormatter.Format.Underlined, "", true));
//TODO: Only format name mentions outisde open_url
/*formattedmessage = formattedmessage
.replace(
item,
String.format(
"\",\"color\":\"%s\"},{\"text\":\"%s\",\"color\":\"%s\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open URL\",\"color\":\"blue\"}]}}},{\"text\":\"",
colormode, url, colormode, url));*/
// TODO: Only format name mentions outisde open_url
/*
* formattedmessage = formattedmessage .replace( item, String.format(
* "\",\"color\":\"%s\"},{\"text\":\"%s\",\"color\":\"%s\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open URL\",\"color\":\"blue\"}]}}},{\"text\":\""
* , colormode, url, colormode, url));
*/
StringBuilder sb = new StringBuilder();
sb.append("(");
for (Player p : PluginMain.GetPlayers())
sb.append(p.getName()).append("|");
sb.deleteCharAt(sb.length() - 1);
sb.append(")");
formatters.add(new ChatFormatter(Pattern.compile(sb.toString()),
ChatFormatter.Color.Aqua, "", (String match) -> {
Player p = Bukkit.getPlayer(match);
if (p == null) {
System.out.println("Error: Can't find player " + match
+ " but it was reported as online.");
}
MaybeOfflinePlayer mpp = MaybeOfflinePlayer
.AddPlayerIfNeeded(p.getUniqueId());
if (PlayerListener.NotificationSound == null)
p.playSound(p.getLocation(),
Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO:
// Airhorn
else
p.playSound(p.getLocation(), PlayerListener.NotificationSound,
1.0f, (float) PlayerListener.NotificationPitch);
color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb
: mpp.GetFlairColor()));
return true;
}));
if (!hadurls) {
for (Player p : PluginMain.GetPlayers()) {
String color = ""; //TODO: Regex with all names and check for the correct JSON behind them
String color = ""; // TODO: Regex with all names and check for
// the correct JSON behind them
if (formattedmessage.matches("(?i).*"
+ Pattern.quote(p.getName()) + ".*")) {
if (PlayerListener.NotificationSound == null)

View file

@ -45,8 +45,6 @@ import au.com.mineauz.minigames.MinigamePlayer;
import au.com.mineauz.minigames.Minigames;
import com.earth2me.essentials.Essentials;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.PlayerProfile;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
@ -57,8 +55,6 @@ import com.palmergames.bukkit.towny.object.WorldCoord;
import com.vexsoftware.votifier.model.Vote;
import com.vexsoftware.votifier.model.VotifierEvent;
import fr.xephi.authme.AuthMe;
public class PlayerListener implements Listener {
public static HashMap<String, UUID> nicknames = new HashMap<>();
@ -96,13 +92,17 @@ public class PlayerListener implements Listener {
if (player == null)
return;
PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit
.getPlugin(FastLoginBukkit.class)).getStorage()
.getProfile(player.getName(), true);
boolean ispremium = pp != null && pp.isPremium();
/*
* PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit
* .getPlugin(FastLoginBukkit.class)).getStorage()
* .getProfile(player.getName(), true); boolean ispremium =
* pp != null && pp.isPremium();
*/// Login stuff
if (ispremium
&& mp.FlairState.equals(FlairStates.NoComment)) {
if (/*
* ispremium &&
*/// Login stuff
mp.FlairState.equals(FlairStates.NoComment)) {
String json = String
.format("[\"\",{\"text\":\"If you're from Reddit and you'd like your /r/TheButton flair displayed ingame, write your Minecraft name to \",\"color\":\"aqua\"},{\"text\":\"[this thread].\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]",
PluginMain.FlairThreadURL);
@ -121,63 +121,41 @@ public class PlayerListener implements Listener {
timer.schedule(tt, 15 * 1000);
}
final Timer timer = new Timer();
mp.LoginWarningCount = 0;
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
@Override
public void run() {
final Player player = Bukkit.getPlayer(mp.PlayerName);
if (player == null)
return;
PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit
.getPlugin(FastLoginBukkit.class)).getStorage()
.getProfile(player.getName(), true);
boolean ispremium = pp != null && pp.isPremium();
final MaybeOfflinePlayer mplayer = mp;
if (mp.LoginWarningCount < LoginWarningCountTotal) {
if (AuthMe.getInstance().api.isAuthenticated(player)) {
// The player logged in in any way
if (!ispremium
&& !mp.FlairState.equals(FlairStates.Accepted)
&& !mp.FlairState.equals(FlairStates.Commented)) {
// The player isn't premium, and doesn't have a
// flair
String json = String
.format("[\"\",{\"text\":\"Welcome! If you are a premium Minecraft user, please do /premium and relog, otherwise please verify your /r/thebutton flair to play, \",\"color\":\"gold\"},{\"text\":\"[here].\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]",
PluginMain.FlairThreadURL);
PluginMain.Instance.getServer().dispatchCommand(
PluginMain.Console,
"tellraw " + mp.PlayerName + " " + json);
}
}
} else {
if (AuthMe.getInstance().api.isAuthenticated(player)) {
if (!ispremium
&& !mplayer.FlairState
.equals(FlairStates.Accepted)
&& !mplayer.FlairState
.equals(FlairStates.Commented)) {
Bukkit.getScheduler().runTask(PluginMain.Instance,
new Runnable() {
@Override
public void run() {
player.kickPlayer("Please either use /premium and relog or verify your flair by commenting in the thread and using /u accept.");
}
});
timer.cancel();
}
}
}
mp.LoginWarningCount++;
}
};
tt.mp = mp;
int timeout = AuthMe.getInstance().getConfig()
.getInt("settings.restrictions.timeout");
timer.schedule(tt, (timeout / LoginWarningCountTotal) * 1000,
(timeout / LoginWarningCountTotal) * 1000);
/*
* final Timer timer = new Timer(); mp.LoginWarningCount = 0;
* PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
*
* @Override public void run() { final Player player =
* Bukkit.getPlayer(mp.PlayerName); if (player == null) return;
*
* PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit
* .getPlugin(FastLoginBukkit.class)).getStorage()
* .getProfile(player.getName(), true); boolean ispremium = pp != null
* && pp.isPremium(); final MaybeOfflinePlayer mplayer = mp;
*
* if (mp.LoginWarningCount < LoginWarningCountTotal) { if
* (AuthMe.getInstance().api.isAuthenticated(player)) { // The player
* logged in in any way if (!ispremium &&
* !mp.FlairState.equals(FlairStates.Accepted) &&
* !mp.FlairState.equals(FlairStates.Commented)) { // The player isn't
* premium, and doesn't have a // flair String json = String .format(
* "[\"\",{\"text\":\"Welcome! If you are a premium Minecraft user, please do /premium and relog, otherwise please verify your /r/thebutton flair to play, \",\"color\":\"gold\"},{\"text\":\"[here].\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]"
* , PluginMain.FlairThreadURL);
* PluginMain.Instance.getServer().dispatchCommand( PluginMain.Console,
* "tellraw " + mp.PlayerName + " " + json); } } } else { if
* (AuthMe.getInstance().api.isAuthenticated(player)) { if (!ispremium
* && !mplayer.FlairState .equals(FlairStates.Accepted) &&
* !mplayer.FlairState .equals(FlairStates.Commented)) {
* Bukkit.getScheduler().runTask(PluginMain.Instance, new Runnable() {
*
* @Override public void run() { player.kickPlayer(
* "Please either use /premium and relog or verify your flair by commenting in the thread and using /u accept."
* ); } }); timer.cancel(); } } } mp.LoginWarningCount++; } }; tt.mp =
* mp; int timeout = AuthMe.getInstance().getConfig()
* .getInt("settings.restrictions.timeout"); timer.schedule(tt, (timeout
* / LoginWarningCountTotal) * 1000, (timeout / LoginWarningCountTotal)
* * 1000);
*/// Login stuff
/* NICKNAME LOGIC */
@ -355,17 +333,14 @@ public class PlayerListener implements Listener {
.getPlayer().getDisplayName(), message));
}
}
/*boolean tping = false;
boolean tphering = false;
if (cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("call")
|| cmd.equalsIgnoreCase("ecall")
|| cmd.equalsIgnoreCase("etpa")
|| cmd.equalsIgnoreCase("tpask")
|| cmd.equalsIgnoreCase("etpask"))
tping = true;
if (cmd.equalsIgnoreCase("tpahere")
|| cmd.equalsIgnoreCase("etpahere"))
tphering = true;*/
/*
* boolean tping = false; boolean tphering = false; if
* (cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("call") ||
* cmd.equalsIgnoreCase("ecall") || cmd.equalsIgnoreCase("etpa") ||
* cmd.equalsIgnoreCase("tpask") || cmd.equalsIgnoreCase("etpask"))
* tping = true; if (cmd.equalsIgnoreCase("tpahere") ||
* cmd.equalsIgnoreCase("etpahere")) tphering = true;
*/
/*
* for (HelpTopic ht : PluginMain.Instance.getServer()
@ -381,37 +356,30 @@ public class PlayerListener implements Listener {
* break; }
*/
/*if (tphering) {
Player target = Bukkit.getPlayer(event.getMessage()
.substring(index + 1).split(" ")[0]);
if (target != null
&& BoardColl.get()
.getFactionAt(PS.valueOf(target.getLocation()))
.getId().equalsIgnoreCase("tower")) {
event.getPlayer()
.sendMessage(
"§cYou are not allowed to teleport players out from the Tower");
event.setCancelled(true);
}
}*/
/*
* if (tphering) { Player target =
* Bukkit.getPlayer(event.getMessage() .substring(index +
* 1).split(" ")[0]); if (target != null && BoardColl.get()
* .getFactionAt(PS.valueOf(target.getLocation()))
* .getId().equalsIgnoreCase("tower")) { event.getPlayer()
* .sendMessage(
* "§cYou are not allowed to teleport players out from the Tower");
* event.setCancelled(true); } }
*/
/*
* for (String s : Bukkit.getCommandAliases().get("/tpahere")) { if
* (cmd.equalsIgnoreCase(s)) { tping = true; break; } }
*/
/*if (tping) {
if (
// MPlayer.get(event.getPlayer()).getFaction().getId().equalsIgnoreCase("nomansland"))
// {
BoardColl
.get()
.getFactionAt(
PS.valueOf(event.getPlayer().getLocation()))
.getId().equalsIgnoreCase("tower")) {
event.getPlayer().sendMessage(
"§cYou are not allowed to teleport to the Tower");
event.setCancelled(true);
}
}*/
/*
* if (tping) { if ( //
* MPlayer.get(event.getPlayer()).getFaction().getId
* ().equalsIgnoreCase("nomansland")) // { BoardColl .get()
* .getFactionAt( PS.valueOf(event.getPlayer().getLocation()))
* .getId().equalsIgnoreCase("tower")) {
* event.getPlayer().sendMessage(
* "§cYou are not allowed to teleport to the Tower");
* event.setCancelled(true); } }
*/
}
if (cmd.equalsIgnoreCase("sethome")) {
TownyUniverse tu = PluginMain.Instance.TU;

View file

@ -1,6 +1,7 @@
package io.github.norbipeti.thebuttonmcchat.commands.ucmds;
import io.github.norbipeti.thebuttonmcchat.ChatFormatter;
import io.github.norbipeti.thebuttonmcchat.ChatFormatter.Color;
import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer;
import io.github.norbipeti.thebuttonmcchat.PluginMain;
@ -24,7 +25,7 @@ public class CCommand extends UCommandBase {
if (args.length < 1) {
if (PluginMain.permission.has(player, "tbmc.rainbow")) {
p.RainbowPresserColorMode = !p.RainbowPresserColorMode;
p.OtherColorMode = "";
p.OtherColorMode = null;
if (p.RainbowPresserColorMode)
player.sendMessage("§eRainbow colors §aenabled.");
else
@ -36,7 +37,7 @@ public class CCommand extends UCommandBase {
} else {
if (PluginMain.permission.has(player, "tbmc.admin")) {
p.RainbowPresserColorMode = false;
p.OtherColorMode = args[0];
p.OtherColorMode = null;
try {
p.OtherColorMode = ChatFormatter.Color.valueOf(args[0]
.toLowerCase());
@ -44,7 +45,7 @@ public class CCommand extends UCommandBase {
player.sendMessage("§cUnknown message color: " + args[0]);
player.sendMessage("§cUse color names, like blue, or dark_aqua");
}
if (p.OtherColorMode.length() > 0)
if (p.OtherColorMode != null)
player.sendMessage(String.format(
"§eMessage color set to %s", p.OtherColorMode));
else