Skip to content

Commit

Permalink
TotalFreedomMod Electrum
Browse files Browse the repository at this point in the history
Version 5.0

This TotalFreedomMod release implements many changes. Most notably, the
internals have been completely revamped. TotalFreedomMod now relies on the
Aero library for core mechanics such as command handling and services.

Another important change is the UUID system. In TotalFreedomMod Electrum,
it has been completely removed. The core reason for this is that the
system as a whole was very bugged. Additionally, it did not solve the
primary reason for its conception: preserving player data when the player
changes their username. This is because TotalFreedomMod servers usually
run in offline-mode. This meaning that some of the players joining do not
have a registerd Mojang UUID whatsoever. All in all, the UUID system was
buggy, and it did not fix the reason it was implemented, so it has been
completely removed. The admin list and the ban list now use usernames and
IPs again.

Lastly, many smaller changes have been implemented. Due to the amount of
changes, they have not been named individualy. Please refer to the issues
below for more details.

Fixes #342
Fixes #350
Fixes #380
Fixes #684
Fixes #704
Fixes #716
Fixes #735
Fixes #745
Fixes #784
Fixes #765
Fixes #791
Fixes #805
Fixes #826
Fixes #883
Fixes #1524
Fixes #1534
Fixes #1536
Fixes #1538
Fixes #1545
Fixes #1546
Fixes #1568
Fixes #1627
Resolves #403
Resolves #435
Resolves #597
Resolves #603
Resolves #628
Resolves #690
Resolves #708
Resolves #747
Resolves #748
Resolves #749
Resolves #764
Resolves #767
Resolves #782
Resolves #809
Resolves #803
Resolves #811
Resolves #813
Resolves #830
Resolves #848
Resolves #856
Resolves #876
Resolves #908
Resolves #992
Resolves #1018
Resolves #1432
Resolves #1446
Resolves #1494
Resolves #1501
Resolves #1526
Resolves #1540
Resolves #1550
Resolves #1560
Resolves #1561
Resolves #1578
Resolves #1613
  • Loading branch information
JeromSar committed May 12, 2016
1 parent 924f718 commit aca3398
Show file tree
Hide file tree
Showing 109 changed files with 2,097 additions and 2,021 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ TotalFreedomMod is a CraftBukkit server plugin designed primarily to support the

This plugin was originally coded by StevenLawson (Madgeek1450), with Jerom van der Sar (Prozza) becoming heavily involved in its development some time later. It consists of over 85 custom coded commands and a large variety of distinguishable features not included in any other plugin. The plugin has since its beginning grown immensely. Together, with the main TotalFreedom server, TotalFreedomMod has a long-standing reputation of effectiveness whilst maintaining a clear feeling of openness towards the administrators and the players themselves.

### Download ###
You may download official binaries from the [releases page](https://github.com/TotalFreedom/TotalFreedomMod/releases).

### Contributing ###
Please see [CONTRIBUTING.md](CONTRIBUTING.md) if you are interested in developing TotalFreedomMod. For information on how TotalFreedomMod is licensed, please see [LICENSE.md](LICENSE.md).
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tfm.build.version>${project.version}</tfm.build.version>
<tfm.build.codename>Electrum</tfm.build.codename>
<tfm.build.number>${maven.buildnumber}</tfm.build.number>
<tfm.build.date>${maven.build.timestamp}</tfm.build.date>
<tfm.build.author>${buildAuthor}</tfm.build.author>
Expand Down Expand Up @@ -120,7 +121,7 @@
<target>1.7</target>
</configuration>
</plugin>

<!-- Antrun -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
Expand Down Expand Up @@ -224,7 +225,7 @@
<configuration>
<buildNumberPropertyName>maven.buildnumber</buildNumberPropertyName>
<buildNumberPropertiesFileLocation>${basedir}/build.properties</buildNumberPropertiesFileLocation>
<format>{0,number}</format>
<format>{0,number,#}</format>
<items>
<item>buildNumber</item>
</items>
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/me/totalfreedom/totalfreedommod/Announcer.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public void run()
current = 0;
}

FUtil.bcastMsg(prefix + announcements.get(current));
announce(announcements.get(current));
}
}.runTaskTimer(TotalFreedomMod.plugin, interval, interval);
}.runTaskTimer(plugin, interval, interval);
}

