mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
chat reactions
This commit is contained in:
parent
af935cb824
commit
cbc1d997ec
@ -1,10 +1,14 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
import java.util.Date;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopData;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
@ -59,6 +63,22 @@ public class ChatManager extends FreedomService
|
||||
message = FUtil.colorize(message);
|
||||
message = message.replaceAll(ChatColor.MAGIC.toString(), "&k");
|
||||
|
||||
if (ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean() && !plugin.sh.reactionString.isEmpty() && message.equals(plugin.sh.reactionString))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
ShopData data = plugin.sh.getData(player);
|
||||
data.setCoins(data.getCoins() + plugin.sh.coinsPerReactionWin);
|
||||
plugin.sh.save(data);
|
||||
plugin.sh.reactionString = "";
|
||||
Date currentTime = new Date();
|
||||
long seconds = (currentTime.getTime() - plugin.sh.reactionStartTime.getTime()) / 1000;
|
||||
String reactionMessage = ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "Reaction" + ChatColor.DARK_GRAY + "] "
|
||||
+ ChatColor.GREEN + player.getName() + ChatColor.AQUA + " won in " + seconds + " seconds!";
|
||||
FUtil.bcastMsg(reactionMessage, false);
|
||||
player.sendMessage(ChatColor.GREEN + "You have been given " + ChatColor.GOLD + plugin.sh.coinsPerReactionWin + ChatColor.GREEN + " coins!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ConfigEntry.TOGGLE_CHAT.getBoolean() && !plugin.al.isAdmin(player))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
@ -201,8 +201,8 @@ public class LoginProcess extends FreedomService
|
||||
|
||||
if (TELEPORT_ON_JOIN.contains(player.getName()))
|
||||
{
|
||||
int x = FUtil.random(-10000, 10000);
|
||||
int z = FUtil.random(-10000, 10000);
|
||||
int x = FUtil.randomInteger(-10000, 10000);
|
||||
int z = FUtil.randomInteger(-10000, 10000);
|
||||
int y = player.getWorld().getHighestBlockYAt(x, z);
|
||||
Location location = new Location(player.getLocation().getWorld(), x, y, z);
|
||||
player.teleport(location);
|
||||
|
@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopData;
|
||||
import me.totalfreedom.totalfreedommod.shop.ShopItem;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -16,6 +17,12 @@ public class Command_manageshop extends FreedomCommand
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
|
||||
if (!FUtil.isExecutive(sender.getName()))
|
||||
{
|
||||
return noPerms();
|
||||
}
|
||||
|
||||
if (args.length < 2)
|
||||
{
|
||||
return false;
|
||||
|
@ -15,8 +15,8 @@ public class Command_tprandom extends FreedomCommand
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
int x = FUtil.random(-10000, 10000);
|
||||
int z = FUtil.random(-10000, 10000);
|
||||
int x = FUtil.randomInteger(-10000, 10000);
|
||||
int z = FUtil.randomInteger(-10000, 10000);
|
||||
int y = playerSender.getWorld().getHighestBlockYAt(x, z);
|
||||
Location location = new Location(playerSender.getLocation().getWorld(), x, y, z);
|
||||
playerSender.teleport(location);
|
||||
|
@ -84,6 +84,10 @@ public enum ConfigEntry
|
||||
SHOP_TITLE(String.class, "shop.title"),
|
||||
SHOP_PREFIX(String.class, "shop.prefix"),
|
||||
SHOP_COINS_PER_VOTE(Integer.class, "shop.coins_per_vote"),
|
||||
SHOP_REACTIONS_ENABLED(Boolean.class, "shop.reactions.enabled"),
|
||||
SHOP_REACTIONS_INTERVAL(Integer.class, "shop.reactions.interval"),
|
||||
SHOP_REACTIONS_COINS_PER_WIN(Integer.class, "shop.reactions.coins_per_win"),
|
||||
SHOP_REACTIONS_STRING_LENGTH(Integer.class, "shop.reactions.string_length"),
|
||||
SHOP_PRICES_GRAPPLING_HOOK(Integer.class, "shop.prices.grappling_hook"),
|
||||
SHOP_PRICES_LIGHTNING_ROD(Integer.class, "shop.prices.lightning_rod"),
|
||||
SHOP_PRICES_FIRE_BALL(Integer.class, "shop.prices.fire_ball"),
|
||||
|
@ -7,6 +7,8 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -29,6 +31,8 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class Shop extends FreedomService
|
||||
{
|
||||
@ -36,6 +40,10 @@ public class Shop extends FreedomService
|
||||
public final Map<UUID, ShopData> dataMap = Maps.newHashMap(); // uuid, dataMap
|
||||
@Getter
|
||||
private final File configFolder;
|
||||
private BukkitTask reactions;
|
||||
public String reactionString = "";
|
||||
public Date reactionStartTime;
|
||||
public final int coinsPerReactionWin = ConfigEntry.SHOP_REACTIONS_COINS_PER_WIN.getInteger();
|
||||
|
||||
public Shop(TotalFreedomMod plugin)
|
||||
{
|
||||
@ -48,6 +56,25 @@ public class Shop extends FreedomService
|
||||
protected void onStart()
|
||||
{
|
||||
dataMap.clear();
|
||||
if (ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean())
|
||||
{
|
||||
long interval = ConfigEntry.SHOP_REACTIONS_INTERVAL.getInteger() * 20L;
|
||||
|
||||
reactions = new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
reactionString = FUtil.randomString(ConfigEntry.SHOP_REACTIONS_STRING_LENGTH.getInteger());
|
||||
String reactionMessage = ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "Reaction" + ChatColor.DARK_GRAY + "] "
|
||||
+ ChatColor.AQUA + "Type the string " + ChatColor.DARK_AQUA + reactionString
|
||||
+ ChatColor.AQUA + " to win " + ChatColor.GOLD + plugin.sh.coinsPerReactionWin + ChatColor.AQUA + " coins!";
|
||||
FUtil.bcastMsg(reactionMessage, false);
|
||||
reactionStartTime = new Date();
|
||||
}
|
||||
}.runTaskTimer(plugin, interval, interval);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,6 +84,11 @@ public class Shop extends FreedomService
|
||||
{
|
||||
save(sd);
|
||||
}
|
||||
|
||||
if (ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean())
|
||||
{
|
||||
reactions.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public void save(ShopData data)
|
||||
|
@ -211,8 +211,16 @@ public class FUtil
|
||||
}
|
||||
|
||||
public static void bcastMsg(String message, ChatColor color)
|
||||
{
|
||||
bcastMsg(message, color, true);
|
||||
}
|
||||
|
||||
public static void bcastMsg(String message, ChatColor color, Boolean toConsole)
|
||||
{
|
||||
if (toConsole)
|
||||
{
|
||||
FLog.info(message, true);
|
||||
}
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
@ -220,9 +228,14 @@ public class FUtil
|
||||
}
|
||||
}
|
||||
|
||||
public static void bcastMsg(String message, Boolean toConsole)
|
||||
{
|
||||
bcastMsg(message, null, toConsole);
|
||||
}
|
||||
|
||||
public static void bcastMsg(String message)
|
||||
{
|
||||
FUtil.bcastMsg(message, null);
|
||||
FUtil.bcastMsg(message, null, true);
|
||||
}
|
||||
|
||||
// Still in use by listeners
|
||||
@ -549,13 +562,29 @@ public class FUtil
|
||||
return packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
public static int random(int min, int max)
|
||||
public static int randomInteger(int min, int max)
|
||||
{
|
||||
int range = max - min + 1;
|
||||
int value = (int)(Math.random() * range) + min;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String randomString(int length)
|
||||
{
|
||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz0123456789";
|
||||
String randomString = "";
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
int selectedCharacter = randomInteger(1, characters.length()) - 1;
|
||||
|
||||
randomString += characters.charAt(selectedCharacter);
|
||||
}
|
||||
|
||||
return randomString;
|
||||
|
||||
}
|
||||
|
||||
public static boolean isPaper()
|
||||
{
|
||||
try
|
||||
@ -606,7 +635,7 @@ public class FUtil
|
||||
public static Player getRandomPlayer()
|
||||
{
|
||||
List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
|
||||
return players.get(random(0, players.size() - 1));
|
||||
return players.get(randomInteger(0, players.size() - 1));
|
||||
}
|
||||
|
||||
// convert the current time
|
||||
|
@ -67,7 +67,7 @@ discord:
|
||||
chat_channel_id: ''
|
||||
# Do you want roles to sync with the server?
|
||||
role_sync: false
|
||||
# Master Admin role ID
|
||||
# Master Builder role ID
|
||||
master_builder_role_id: ''
|
||||
# Super Admin role ID
|
||||
super_role_id: ''
|
||||
@ -98,6 +98,21 @@ shop:
|
||||
# How many coins to voters get per vote?
|
||||
coins_per_vote: 20
|
||||
|
||||
# Chat reactions
|
||||
reactions:
|
||||
|
||||
# Enable chat reactions?
|
||||
enabled: true
|
||||
|
||||
# How much time (in seconds) before a new reaction prompt is made
|
||||
interval: 300
|
||||
|
||||
# How many coins do winners get?
|
||||
coins_per_win: 5
|
||||
|
||||
# How long is the random string (in characters)?
|
||||
string_length: 10
|
||||
|
||||
# Item prices
|
||||
prices:
|
||||
grappling_hook: 100
|
||||
|
Loading…
Reference in New Issue
Block a user