mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-23 03:34:57 +00:00
Merge branch 'main' of https://github.com/TheDeus-Group/TFM-4.3-Reloaded
This commit is contained in:
commit
8e4f0381e2
5 changed files with 142 additions and 7 deletions
|
@ -24,6 +24,9 @@ import me.StevenLawson.TotalFreedomMod.world.FlatlandsWorld;
|
|||
import me.StevenLawson.TotalFreedomMod.world.ProtectedArea;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
@ -31,6 +34,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -45,6 +49,7 @@ public class TotalFreedomMod extends JavaPlugin {
|
|||
public static final String CONFIG_FILENAME = "config.yml";
|
||||
public static final String SUPERADMIN_FILENAME = "superadmin.yml";
|
||||
public static final String PERMBAN_FILENAME = "permban.yml";
|
||||
public static final String PLAYERTAGS_FILENAME = "playerTags.yml";
|
||||
public static final String UUID_FILENAME = "uuids.db";
|
||||
public static final String PROTECTED_AREA_FILENAME = "protectedareas.dat";
|
||||
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
||||
|
@ -65,6 +70,7 @@ public class TotalFreedomMod extends JavaPlugin {
|
|||
public static Map<Player, Double> fuckoffEnabledFor = new HashMap<>();
|
||||
public static Logger logger;
|
||||
|
||||
private FileConfiguration customConfig; // Custom configuration implementation by Eva
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
|
@ -103,7 +109,8 @@ public class TotalFreedomMod extends JavaPlugin {
|
|||
Utilities.createBackups(CONFIG_FILENAME, true);
|
||||
Utilities.createBackups(SUPERADMIN_FILENAME);
|
||||
Utilities.createBackups(PERMBAN_FILENAME);
|
||||
|
||||
Utilities.createBackups(PLAYERTAGS_FILENAME);
|
||||
this.createCustomConfig();
|
||||
// Load services
|
||||
UUIDManager.load();
|
||||
AdminList.load();
|
||||
|
@ -219,6 +226,25 @@ public class TotalFreedomMod extends JavaPlugin {
|
|||
return CommandHandler.handleCommand(sender, cmd, commandLabel, args);
|
||||
}
|
||||
|
||||
public FileConfiguration getCustomConfig() {
|
||||
return this.customConfig;
|
||||
}
|
||||
//CustomConfig implementation by Eva
|
||||
private void createCustomConfig() {
|
||||
File customConfigFile = new File(getDataFolder(), "playerTags.yml");
|
||||
if (!customConfigFile.exists()) {
|
||||
customConfigFile.getParentFile().mkdirs();
|
||||
saveResource("playerTags.yml", false);
|
||||
}
|
||||
|
||||
customConfig= new YamlConfiguration();
|
||||
try {
|
||||
customConfig.load(customConfigFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void setAppProperties()
|
||||
{
|
||||
try
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package me.StevenLawson.TotalFreedomMod.commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
||||
import me.StevenLawson.TotalFreedomMod.config.TagConfiguration;
|
||||
import me.StevenLawson.TotalFreedomMod.player.PlayerData;
|
||||
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -8,12 +9,17 @@ import org.bukkit.ChatColor;
|
|||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import javax.swing.text.html.HTML;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Sets yourself a prefix", usage = "/<command> <set <tag..> | off | clear <player> | clearall>")
|
||||
@CommandParameters(description = "Sets yourself a prefix", usage = "/<command> <(-s) set <tag..> | off | clear <player> | clearall>")
|
||||
public class Command_tag extends FreedomCommand {
|
||||
public static final List<String> FORBIDDEN_WORDS = Arrays.asList("admin", "owner", "moderator", "developer", "console");
|
||||
|
||||
|
@ -50,6 +56,12 @@ public class Command_tag extends FreedomCommand {
|
|||
if (playerdata.getTag() != null)
|
||||
{
|
||||
count++;
|
||||
if(TagConfiguration.getTag(playerdata.getUniqueId().toString()) != null){
|
||||
String playerTag = TagConfiguration.getTag(playerdata.getUniqueId().toString());
|
||||
if(!"".equalsIgnoreCase(playerTag)){
|
||||
TagConfiguration.saveTag(sender_p.getUniqueId().toString(), "");
|
||||
}
|
||||
}
|
||||
playerdata.setTag(null);
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +79,12 @@ public class Command_tag extends FreedomCommand {
|
|||
else
|
||||
{
|
||||
PlayerData.getPlayerData(sender_p).setTag(null);
|
||||
if(TagConfiguration.getTag(sender_p.getUniqueId().toString()) != null){
|
||||
String playerTag = TagConfiguration.getTag(sender_p.getUniqueId().toString());
|
||||
if(!"".equalsIgnoreCase(playerTag)){
|
||||
TagConfiguration.saveTag(sender_p.getUniqueId().toString(), "");
|
||||
}
|
||||
}
|
||||
playerMsg("Your tag has been removed.");
|
||||
}
|
||||
|
||||
|
@ -88,14 +106,18 @@ public class Command_tag extends FreedomCommand {
|
|||
}
|
||||
|
||||
final Player player = getPlayer(args[1]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
playerMsg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerData.getPlayerData(player).setTag(null);
|
||||
if(TagConfiguration.getTag(player.getUniqueId().toString()) != null){
|
||||
String playerTag = TagConfiguration.getTag(player.getUniqueId().toString());
|
||||
if(!"".equalsIgnoreCase(playerTag)){
|
||||
TagConfiguration.saveTag(player.getUniqueId().toString(), "");
|
||||
}
|
||||
}
|
||||
playerMsg("Removed " + player.getName() + "'s tag.");
|
||||
|
||||
return true;
|
||||
|
@ -134,11 +156,48 @@ public class Command_tag extends FreedomCommand {
|
|||
}
|
||||
|
||||
PlayerData.getPlayerData(sender_p).setTag(outputTag);
|
||||
playerMsg("Tag set to '" + outputTag + "'.");
|
||||
playerMsg("Tag set to '" + outputTag + ChatColor.GRAY + "'.");
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
else if ("-s".equalsIgnoreCase(args[0]) && "set".equalsIgnoreCase(args[1]))
|
||||
{
|
||||
final String inputTag = StringUtils.join(args, " ", 2, args.length);
|
||||
final String outputTag = Utilities.colorize(StringUtils.replaceEachRepeatedly(StringUtils.strip(inputTag),
|
||||
new String[]
|
||||
{
|
||||
"" + ChatColor.COLOR_CHAR, "&k"
|
||||
},
|
||||
new String[]
|
||||
{
|
||||
"", ""
|
||||
})) + ChatColor.RESET;
|
||||
|
||||
if (!AdminList.isSuperAdmin(sender))
|
||||
{
|
||||
final String rawTag = ChatColor.stripColor(outputTag).toLowerCase();
|
||||
|
||||
if (rawTag.length() > 20)
|
||||
{
|
||||
playerMsg("That tag is too long (Max is 20 characters).");
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String word : FORBIDDEN_WORDS)
|
||||
{
|
||||
if (rawTag.contains(word))
|
||||
{
|
||||
playerMsg("That tag contains a forbidden word.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlayerData.getPlayerData(sender_p).setTag(outputTag);
|
||||
TagConfiguration.saveTag(sender_p.getUniqueId().toString(), outputTag);
|
||||
playerMsg("Tag set to '" + outputTag + ChatColor.GRAY + "'. (saved)");
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package me.StevenLawson.TotalFreedomMod.config;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TagConfiguration {
|
||||
private static Plugin plugin = JavaPlugin.getPlugin(TotalFreedomMod.class);
|
||||
private static final FileConfiguration playerdata = TotalFreedomMod.getPlugin(TotalFreedomMod.class).getCustomConfig();
|
||||
private static File cfile = new File(plugin.getDataFolder(), "playerTags.yml");
|
||||
public static void saveTag(String playerUuid, String tag) {
|
||||
try {
|
||||
// Set tag value and save.
|
||||
playerdata.set(playerUuid, tag);
|
||||
playerdata.save(cfile);
|
||||
} catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTag(String playerUuid){
|
||||
if(playerdata.get(playerUuid) != null && playerdata.isString(playerUuid)) {
|
||||
if(!playerdata.getString(playerUuid).isEmpty() && !"".equalsIgnoreCase(playerdata.getString(playerUuid))){
|
||||
// Return the value if exists, checking will be done on join event.
|
||||
return playerdata.getString(playerUuid);
|
||||
} else {
|
||||
try {
|
||||
// Try and write player tags if not added
|
||||
playerdata.set(playerUuid, "");
|
||||
playerdata.save(cfile);
|
||||
} catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
} else return null;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import me.StevenLawson.TotalFreedomMod.Server;
|
|||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
||||
import me.StevenLawson.TotalFreedomMod.ban.BanManager;
|
||||
import me.StevenLawson.TotalFreedomMod.config.TagConfiguration;
|
||||
import me.StevenLawson.TotalFreedomMod.discord.bridge.DiscordBridge;
|
||||
import me.StevenLawson.TotalFreedomMod.command.CommandBlocker;
|
||||
import me.StevenLawson.TotalFreedomMod.commands.Command_landmine;
|
||||
|
@ -18,6 +19,7 @@ import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
|||
import me.StevenLawson.TotalFreedomMod.world.AdminWorld;
|
||||
import me.StevenLawson.TotalFreedomMod.world.RollbackManager;
|
||||
import me.StevenLawson.TotalFreedomMod.world.RollbackManager.RollbackEntry;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -896,7 +898,12 @@ public class PlayerListener implements Listener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(TagConfiguration.getTag(player.getUniqueId().toString()) != null){
|
||||
String playerTag = TagConfiguration.getTag(player.getUniqueId().toString());
|
||||
if(!"".equalsIgnoreCase(playerTag)){
|
||||
PlayerData.getPlayerData(player).setTag(playerTag);
|
||||
}
|
||||
}
|
||||
DiscordBridge.transmitMessage(String.format("**%s joined the server**", player.getDisplayName()));
|
||||
}
|
||||
|
||||
|
|
1
src/main/resources/playerTags.yml
Normal file
1
src/main/resources/playerTags.yml
Normal file
|
@ -0,0 +1 @@
|
|||
|
Loading…
Reference in a new issue