@Override
Expand All @@ -80,4 +80,9 @@ public List<String> getAnnouncements()
return Collections.unmodifiableList(announcements);
}

public void announce(String message)
{
FUtil.bcastMsg(prefix + message);
}

}
8 changes: 4 additions & 4 deletions src/main/java/me/totalfreedom/totalfreedommod/AntiNuke.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ else if (playerLocation.distanceSquared(location) > (nukeMonitorRange * nukeMoni
if (fPlayer.incrementAndGetFreecamDestroyCount() > ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
{
FUtil.bcastMsg(player.getName() + " has been flagged for possible freecam nuking.", ChatColor.RED);
FUtil.autoEject(player, "Freecam (extended range) block breaking is not permitted on this server.");
plugin.ae.autoEject(player, "Freecam (extended range) block breaking is not permitted on this server.");

fPlayer.resetFreecamDestroyCount();

Expand All @@ -72,7 +72,7 @@ else if (playerLocation.distanceSquared(location) > (nukeMonitorRange * nukeMoni
if (fPlayer.incrementAndGetBlockDestroyCount() > ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger())
{
FUtil.bcastMsg(player.getName() + " is breaking blocks too fast!", ChatColor.RED);
FUtil.autoEject(player, "You are breaking blocks too fast. Nukers are not permitted on this server.");
plugin.ae.autoEject(player, "You are breaking blocks too fast. Nukers are not permitted on this server.");

fPlayer.resetBlockDestroyCount();

Expand Down Expand Up @@ -112,7 +112,7 @@ else if (playerLocation.distanceSquared(blockLocation) > (nukeMonitorRange * nuk
if (fPlayer.incrementAndGetFreecamPlaceCount() > ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
{
FUtil.bcastMsg(player.getName() + " has been flagged for possible freecam building.", ChatColor.RED);
FUtil.autoEject(player, "Freecam (extended range) block building is not permitted on this server.");
plugin.ae.autoEject(player, "Freecam (extended range) block building is not permitted on this server.");

fPlayer.resetFreecamPlaceCount();

Expand All @@ -124,7 +124,7 @@ else if (playerLocation.distanceSquared(blockLocation) > (nukeMonitorRange * nuk
if (fPlayer.incrementAndGetBlockPlaceCount() > ConfigEntry.NUKE_MONITOR_COUNT_PLACE.getInteger())
{
FUtil.bcastMsg(player.getName() + " is placing blocks too fast!", ChatColor.RED);
FUtil.autoEject(player, "You are placing blocks too fast.");
plugin.ae.autoEject(player, "You are placing blocks too fast.");

fPlayer.resetBlockPlaceCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
if (fPlayer.incrementAndGetMsgCount() > MSG_PER_CYCLE)
{
FUtil.bcastMsg(player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
FUtil.autoEject(player, "Kicked for spamming commands.");
plugin.ae.autoEject(player, "Kicked for spamming commands.");

fPlayer.resetMsgCount();
event.setCancelled(true);
Expand Down
116 changes: 116 additions & 0 deletions src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package me.totalfreedom.totalfreedommod;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import me.totalfreedom.totalfreedommod.banning.Ban;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.util.Ips;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;

public class AutoEject extends FreedomService
{

private final Map<String, Integer> ejects = new HashMap<>(); // ip -> amount

public AutoEject(TotalFreedomMod plugin)
{
super(plugin);
}

@Override
protected void onStart()
{
}

@Override
protected void onStop()
{
}

public void autoEject(Player player, String kickMessage)
{
EjectMethod method = EjectMethod.STRIKE_ONE;
final String ip = Ips.getIp(player);

if (!ejects.containsKey(ip))
{
ejects.put(ip, 0);
}

int kicks = ejects.get(ip);
kicks += 1;

ejects.put(ip, kicks);

if (kicks <= 1)
{
method = EjectMethod.STRIKE_ONE;
}
else if (kicks == 2)
{
method = EjectMethod.STRIKE_TWO;
}
else if (kicks >= 3)
{
method = EjectMethod.STRIKE_THREE;
}

FLog.info("AutoEject -> name: " + player.getName() + " - player ip: " + ip + " - method: " + method.toString());

player.setOp(false);
player.setGameMode(GameMode.SURVIVAL);
player.getInventory().clear();

switch (method)
{
case STRIKE_ONE:
{
final Calendar cal = new GregorianCalendar();
cal.add(Calendar.MINUTE, 5);
final Date expires = cal.getTime();

FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 5 minutes.");

plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
player.kickPlayer(kickMessage);

break;
}
case STRIKE_TWO:
{
final Calendar c = new GregorianCalendar();
c.add(Calendar.MINUTE, 10);
final Date expires = c.getTime();

FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 10 minutes.");

plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
player.kickPlayer(kickMessage);
break;
}
case STRIKE_THREE:
{
plugin.bm.addBan(Ban.forPlayerFuzzy(player, Bukkit.getConsoleSender(), null, kickMessage));

FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");

player.kickPlayer(kickMessage);
break;
}
}
}

public static enum EjectMethod
{

STRIKE_ONE, STRIKE_TWO, STRIKE_THREE;
}

}
87 changes: 87 additions & 0 deletions src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package me.totalfreedom.totalfreedommod;

import java.io.File;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.component.PluginComponent;
import net.pravian.aero.config.YamlConfig;
import org.bukkit.util.FileUtil;

public class BackupManager extends PluginComponent<TotalFreedomMod>
{

public BackupManager(TotalFreedomMod plugin)
{
super(plugin);
}

public void createBackups(String file)
{
createBackups(file, false);
}

public void createBackups(String file, boolean onlyWeekly)
{
final String save = file.split("\\.")[0];
final YamlConfig config = new YamlConfig(plugin, "backup/backup.yml", false);
config.load();

// Weekly
if (!config.isInt(save + ".weekly"))
{
performBackup(file, "weekly");
config.set(save + ".weekly", FUtil.getUnixTime());
}
else
{
int lastBackupWeekly = config.getInt(save + ".weekly");

if (lastBackupWeekly + 3600 * 24 * 7 < FUtil.getUnixTime())
{
performBackup(file, "weekly");
config.set(save + ".weekly", FUtil.getUnixTime());
}
}

if (onlyWeekly)
{
config.save();
return;
}

// Daily
if (!config.isInt(save + ".daily"))
{
performBackup(file, "daily");
config.set(save + ".daily", FUtil.getUnixTime());
}
else
{
int lastBackupDaily = config.getInt(save + ".daily");

if (lastBackupDaily + 3600 * 24 < FUtil.getUnixTime())
{
performBackup(file, "daily");
config.set(save + ".daily", FUtil.getUnixTime());
}
}

config.save();
}

private void performBackup(String file, String type)
{
FLog.info("Backing up " + file + " to " + file + "." + type + ".bak");
final File backupFolder = new File(plugin.getDataFolder(), "backup");

if (!backupFolder.exists())
{
backupFolder.mkdirs();
}

final File oldYaml = new File(plugin.getDataFolder(), file);
final File newYaml = new File(backupFolder, file + "." + type + ".bak");
FileUtil.copy(oldYaml, newYaml);
}

}
40 changes: 37 additions & 3 deletions src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FSync;
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -84,10 +87,41 @@ private void handleChatEvent(AsyncPlayerChatEvent event)
// Finally, set message
event.setMessage(message);

// Set the tag
if (fPlayer.getTag() != null)
// Make format
String format = "<%1$s> %2$s";

String tag = fPlayer.getTag();
if (tag != null && !tag.isEmpty())
{
event.setFormat("<" + fPlayer.getTag().replaceAll("%", "%%") + " %1$s> %2$s");
format = tag.replace("%", "%%") + " " + format;
}

// Set format
event.setFormat(format);
}

public void adminChat(CommandSender sender, String message)
{
String name = sender.getName() + " " + plugin.rm.getDisplay(sender).getColoredTag() + ChatColor.WHITE;
FLog.info("[ADMIN] " + name + ": " + message);

for (Player player : server.getOnlinePlayers())
{
if (plugin.al.isAdmin(player))
{
player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + name + ": " + ChatColor.GOLD + message);
}
}
}

public void reportAction(Player reporter, Player reported, String report)
{
for (Player player : server.getOnlinePlayers())
{
if (plugin.al.isAdmin(player))
{
playerMsg(player, ChatColor.RED + "[REPORTS] " + ChatColor.GOLD + reporter.getName() + " has reported " + reported.getName() + " for " + report);
}
}
}

Expand Down
Loading

0 comments on commit aca3398

Please sign in to comment.