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: yeehaw:
description: This command makes you yeehaw. description: This command makes you yeehaw.
author: NorbiPeti author: NorbiPeti
depend: [Essentials, Towny, Minigames, Votifier, WorldGuard, WorldEdit, ProtocolLib, FastLogin, Vault, AuthMe] depend: [Essentials, Towny, Minigames, Votifier, WorldGuard, WorldEdit, ProtocolLib, Vault]
permissions: permissions:
tbmc.admin: tbmc.admin:
description: Gives access to /un- commands and /u admin commands 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.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet;
import java.util.function.Predicate;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -72,8 +74,7 @@ public class ChatProcessing {
colormode = ChatFormatter.Color.Green; colormode = ChatFormatter.Color.Green;
// If greentext, ignore channel or player colors // If greentext, ignore channel or player colors
formatters.add(new ChatFormatter(Pattern.compile(".+"), colormode, formatters.add(new ChatFormatter(Pattern.compile(".+"), colormode, ""));
""));
String formattedmessage = message; String formattedmessage = message;
formattedmessage = formattedmessage.replace("\\", "\\\\"); formattedmessage = formattedmessage.replace("\\", "\\\\");
@ -98,17 +99,45 @@ public class ChatProcessing {
formatters.add(new ChatFormatter(Pattern formatters.add(new ChatFormatter(Pattern
.compile("http[\\w:/?=$\\-_.+!*'(),]+"), .compile("http[\\w:/?=$\\-_.+!*'(),]+"),
ChatFormatter.Format.Underlined, "", true)); ChatFormatter.Format.Underlined, "", true));
//TODO: Only format name mentions outisde open_url // TODO: Only format name mentions outisde open_url
/*formattedmessage = formattedmessage /*
.replace( * formattedmessage = formattedmessage .replace( item, String.format(
item, * "\",\"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\":\""
String.format( * , colormode, url, colormode, url));
"\",\"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) { if (!hadurls) {
for (Player p : PluginMain.GetPlayers()) { 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).*" if (formattedmessage.matches("(?i).*"
+ Pattern.quote(p.getName()) + ".*")) { + Pattern.quote(p.getName()) + ".*")) {
if (PlayerListener.NotificationSound == null) if (PlayerListener.NotificationSound == null)

View file

@ -45,8 +45,6 @@ import au.com.mineauz.minigames.MinigamePlayer;
import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.Minigames;
import com.earth2me.essentials.Essentials; 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.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town; 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.Vote;
import com.vexsoftware.votifier.model.VotifierEvent; import com.vexsoftware.votifier.model.VotifierEvent;
import fr.xephi.authme.AuthMe;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
public static HashMap<String, UUID> nicknames = new HashMap<>(); public static HashMap<String, UUID> nicknames = new HashMap<>();
@ -96,13 +92,17 @@ public class PlayerListener implements Listener {
if (player == null) if (player == null)
return; return;
PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit /*
.getPlugin(FastLoginBukkit.class)).getStorage() * PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit
.getProfile(player.getName(), true); * .getPlugin(FastLoginBukkit.class)).getStorage()
boolean ispremium = pp != null && pp.isPremium(); * .getProfile(player.getName(), true); boolean ispremium =
* pp != null && pp.isPremium();
*/// Login stuff
if (ispremium if (/*
&& mp.FlairState.equals(FlairStates.NoComment)) { * ispremium &&
*/// Login stuff
mp.FlairState.equals(FlairStates.NoComment)) {
String json = String 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\"}]}}}]", .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); PluginMain.FlairThreadURL);
@ -121,63 +121,41 @@ public class PlayerListener implements Listener {
timer.schedule(tt, 15 * 1000); timer.schedule(tt, 15 * 1000);
} }
final Timer timer = new Timer(); /*
mp.LoginWarningCount = 0; * final Timer timer = new Timer(); mp.LoginWarningCount = 0;
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() { * PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
@Override *
public void run() { * @Override public void run() { final Player player =
final Player player = Bukkit.getPlayer(mp.PlayerName); * Bukkit.getPlayer(mp.PlayerName); if (player == null) return;
if (player == null) *
return; * PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit
* .getPlugin(FastLoginBukkit.class)).getStorage()
PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit * .getProfile(player.getName(), true); boolean ispremium = pp != null
.getPlugin(FastLoginBukkit.class)).getStorage() * && pp.isPremium(); final MaybeOfflinePlayer mplayer = mp;
.getProfile(player.getName(), true); *
boolean ispremium = pp != null && pp.isPremium(); * if (mp.LoginWarningCount < LoginWarningCountTotal) { if
final MaybeOfflinePlayer mplayer = mp; * (AuthMe.getInstance().api.isAuthenticated(player)) { // The player
* logged in in any way if (!ispremium &&
if (mp.LoginWarningCount < LoginWarningCountTotal) { * !mp.FlairState.equals(FlairStates.Accepted) &&
if (AuthMe.getInstance().api.isAuthenticated(player)) { * !mp.FlairState.equals(FlairStates.Commented)) { // The player isn't
// The player logged in in any way * premium, and doesn't have a // flair String json = String .format(
if (!ispremium * "[\"\",{\"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\"}]}}}]"
&& !mp.FlairState.equals(FlairStates.Accepted) * , PluginMain.FlairThreadURL);
&& !mp.FlairState.equals(FlairStates.Commented)) { * PluginMain.Instance.getServer().dispatchCommand( PluginMain.Console,
// The player isn't premium, and doesn't have a * "tellraw " + mp.PlayerName + " " + json); } } } else { if
// flair * (AuthMe.getInstance().api.isAuthenticated(player)) { if (!ispremium
String json = String * && !mplayer.FlairState .equals(FlairStates.Accepted) &&
.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\"}]}}}]", * !mplayer.FlairState .equals(FlairStates.Commented)) {
PluginMain.FlairThreadURL); * Bukkit.getScheduler().runTask(PluginMain.Instance, new Runnable() {
PluginMain.Instance.getServer().dispatchCommand( *
PluginMain.Console, * @Override public void run() { player.kickPlayer(
"tellraw " + mp.PlayerName + " " + json); * "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()
} else { * .getInt("settings.restrictions.timeout"); timer.schedule(tt, (timeout
if (AuthMe.getInstance().api.isAuthenticated(player)) { * / LoginWarningCountTotal) * 1000, (timeout / LoginWarningCountTotal)
if (!ispremium * * 1000);
&& !mplayer.FlairState */// Login stuff
.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);
/* NICKNAME LOGIC */ /* NICKNAME LOGIC */
@ -355,17 +333,14 @@ public class PlayerListener implements Listener {
.getPlayer().getDisplayName(), message)); .getPlayer().getDisplayName(), message));
} }
} }
/*boolean tping = false; /*
boolean tphering = false; * boolean tping = false; boolean tphering = false; if
if (cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("call") * (cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("call") ||
|| cmd.equalsIgnoreCase("ecall") * cmd.equalsIgnoreCase("ecall") || cmd.equalsIgnoreCase("etpa") ||
|| cmd.equalsIgnoreCase("etpa") * cmd.equalsIgnoreCase("tpask") || cmd.equalsIgnoreCase("etpask"))
|| cmd.equalsIgnoreCase("tpask") * tping = true; if (cmd.equalsIgnoreCase("tpahere") ||
|| cmd.equalsIgnoreCase("etpask")) * cmd.equalsIgnoreCase("etpahere")) tphering = true;
tping = true; */
if (cmd.equalsIgnoreCase("tpahere")
|| cmd.equalsIgnoreCase("etpahere"))
tphering = true;*/
/* /*
* for (HelpTopic ht : PluginMain.Instance.getServer() * for (HelpTopic ht : PluginMain.Instance.getServer()
@ -381,37 +356,30 @@ public class PlayerListener implements Listener {
* break; } * break; }
*/ */
/*if (tphering) { /*
Player target = Bukkit.getPlayer(event.getMessage() * if (tphering) { Player target =
.substring(index + 1).split(" ")[0]); * Bukkit.getPlayer(event.getMessage() .substring(index +
if (target != null * 1).split(" ")[0]); if (target != null && BoardColl.get()
&& BoardColl.get() * .getFactionAt(PS.valueOf(target.getLocation()))
.getFactionAt(PS.valueOf(target.getLocation())) * .getId().equalsIgnoreCase("tower")) { event.getPlayer()
.getId().equalsIgnoreCase("tower")) { * .sendMessage(
event.getPlayer() * "§cYou are not allowed to teleport players out from the Tower");
.sendMessage( * event.setCancelled(true); } }
"§cYou are not allowed to teleport players out from the Tower"); */
event.setCancelled(true);
}
}*/
/* /*
* for (String s : Bukkit.getCommandAliases().get("/tpahere")) { if * for (String s : Bukkit.getCommandAliases().get("/tpahere")) { if
* (cmd.equalsIgnoreCase(s)) { tping = true; break; } } * (cmd.equalsIgnoreCase(s)) { tping = true; break; } }
*/ */
/*if (tping) { /*
if ( * if (tping) { if ( //
// MPlayer.get(event.getPlayer()).getFaction().getId().equalsIgnoreCase("nomansland")) * MPlayer.get(event.getPlayer()).getFaction().getId
// { * ().equalsIgnoreCase("nomansland")) // { BoardColl .get()
BoardColl * .getFactionAt( PS.valueOf(event.getPlayer().getLocation()))
.get() * .getId().equalsIgnoreCase("tower")) {
.getFactionAt( * event.getPlayer().sendMessage(
PS.valueOf(event.getPlayer().getLocation())) * "§cYou are not allowed to teleport to the Tower");
.getId().equalsIgnoreCase("tower")) { * event.setCancelled(true); } }
event.getPlayer().sendMessage( */
"§cYou are not allowed to teleport to the Tower");
event.setCancelled(true);
}
}*/
} }
if (cmd.equalsIgnoreCase("sethome")) { if (cmd.equalsIgnoreCase("sethome")) {
TownyUniverse tu = PluginMain.Instance.TU; TownyUniverse tu = PluginMain.Instance.TU;

View file

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