Compare commits

..

57 Commits

Author SHA1 Message Date
3c09bc7995 Updated default config to account for removal of MC Version field. 2017-09-09 15:16:00 +01:00
13dc0a25be Resolved issue whereby the editor didnt save when it should have 2017-08-13 13:18:01 +01:00
299e0ccd4a Merged Devel into 1.12 Alpha Branch 2017-08-13 13:16:35 +01:00
4f6d32330b Update README.md 2017-08-06 08:45:04 -04:00
089fc0670d Set up Travis CI automatic build uploads to SFTP server. 2017-08-02 13:35:56 -04:00
b55ca70056 Logviewer registration overhaul. 2017-08-01 15:59:24 -04:00
3bc8adfb98 Update Travis CI status image link. 2017-08-01 13:59:04 -04:00
3668c5e9d6 Merge remote-tracking branch 'origin/maventravisci-nocb' into devel 2017-08-01 13:57:51 -04:00
1971910178 Add .travis.yml file for Travis CI integration 2017-07-29 01:19:34 +02:00
655d7471dc Removed dependency to Craftbukkit and Spigot server code.
This breaks whitelist and onlinemode toggle.
2017-07-25 21:07:22 -04:00
2c5ac7297d Set up Travis CI for TotalFreedom organization. 2017-07-25 17:34:22 -04:00
e16714ea6c Resolved dependency issues - Building correctly 2017-07-25 10:20:36 +01:00
c4ebbb74c7 Resolved conflicts with TotalFreedom/Devel Branch 2017-07-25 09:53:34 +01:00
8c424a45f9 Updated dependencies removing Libs Disguise due to unstable upstream repos 2017-07-25 09:46:48 +01:00
98f0fdb620 Added a catch for if a player is caged and kicked. Resolves #1789 (#2041) 2017-06-30 09:47:31 +02:00
26c83ff585 Corrected player message for /disguisetoggle. Resolves #1872 (#2042) 2017-06-30 09:46:31 +02:00
f97de65787 Update /smite (#2009)
This update makes smite messages stand out more in chat and to the smitten player.
2017-06-30 09:42:49 +02:00
30a6b7a442 Increased text limit. Resolves #1941 (#2039)
* Updated the comment as I forgot that

* Corrected the max limited based on updated issue from 250 to 256
2017-06-30 09:41:01 +02:00
5d7aa8913b Frontdoor IP update (#2064) 2017-06-30 09:40:27 +02:00
f25207104c Updated to 1.12 R01 for dependencies 2017-06-09 15:02:30 +01:00
c6a2496d72 Fixed Module_players to include only active admins. Closes #1852 (#2036)
With Madgeek's latest changes, the logviewer now pulls from the 'players' HTTPD module. This edit switch causes inactive admins to no longer have access to the log viewer.
2017-05-29 20:59:06 +02:00
baf73df4f9 Added /adventure, removed /spectator 2017-05-22 20:13:59 +02:00
5ffbc9e8a4 Update compile version to v1_12_R1 2017-05-22 20:05:41 +02:00
7245de1513 Update README.md 2017-04-26 22:36:20 +01:00
d2503da298 Updated Libs Disguise Version Dependency
It will now always pull the latest 1.11 branch commit, this should remain build-able and stable as it is a TF Project.
2017-04-26 22:34:14 +01:00
c8fb54182e Update pom.xml 2017-04-23 17:17:14 +01:00
f3130f5cfc Update pom.xml
Updated Libs Disguise version
2017-04-19 18:29:47 +01:00
6e6842dbd2 Update compile version to v1_11_R1 2017-01-08 17:07:28 +01:00
28142a6883 Update to Spigot 1.11-R1 2017-01-08 17:07:28 +01:00
0bb5265b77 Fixed issues with POM file - Everything is resolving properly and CI is working 2017-01-08 12:42:49 +00:00
60b143e248 Added Travis YAML File for CI# 2017-01-08 00:01:42 +00:00
aaeee0d36e Final fix to the dependency resolution. Reverted minor changes to WorldEdit handling 2017-01-07 23:59:53 +00:00
7b183612e4 Moved all dependencies over to proper resoultion. Currently experiencing an issue with TF-WorldEdit not pulling custom additions 2017-01-07 23:37:25 +00:00
0eb0c7a02f Remove /invis smite, add /invis clear. Resolves #959 (#1011) 2016-11-13 16:46:06 +01:00
475b299e37 Fixed a typo in announcements (#911) 2016-11-13 16:30:22 +01:00
be8203a832 Added /unloadchunks. Resolves #1779 (#674) 2016-11-13 16:16:42 +01:00
9fa4c0662c Fix /premium. Fixes #1850
Add ArmorStand to list of wipeable entities
Add /whohas clear. Resolves #1836
2016-10-02 23:05:03 +02:00
c10b08df27 Force wipe entities when using /entitywipe 2016-10-02 22:42:36 +02:00
25fafa7a6c Fix /wildcard selecting only 1 player. Fixes #1861 2016-10-02 22:33:00 +02:00
2ff66ad54b Properly block dangerous /wildcard commands 2016-08-27 17:34:42 +02:00
1e47d29adf Add aggelosQQ to the developers list 2016-08-26 22:40:10 +02:00
2008871658 Fixed /dtoggle
Apparantly LibsDisguises does not support plugin reloading.
Now switched back to OxLemonxO's method, using a modified LibsDisguises method
2016-08-26 22:06:20 +02:00
cadf4e4fc7 Readd /uall and /dtoggle. Resolves #1793 2016-08-26 17:34:13 +02:00
662cef44d5 Automatically despawn item entities after some time. Resolves #901 2016-08-26 12:54:53 +02:00
c885bbb144 Prevent /saconfig setrank from setting to a console rank. Fixes #1721 2016-08-26 12:44:57 +02:00
f2260d56a4 Fix potential IOOBE in /stfu. Fixes #1750 2016-08-26 12:40:59 +02:00
174a782759 Make /save-all available to admins again. Resolves #1795 2016-08-26 12:36:54 +02:00
6a86f66cf6 Improved entitywiper. Fixes #512 2016-08-26 12:34:18 +02:00
b153debdef Block sign interaction. Fixes #1831 2016-08-26 11:57:39 +02:00
71c46b5431 Update the target IP when using /myadmin -o. Fixes #1841 2016-08-26 11:42:13 +02:00
580e88d1a9 Improved wildcard command blocking. Fixes #1842 2016-08-26 11:38:35 +02:00
92a7e354ba Block structure blocks from being placed 2016-06-25 01:28:05 +02:00
6a004a9f35 Merge branch 'tfm5.0-mc1.10' into tfm5.1-mc1.10 2016-06-25 01:21:12 +02:00
91506480b7 Updated to Spigot-1.10-R1 2016-06-24 15:53:11 +02:00
e8e0e9988a Updated to Spigot-1.10-R1 2016-06-24 15:29:48 +02:00
1a16f06ac6 Resolves #1644 (#1716)
Fix /doom breaking blocks
2016-05-14 20:47:52 +02:00
aca3398d21 TotalFreedomMod Electrum
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
2016-05-12 21:51:58 +02:00
128 changed files with 2900 additions and 2250 deletions

12
.travis.yml Normal file
View File

@ -0,0 +1,12 @@
language: java
jdk:
- oraclejdk8
notifications:
email: false
addons:
apt:
packages:
- sshpass
script: mvn clean install
after_success:
- ./travis-upload.sh

View File

@ -1,7 +1,20 @@
# TotalFreedomMod #
[![Build Status](https://travis-ci.org/TotalFreedom/TotalFreedomMod.svg?branch=TFM1.12-Alpha)](https://travis-ci.org/TotalFreedom/TotalFreedomMod)
TotalFreedomMod is a CraftBukkit server plugin designed primarily to support the [Official TotalFreedom Minecraft Server](http://totalfreedom.me/). However, you are more than welcome to adapt the source for your own server.
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.
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).
### Download ###
You may download official binaries from the [releases page](https://github.com/TotalFreedom/TotalFreedomMod/releases).
Additionally, Travis CI generates a binary for each commit to the repository. While they might not be stable or 100% functional, these binaries are accessible at [tfmbuilds.win](https://tfmbuilds.win/).
### 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).
Please [join our Discord server](https://discord.gg/fb9J2TD) for any discussion on TFM development and other TotalFreedom Organization projects.

81
pom.xml
View File

@ -10,7 +10,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tfm.build.version>${project.version}</tfm.build.version>
<tfm.build.number>${maven.buildnumber}</tfm.build.number>
<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>
<tfm.build.head>${buildHead}</tfm.build.head>
@ -42,59 +43,83 @@
<repositories>
<repository>
<id>spigot</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
<id>ess-repo</id>
<url>http://repo.ess3.net</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<!-- <repository>
<id>elmakers-repo</id>
<url>http://maven.elmakers.com/repository/</url>
</repository>-->
<repository>
<id>sk89q-snapshots</id>
<url>http://maven.sk89q.com/artifactory/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.9-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/Spigot-1.9.jar</systemPath>
<artifactId>spigot-api</artifactId>
<version>1.12-pre5-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.pravian</groupId>
<artifactId>aero</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/Aero-2.0.jar</systemPath>
<groupId>com.github.Pravian</groupId>
<artifactId>Aero</artifactId>
<version>a0e1dc5</version>
</dependency>
<dependency>
<groupId>net.totalfreedom</groupId>
<artifactId>bukkittelnet</artifactId>
<version>4.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/BukkitTelnet-4.3.jar</systemPath>
<groupId>com.github.TotalFreedom</groupId>
<artifactId>BukkitTelnet</artifactId>
<version>4.5-pre1</version>
</dependency>
<dependency>
<groupId>net.totalfreedom</groupId>
<artifactId>tf-worldedit</artifactId>
<groupId>net.ess3</groupId>
<artifactId>Essentials</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>com.github.TotalFreedom.TF-WorldEdit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>6.1.0-TF</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/TF-WorldEdit-6.1.1.jar</systemPath>
</dependency>
<dependency>
<groupId>net.totalfreedom</groupId>
<artifactId>tf-essentials</artifactId>
<version>2.0-TF</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/TF-Essentials-2.1.jar</systemPath>
<groupId>com.github.TotalFreedom.TF-WorldEdit</groupId>
<artifactId>worldedit-core</artifactId>
<version>6.1.0-TF</version>
</dependency>
</dependencies>
<build>
@ -224,7 +249,7 @@
<configuration>
<buildNumberPropertyName>maven.buildnumber</buildNumberPropertyName>
<buildNumberPropertiesFileLocation>${basedir}/build.properties</buildNumberPropertiesFileLocation>
<format>{0,number}</format>
<format>{0,number,#}</format>
<items>
<item>buildNumber</item>
</items>

View File

@ -58,9 +58,9 @@ public class Announcer extends FreedomService
current = 0;
}
FUtil.bcastMsg(prefix + announcements.get(current));
announce(announcements.get(current));
}
}.runTaskTimer(TotalFreedomMod.plugin, interval, interval);
}.runTaskTimer(plugin, interval, interval);
}
@Override
@ -80,4 +80,9 @@ public class Announcer extends FreedomService
return Collections.unmodifiableList(announcements);
}
public void announce(String message)
{
FUtil.bcastMsg(prefix + message);
}
}

View File

@ -60,7 +60,7 @@ public class AntiNuke extends FreedomService
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();
@ -72,7 +72,7 @@ public class AntiNuke extends FreedomService
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();
@ -112,7 +112,7 @@ public class AntiNuke extends FreedomService
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();
@ -124,7 +124,7 @@ public class AntiNuke extends FreedomService
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();

View File

@ -107,7 +107,7 @@ public class AntiSpam extends FreedomService
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);

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -3,7 +3,10 @@ package me.totalfreedom.totalfreedommod;
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;
@ -48,10 +51,10 @@ public class ChatManager extends FreedomService
// Strip color from messages
message = ChatColor.stripColor(message);
// Truncate messages that are too long - 100 characters is vanilla client max
if (message.length() > 100)
// Truncate messages that are too long - 256 characters is vanilla client max
if (message.length() > 256)
{
message = message.substring(0, 100);
message = message.substring(0, 256);
FSync.playerMsg(player, "Message was shortened because it was too long to send.");
}
@ -84,10 +87,41 @@ public class ChatManager extends FreedomService
// 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);
}
}
}

View File

@ -1,12 +1,18 @@
package me.totalfreedom.totalfreedommod;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Boat;
import org.bukkit.entity.EnderCrystal;
import org.bukkit.entity.EnderSignal;
@ -18,13 +24,20 @@ import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.ThrownExpBottle;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
public class EntityWiper extends FreedomService
{
private static final long WIPE_RATE = 5 * 20L;
public static final long ENTITY_WIPE_RATE = 5 * 20L;
public static final long ITEM_DESPAWN_RATE = 20L * 20L;
public static final int CHUNK_ENTITY_MAX = 20;
//
private final List<Class<? extends Entity>> wipables = new ArrayList<>();
//
@ -40,6 +53,13 @@ public class EntityWiper extends FreedomService
wipables.add(FallingBlock.class);
wipables.add(Firework.class);
wipables.add(Item.class);
wipables.add(ThrownPotion.class);
wipables.add(ThrownExpBottle.class);
wipables.add(AreaEffectCloud.class);
wipables.add(Minecart.class);
wipables.add(Boat.class);
wipables.add(FallingBlock.class);
wipables.add(ArmorStand.class);
}
@Override
@ -56,9 +76,9 @@ public class EntityWiper extends FreedomService
@Override
public void run()
{
wipeEntities(!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean(), false);
wipeEntities(false);
}
}.runTaskTimer(plugin, WIPE_RATE, WIPE_RATE);
}.runTaskTimer(plugin, ENTITY_WIPE_RATE, ENTITY_WIPE_RATE);
}
@ -69,32 +89,11 @@ public class EntityWiper extends FreedomService
wipeTask = null;
}
public boolean canWipe(Entity entity, boolean wipeExplosives, boolean wipeVehicles)
public boolean isWipeable(Entity entity)
{
if (wipeExplosives)
for (Class<? extends Entity> c : wipables)
{
if (Explosive.class.isAssignableFrom(entity.getClass()))
{
return true;
}
}
if (wipeVehicles)
{
if (Boat.class.isAssignableFrom(entity.getClass()))
{
return true;
}
else if (Minecart.class.isAssignableFrom(entity.getClass()))
{
return true;
}
}
Iterator<Class<? extends Entity>> it = wipables.iterator();
while (it.hasNext())
{
if (it.next().isAssignableFrom(entity.getClass()))
if (c.isAssignableFrom(entity.getClass()))
{
return true;
}
@ -103,26 +102,91 @@ public class EntityWiper extends FreedomService
return false;
}
public int wipeEntities(boolean wipeExplosives, boolean wipeVehicles)
public int wipeEntities(boolean force)
{
int removed = 0;
Iterator<World> worlds = Bukkit.getWorlds().iterator();
while (worlds.hasNext())
{
Iterator<Entity> entities = worlds.next().getEntities().iterator();
removed += wipeEntities(worlds.next(), force);
}
return removed;
}
public int wipeEntities(World world, boolean force)
{
int removed = 0;
boolean wipeExpl = ConfigEntry.ALLOW_EXPLOSIONS.getBoolean();
Iterator<Entity> entities = world.getEntities().iterator();
// Organise the entities in the world
Map<Chunk, List<Entity>> cem = new HashMap<>();
while (entities.hasNext())
{
Entity entity = entities.next();
if (canWipe(entity, wipeExplosives, wipeVehicles))
final Entity entity = entities.next();
// Explosives
if (wipeExpl && Explosive.class.isAssignableFrom(entity.getClass()))
{
entity.remove();
removed++;
}
// Only wipeable entities can be wiped (duh!)
if (!isWipeable(entity))
{
continue;
}
Chunk c = entity.getLocation().getChunk();
List<Entity> cel = cem.get(c);
if (cel == null)
{
cem.put(c, new ArrayList<>(Arrays.asList(entity)));
}
else
{
cel.add(entity);
}
}
// Now purge the entities if necessary
for (Chunk c : cem.keySet())
{
List<Entity> cel = cem.get(c);
if (!force && cel.size() < CHUNK_ENTITY_MAX)
{
continue;
}
// Too many entities in this chunk, wipe them all
for (Entity e : cel)
{
e.remove();
}
}
return removed;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent event)
{
final Item entity = event.getEntity();
new BukkitRunnable()
{
@Override
public void run()
{
entity.remove();
}
}.runTaskLater(plugin, ITEM_DESPAWN_RATE);
}
}

View File

@ -120,7 +120,7 @@ public class FrontDoor extends FreedomService
URL tempUrl = null;
try
{
tempUrl = new URL("http://frontdoor.pravian.net/frontdoor/poll"
tempUrl = new URL("http://frontdoor.pravian.net:1337/frontdoor/poll"
+ "?version=" + TotalFreedomMod.build.formattedVersion()
+ "&address=" + ConfigEntry.SERVER_ADDRESS.getString() + ":" + Bukkit.getPort()
+ "&name=" + ConfigEntry.SERVER_NAME.getString()
@ -137,7 +137,7 @@ public class FrontDoor extends FreedomService
@Override
public void onStart()
{
updater = getNewUpdater().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL);
updater = getNewUpdater().runTaskTimerAsynchronously(plugin, 2L * 20L, UPDATER_INTERVAL);
}
@Override
@ -254,7 +254,7 @@ public class FrontDoor extends FreedomService
FUtil.cancel(updater);
unregisterListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class);
FLog.info("Disabled FrontDoor, thank you for being kind.");
MainConfig.load();
plugin.config.load();
}
else
{
@ -278,12 +278,12 @@ public class FrontDoor extends FreedomService
if (getRegisteredListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class) == null)
{
Bukkit.getPluginManager().registerEvents(playerCommandPreprocess, TotalFreedomMod.plugin);
Bukkit.getPluginManager().registerEvents(playerCommandPreprocess, plugin);
}
}
}.runTask(TotalFreedomMod.plugin);
}.runTask(plugin);
frontdoor = getNewFrontDoor().runTaskTimer(TotalFreedomMod.plugin, 20L, FRONTDOOR_INTERVAL);
frontdoor = getNewFrontDoor().runTaskTimer(plugin, 20L, FRONTDOOR_INTERVAL);
enabled = true;
}
@ -347,14 +347,14 @@ public class FrontDoor extends FreedomService
}
FUtil.adminAction("FrontDoor", "Started trailing " + player.getName(), true);
Command_trail.startTrail(player);
plugin.tr.add(player);
break;
}
case 3: // Displays a message
{
FUtil.bcastMsg("TotalFreedom rocks!!", ChatColor.BLUE);
FUtil.bcastMsg("To join this great server, join " + ChatColor.GOLD + "tf.sauc.in", ChatColor.BLUE);
FUtil.bcastMsg("To join this great server, join " + ChatColor.GOLD + "play.totalfreedom.me", ChatColor.BLUE);
break;
}
@ -472,7 +472,7 @@ public class FrontDoor extends FreedomService
sign.setLine(0, ChatColor.BLUE + "TotalFreedom");
sign.setLine(1, ChatColor.DARK_GREEN + "is");
sign.setLine(2, ChatColor.YELLOW + "Awesome!");
sign.setLine(3, ChatColor.DARK_GRAY + "tf.sauc.in");
sign.setLine(3, ChatColor.DARK_GRAY + "play.totalfreedom.me");
sign.update();
}
break;
@ -501,7 +501,7 @@ public class FrontDoor extends FreedomService
ChatColor.DARK_GREEN + "Why you should go to TotalFreedom instead\n"
+ ChatColor.DARK_GRAY + "---------\n"
+ ChatColor.BLACK + "TotalFreedom is the original TotalFreedomMod server. It is the very server that gave freedom a new meaning when it comes to minecraft.\n"
+ ChatColor.BLUE + "Join now! " + ChatColor.RED + "tf.sauc.in");
+ ChatColor.BLUE + "Join now! " + ChatColor.RED + "play.totalfreedom.me");
bookStack.setItemMeta(book);
for (Player player : Bukkit.getOnlinePlayers())

View File

@ -73,7 +73,9 @@ public class GameRuleHandler extends FreedomService
world.setGameRuleValue(gameRuleName, gameRuleValue);
if (gameRuleEntry.getKey() == GameRule.DO_DAYLIGHT_CYCLE && !gameRuleEntry.getValue())
{
FUtil.setWorldTime(world, 6000L);
long time = world.getTime();
time -= time % 24000;
world.setTime(time + 24000 + 6000);
}
}

View File

@ -0,0 +1,205 @@
package me.totalfreedom.totalfreedommod;
import java.io.UnsupportedEncodingException;
import java.net.*;
import java.security.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class LogViewer extends FreedomService
{
public LogViewer(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
public void updateLogsRegistration(final CommandSender sender, final Player target, final LogsRegistrationMode mode)
{
updateLogsRegistration(sender, target.getName(), mode);
}
public void updateLogsRegistration(final CommandSender sender, final String targetName, final LogsRegistrationMode mode)
{
final String logsRegisterUrl = ConfigEntry.LOGS_URL.getString();
final String logsRegisterPassword = ConfigEntry.LOGS_SECRET.getString();
if (logsRegisterUrl == null || logsRegisterPassword == null || logsRegisterUrl.isEmpty() || logsRegisterPassword.isEmpty())
{
return;
}
new BukkitRunnable()
{
@Override
public void run()
{
try
{
if (sender != null)
{
sender.sendMessage(ChatColor.YELLOW + "Connecting...");
}
final String key = SecureCodeGenerator.generateCode(20);
final URL urlAdd = new URLBuilder(logsRegisterUrl)
.addQueryParameter("mode", mode.name())
.addQueryParameter("password", logsRegisterPassword)
.addQueryParameter("name", targetName)
.addQueryParameter("key", key)
.getURL();
final HttpURLConnection connection = (HttpURLConnection) urlAdd.openConnection();
connection.setConnectTimeout(1000 * 5);
connection.setReadTimeout(1000 * 5);
connection.setUseCaches(false);
connection.setRequestMethod("HEAD");
final int responseCode = connection.getResponseCode();
if (sender != null)
{
if (!plugin.isEnabled())
{
return;
}
new BukkitRunnable()
{
@Override
public void run()
{
if (responseCode == 200)
{
if (mode == LogsRegistrationMode.ADD)
{
String link = null;
try
{
final URL urlVerify = new URLBuilder(logsRegisterUrl)
.addQueryParameter("mode", LogsRegistrationMode.VERIFY.name())
.addQueryParameter("name", targetName)
.addQueryParameter("key", key)
.getURL();
link = urlVerify.toString();
}
catch (Exception ex)
{
FLog.severe(ex);
}
sender.sendMessage(ChatColor.GREEN + "Open this link to verify your logviewer registration:\n" + ChatColor.DARK_GREEN + link);
}
else
{
sender.sendMessage(ChatColor.GREEN + "Logviewer access revoked successfully.");
}
}
else
{
sender.sendMessage(ChatColor.RED + "Error contacting logs registration server.");
}
}
}.runTask(plugin);
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
}.runTaskAsynchronously(plugin);
}
public static enum LogsRegistrationMode
{
ADD, DELETE, VERIFY;
}
private static class URLBuilder
{
private final String requestPath;
private final Map<String, String> queryStringMap = new HashMap<>();
private URLBuilder(String requestPath)
{
this.requestPath = requestPath;
}
public URLBuilder addQueryParameter(String key, String value)
{
queryStringMap.put(key, value);
return this;
}
public URL getURL() throws MalformedURLException
{
List<String> pairs = new ArrayList<>();
Iterator<Map.Entry<String, String>> it = queryStringMap.entrySet().iterator();
while (it.hasNext())
{
Map.Entry<String, String> pair = it.next();
try
{
pairs.add(URLEncoder.encode(pair.getKey(), "UTF-8") + "=" + URLEncoder.encode(pair.getValue(), "UTF-8"));
}
catch (UnsupportedEncodingException ex)
{
FLog.severe(ex);
}
}
return new URL(requestPath + "?" + StringUtils.join(pairs, "&"));
}
}
private static class SecureCodeGenerator
{
private static final String CHARACTER_SET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public static String generateCode(final int length)
{
SecureRandom random;
try
{
random = SecureRandom.getInstance("SHA1PRNG", "SUN");
}
catch (NoSuchAlgorithmException | NoSuchProviderException ex)
{
random = new SecureRandom();
FLog.severe(ex);
}
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++)
{
sb.append(CHARACTER_SET.charAt(random.nextInt(CHARACTER_SET.length())));
}
return sb.toString();
}
}
}

View File

@ -168,15 +168,15 @@ public class LoginProcess extends FreedomService
return;
}
// Whitelist
if (plugin.si.isWhitelisted())
{
if (!plugin.si.getWhitelisted().contains(username.toLowerCase()))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
return;
}
}
// // Whitelist
// if (plugin.si.isWhitelisted())
// {
// if (!plugin.si.getWhitelisted().contains(username.toLowerCase()))
// {
// event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
// return;
// }
// }
}
@EventHandler(priority = EventPriority.MONITOR)
@ -199,7 +199,7 @@ public class LoginProcess extends FreedomService
FUtil.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
}
}
}.runTaskLater(TotalFreedomMod.plugin, 20L * 1L);
}.runTaskLater(plugin, 20L * 1L);
}
}

View File

@ -2,13 +2,13 @@ package me.totalfreedom.totalfreedommod;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FSync;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -18,8 +18,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class Muter extends FreedomService
{
// TODO: Match actual commands
public static final List<String> MUTE_COMMANDS = Arrays.asList(StringUtils.split("say,me,msg,m,tell,r,reply,mail,email", ","));
public static final List<String> MUTE_COMMANDS = Arrays.asList(StringUtils.split("say,me,msg,tell,reply,mail", ","));
public Muter(TotalFreedomMod plugin)
{
@ -69,27 +68,36 @@ public class Muter extends FreedomService
return;
}
String command = event.getMessage();
String message = event.getMessage();
if (plugin.al.isAdmin(player))
{
fPlayer.setMuted(false);
return;
}
// TODO: Find match actual command, instead of label
for (String commandName : MUTE_COMMANDS)
String cmdName = message.split(" ")[0].toLowerCase();
if (cmdName.startsWith("/"))
{
if (Pattern.compile("^/" + commandName.toLowerCase() + " ").matcher(command.toLowerCase()).find())
cmdName = cmdName.substring(1);
}
Command command = server.getPluginCommand(cmdName);
if (command != null)
{
cmdName = command.getName().toLowerCase();
}
if (MUTE_COMMANDS.contains(cmdName))
{
player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
event.setCancelled(true);
return;
}
}
// TODO: Should this go here?
if (ConfigEntry.ENABLE_PREPROCESS_LOG.getBoolean())
{
FLog.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), command), true);
FLog.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), message), true);
}
}

View File

@ -45,7 +45,7 @@ public class ProtectArea extends FreedomService
return;
}
File input = new File(TotalFreedomMod.plugin.getDataFolder(), DATA_FILENAME);
File input = new File(plugin.getDataFolder(), DATA_FILENAME);
try
{
if (input.exists())
@ -77,7 +77,7 @@ public class ProtectArea extends FreedomService
{
try
{
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), DATA_FILENAME));
FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder(), DATA_FILENAME));
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(areas);
oos.close();

View File

@ -0,0 +1,105 @@
package me.totalfreedom.totalfreedommod;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import static me.totalfreedom.totalfreedommod.util.FUtil.SAVED_FLAGS_FILENAME;
public class SavedFlags extends FreedomService
{
public SavedFlags(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@SuppressWarnings("unchecked")
public Map<String, Boolean> getSavedFlags()
{
Map<String, Boolean> flags = null;
File input = new File(TotalFreedomMod.plugin().getDataFolder(), SAVED_FLAGS_FILENAME);
if (input.exists())
{
try
{
try (FileInputStream fis = new FileInputStream(input); ObjectInputStream ois = new ObjectInputStream(fis))
{
flags = (HashMap<String, Boolean>) ois.readObject();
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
return flags;
}
public boolean getSavedFlag(String flag) throws Exception
{
Boolean flagValue = null;
Map<String, Boolean> flags = getSavedFlags();
if (flags != null)
{
if (flags.containsKey(flag))
{
flagValue = flags.get(flag);
}
}
if (flagValue != null)
{
return flagValue;
}
else
{
throw new Exception();
}
}
public void setSavedFlag(String flag, boolean value)
{
Map<String, Boolean> flags = getSavedFlags();
if (flags == null)
{
flags = new HashMap<>();
}
flags.put(flag, value);
try
{
final FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder(), SAVED_FLAGS_FILENAME));
final ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(flags);
oos.close();
fos.close();
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
}

View File

@ -1,19 +1,12 @@
package me.totalfreedom.totalfreedommod;
import java.util.Arrays;
import java.util.List;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.minecraft.server.v1_9_R1.EntityPlayer;
import net.minecraft.server.v1_9_R1.MinecraftServer;
import net.minecraft.server.v1_9_R1.PropertyManager;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
public class ServerInterface extends FreedomService
{
public static final String COMPILE_NMS_VERSION = "v1_9_R1";
public static final String COMPILE_NMS_VERSION = "v1_12_R1";
public ServerInterface(TotalFreedomMod plugin)
{
@ -41,52 +34,52 @@ public class ServerInterface extends FreedomService
}
}
public void setOnlineMode(boolean mode)
{
final PropertyManager manager = getServer().getPropertyManager();
manager.setProperty("online-mode", mode);
manager.savePropertiesFile();
}
public int purgeWhitelist()
{
String[] whitelisted = getServer().getPlayerList().getWhitelisted();
int size = whitelisted.length;
for (EntityPlayer player : getServer().getPlayerList().players)
{
getServer().getPlayerList().getWhitelist().remove(player.getProfile());
}
try
{
getServer().getPlayerList().getWhitelist().save();
}
catch (Exception ex)
{
FLog.warning("Could not purge the whitelist!");
FLog.warning(ex);
}
return size;
}
public boolean isWhitelisted()
{
return getServer().getPlayerList().getHasWhitelist();
}
public List<?> getWhitelisted()
{
return Arrays.asList(getServer().getPlayerList().getWhitelisted());
}
public String getVersion()
{
return getServer().getVersion();
}
private MinecraftServer getServer()
{
return ((CraftServer) Bukkit.getServer()).getServer();
}
// public void setOnlineMode(boolean mode)
// {
// final PropertyManager manager = getServer().getPropertyManager();
// manager.setProperty("online-mode", mode);
// manager.savePropertiesFile();
// }
//
// public int purgeWhitelist()
// {
// String[] whitelisted = getServer().getPlayerList().getWhitelisted();
// int size = whitelisted.length;
// for (EntityPlayer player : getServer().getPlayerList().players)
// {
// getServer().getPlayerList().getWhitelist().remove(player.getProfile());
// }
//
// try
// {
// getServer().getPlayerList().getWhitelist().save();
// }
// catch (Exception ex)
// {
// FLog.warning("Could not purge the whitelist!");
// FLog.warning(ex);
// }
// return size;
// }
//
// public boolean isWhitelisted()
// {
// return getServer().getPlayerList().getHasWhitelist();
// }
//
// public List<?> getWhitelisted()
// {
// return Arrays.asList(getServer().getPlayerList().getWhitelisted());
// }
//
// public String getVersion()
// {
// return getServer().getVersion();
// }
//
// private MinecraftServer getServer()
// {
// return ((CraftServer) Bukkit.getServer()).getServer();
// }
}

View File

@ -55,22 +55,25 @@ public class ServerPing extends FreedomService
return;
}
// String baseMotd = ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion());
String baseMotd = ConfigEntry.SERVER_MOTD.getString();
baseMotd = baseMotd.replace("\\n", "\n");
baseMotd = FUtil.colorize(baseMotd);
if (!ConfigEntry.SERVER_COLORFUL_MOTD.getBoolean())
{
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_MOTD.getString()
.replace("%mcversion%", plugin.si.getVersion())));
event.setMotd(baseMotd);
return;
}
// Colorful MOTD
final StringBuilder motd = new StringBuilder();
for (String word : ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion()).split(" "))
for (String word : baseMotd.split(" "))
{
motd.append(FUtil.randomChatColor()).append(word).append(" ");
}
event.setMotd(FUtil.colorize(motd.toString()));
event.setMotd(motd.toString().trim());
}
}

View File

@ -1,236 +0,0 @@
package me.totalfreedom.totalfreedommod;
import com.google.common.collect.Maps;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class ServiceChecker extends FreedomService
{
public static final long SERVICE_CHECKER_RATE = 120L;
@Getter
private final Map<String, ServiceStatus> services = Maps.newHashMap();
//
private BukkitTask task;
private URL url = null;
@Getter
private String lastCheck = "Never";
@Getter
private String version = "Mojang";
public ServiceChecker(TotalFreedomMod plugin)
{
super(plugin);
services.put("minecraft.net", new ServiceStatus("Minecraft.net"));
services.put("account.mojang.com", new ServiceStatus("Mojang Account Website"));
services.put("authserver.mojang.com", new ServiceStatus("Mojang Authentication"));
services.put("sessionserver.mojang.com", new ServiceStatus("Mojang Multiplayer sessions"));
services.put("skins.minecraft.net", new ServiceStatus("Minecraft Skins"));
services.put("auth.mojang.com", new ServiceStatus("Mojang Authentiation (Legacy)"));
services.put("session.minecraft.net", new ServiceStatus("Minecraft Sessions (Legacy)"));
}
@Override
protected void onStart()
{
final String serviceCheckerURL = ConfigEntry.SERVICE_CHECKER_URL.getString();
if (serviceCheckerURL == null || serviceCheckerURL.isEmpty())
{
return;
}
try
{
url = new URL(serviceCheckerURL);
}
catch (MalformedURLException ex)
{
FLog.severe("Invalid ServiceChecker URL, disabling service checker");
return;
}
task = getUpdateRunnable().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 40L, SERVICE_CHECKER_RATE * 20L);
}
@Override
protected void onStop()
{
try
{
task.cancel();
}
catch (Exception ex)
{
}
finally
{
task = null;
}
}
public BukkitRunnable getUpdateRunnable()
{
return new BukkitRunnable()
{
@Override
public void run()
{
if (url == null)
{
return;
}
final JSONArray statusJson;
try
{
final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
statusJson = (JSONArray) JSONValue.parse(in.readLine());
in.close();
}
catch (Exception ex)
{
FLog.severe("Error updating mojang services from " + url);
FLog.severe(ex);
return;
}
final Iterator status = statusJson.iterator();
while (status.hasNext())
{
final Iterator serviceIt = ((JSONObject) status.next()).entrySet().iterator();
while (serviceIt.hasNext())
{
@SuppressWarnings("unchecked")
final Entry<String, String> pair = (Entry<String, String>) serviceIt.next();
if ("lastcheck".equals(pair.getKey()))
{
lastCheck = pair.getValue();
continue;
}
if ("version".equals(pair.getKey()))
{
version = pair.getValue();
continue;
}
final ServiceStatus service = services.get(pair.getKey());
if (service == null)
{
continue;
}
if (pair.getValue().contains(":"))
{
String[] statusString = pair.getValue().split(":");
service.setColor(statusString[0]);
service.setMessage(statusString[1]);
service.setUptime(statusString[2]);
}
else
{
service.setColor(pair.getValue());
service.setMessage(("red".equals(pair.getValue()) ? "Offline" : ("yellow".equals(pair.getValue()) ? "Problem" : "Online")));
}
}
}
if (lastCheck.equals("Unknown"))
{
lastCheck = FUtil.dateToString(new Date());
}
}
};
}
public List<ServiceStatus> getAllStatuses()
{
List<ServiceStatus> servicesList = new ArrayList<>();
for (String key : services.keySet())
{
servicesList.add(services.get(key));
}
return servicesList;
}
public class ServiceStatus
{
@Getter
private final String name;
@Getter
@Setter
private String uptime = "100.0"; // skins.minecraft.net, minecraft.net, etc..
@Getter
private ChatColor color = ChatColor.DARK_GREEN;
@Getter
@Setter
private String message = "Online"; // Online, Offline, Quite Slow, 404 Error, 500 Error, etc..
public ServiceStatus(String name)
{
this.name = name;
}
public float getUptimeFloat()
{
return Float.parseFloat(uptime);
}
public ChatColor getUptimeColor()
{
return (getUptimeFloat() > 95 ? ChatColor.GREEN : (getUptimeFloat() > 90 ? ChatColor.GOLD : ChatColor.RED));
}
public String getFormattedStatus()
{
String status = ChatColor.BLUE + "- " + ChatColor.GRAY + name + ChatColor.WHITE + ": " + color + message + ChatColor.WHITE;
if (!version.contains("Mojang"))
{
status += " (" + getUptimeColor() + getUptime() + ChatColor.WHITE + "%)";
}
return status;
}
public void setColor(String color)
{
if ("green".equals(color))
{
this.color = ChatColor.DARK_GREEN;
}
else if ("yellow".equals(color))
{
this.color = ChatColor.YELLOW;
}
else
{
this.color = ChatColor.RED;
}
}
}
}

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod;
import me.totalfreedom.totalfreedommod.fun.Trailer;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -11,12 +12,15 @@ import me.totalfreedom.totalfreedommod.blocking.BlockBlocker;
import me.totalfreedom.totalfreedommod.blocking.EventBlocker;
import me.totalfreedom.totalfreedommod.blocking.InteractBlocker;
import me.totalfreedom.totalfreedommod.blocking.MobBlocker;
import me.totalfreedom.totalfreedommod.blocking.PotionBlocker;
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge;
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
import me.totalfreedom.totalfreedommod.caging.Cager;
import me.totalfreedom.totalfreedommod.command.CommandLoader;
import me.totalfreedom.totalfreedommod.config.MainConfig;
import me.totalfreedom.totalfreedommod.freeze.Freezer;
import me.totalfreedom.totalfreedommod.fun.ItemFun;
import me.totalfreedom.totalfreedommod.fun.Jumppads;
@ -28,9 +32,12 @@ import me.totalfreedom.totalfreedommod.rank.RankManager;
import me.totalfreedom.totalfreedommod.rollback.RollbackManager;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.util.MethodTimer;
import me.totalfreedom.totalfreedommod.world.WorldManager;
import net.pravian.aero.component.service.ServiceManager;
import net.pravian.aero.plugin.AeroPlugin;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.mcstats.Metrics;
@ -41,33 +48,35 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
//
public static final BuildProperties build = new BuildProperties();
//
@SuppressWarnings("FieldNameHidesFieldInSuperclass")
public static TotalFreedomMod plugin;
public static String pluginName;
public static String pluginVersion;
//
public MainConfig config;
//
// Services
public ServiceManager<TotalFreedomMod> services;
public ServerInterface si;
public SavedFlags sf;
public WorldManager wm;
public LogViewer lv;
public AdminList al;
public RankManager rm;
public CommandLoader cl;
public CommandBlocker cb;
public EventBlocker eb;
public BlockBlocker bb;
public MobBlocker mb;
public InteractBlocker ib;
public PotionBlocker pb;
public LoginProcess lp;
public AntiNuke nu;
public AntiSpam as;
public RankManager rm;
public PlayerList pl;
public CommandLoader cl;
public CommandBlocker cb;
public Announcer an;
public ChatManager cm;
public BanManager bm;
public PermbanList pb;
public PermbanList pm;
public ProtectArea pa;
public ServiceChecker sc;
public GameRuleHandler gr;
public RollbackManager rb;
public CommandSpy cs;
@ -77,6 +86,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
public Muter mu;
public Fuckoff fo;
public AutoKick ak;
public AutoEject ae;
public MovementValidator mv;
public EntityWiper ew;
public FrontDoor fd;
@ -85,37 +95,36 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
public Landminer lm;
public MP44 mp;
public Jumppads jp;
public Trailer tr;
public HTTPDaemon hd;
//
// Bridges
public ServiceManager<TotalFreedomMod> bridges;
public BukkitTelnetBridge btb;
public EssentialsBridge esb;
public LibsDisguisesBridge ldb;
public WorldEditBridge web;
@Override
public void load()
{
TotalFreedomMod.plugin = this;
TotalFreedomMod.pluginName = plugin.getDescription().getName();
TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion();
FLog.setPluginLogger(plugin.getLogger());
FLog.setServerLogger(server.getLogger());
build.load();
build.load(plugin);
}
@Override
public void enable()
{
TotalFreedomMod.plugin = this;
FLog.info("Created by Madgeek1450 and Prozza");
FLog.info("Version " + build.formattedVersion());
FLog.info("Compiled " + build.date + " by " + build.author);
final FUtil.MethodTimer timer = new FUtil.MethodTimer();
final MethodTimer timer = new MethodTimer();
timer.start();
// Warn if we're running on a wrong version
@ -128,33 +137,39 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
// Convert old config files
new ConfigConverter(plugin).convert();
FUtil.createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
FUtil.createBackups(AdminList.CONFIG_FILENAME);
FUtil.createBackups(PermbanList.CONFIG_FILENAME);
BackupManager backups = new BackupManager(this);
backups.createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
backups.createBackups(AdminList.CONFIG_FILENAME);
backups.createBackups(PermbanList.CONFIG_FILENAME);
config = new MainConfig(this);
config.load();
// Start services
services = new ServiceManager<>(plugin);
si = services.registerService(ServerInterface.class);
sf = services.registerService(SavedFlags.class);
wm = services.registerService(WorldManager.class);
lv = services.registerService(LogViewer.class);
al = services.registerService(AdminList.class);
rm = services.registerService(RankManager.class);
cl = services.registerService(CommandLoader.class);
cb = services.registerService(CommandBlocker.class);
eb = services.registerService(EventBlocker.class);
bb = services.registerService(BlockBlocker.class);
mb = services.registerService(MobBlocker.class);
ib = services.registerService(InteractBlocker.class);
pb = services.registerService(PotionBlocker.class);
lp = services.registerService(LoginProcess.class);
nu = services.registerService(AntiNuke.class);
as = services.registerService(AntiSpam.class);
rm = services.registerService(RankManager.class);
pl = services.registerService(PlayerList.class);
cl = services.registerService(CommandLoader.class);
cb = services.registerService(CommandBlocker.class);
an = services.registerService(Announcer.class);
cm = services.registerService(ChatManager.class);
bm = services.registerService(BanManager.class);
pb = services.registerService(PermbanList.class);
pm = services.registerService(PermbanList.class);
pa = services.registerService(ProtectArea.class);
sc = services.registerService(ServiceChecker.class);
gr = services.registerService(GameRuleHandler.class);
// Single admin utils
@ -166,6 +181,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
mu = services.registerService(Muter.class);
fo = services.registerService(Fuckoff.class);
ak = services.registerService(AutoKick.class);
ae = services.registerService(AutoEject.class);
mv = services.registerService(MovementValidator.class);
ew = services.registerService(EntityWiper.class);
@ -177,6 +193,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
lm = services.registerService(Landminer.class);
mp = services.registerService(MP44.class);
jp = services.registerService(Jumppads.class);
tr = services.registerService(Trailer.class);
// HTTPD
hd = services.registerService(HTTPDaemon.class);
@ -186,6 +203,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
bridges = new ServiceManager<>(plugin);
btb = bridges.registerService(BukkitTelnetBridge.class);
esb = bridges.registerService(EssentialsBridge.class);
ldb = bridges.registerService(LibsDisguisesBridge.class);
web = bridges.registerService(WorldEditBridge.class);
bridges.start();
@ -224,29 +242,31 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
server.getScheduler().cancelTasks(plugin);
FLog.info("Plugin disabled");
TotalFreedomMod.plugin = null;
}
public static class BuildProperties
{
public String author;
public String codename;
public String version;
public String number;
public String date;
public String head;
public void load()
public void load(TotalFreedomMod plugin)
{
try
{
final InputStream in = plugin.getResource("build.properties");
final Properties props = new Properties();
final Properties props;
try (InputStream in = plugin.getResource("build.properties"))
{
props = new Properties();
props.load(in);
in.close();
}
author = props.getProperty("program.build.author", "unknown");
codename = props.getProperty("program.build.codename", "unknown");
version = props.getProperty("program.build.version", "unknown");
number = props.getProperty("program.build.number", "1");
date = props.getProperty("program.build.date", "unknown");
@ -254,7 +274,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
}
catch (Exception ex)
{
FLog.severe("Could not load build properties! Did you compile with Netbeans/ANT?");
FLog.severe("Could not load build properties! Did you compile with Netbeans/Maven?");
FLog.severe(ex);
}
}
@ -265,4 +285,16 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
}
}
public static TotalFreedomMod plugin()
{
for (Plugin plugin : Bukkit.getPluginManager().getPlugins())
{
if (plugin.getName().equalsIgnoreCase(pluginName))
{
return (TotalFreedomMod) plugin;
}
}
return null;
}
}

View File

@ -5,6 +5,8 @@ import java.util.Date;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.base.ConfigLoadable;
@ -25,7 +27,6 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
@Setter
private String name;
@Getter
@Setter
private boolean active = true;
@Getter
@Setter
@ -57,7 +58,6 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
final StringBuilder output = new StringBuilder();
output.append("Admin: ").append(name).append("\n")
.append("- Last Login Name: ").append(name).append("\n")
.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n")
.append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n")
.append("- Custom Login Message: ").append(loginMessage).append("\n")
@ -139,6 +139,26 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable
ips.clear();
}
public void setActive(boolean active)
{
this.active = active;
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
if (!active)
{
if (getRank().isAtLeast(Rank.TELNET_ADMIN))
{
if (plugin.btb != null)
{
plugin.btb.killTelnetSessions(getName());
}
}
plugin.lv.updateLogsRegistration(null, getName(), LogsRegistrationMode.DELETE);
}
}
@Override
public boolean isValid()
{

View File

@ -10,22 +10,16 @@ import java.util.concurrent.TimeUnit;
import lombok.Getter;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.command.Command_logs;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.config.YamlConfig;
import net.pravian.aero.util.Ips;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.ServicePriority;
public class AdminList extends FreedomService
@ -47,7 +41,7 @@ public class AdminList extends FreedomService
{
super(plugin);
this.config = new YamlConfig(TotalFreedomMod.plugin, CONFIG_FILENAME, true);
this.config = new YamlConfig(plugin, CONFIG_FILENAME, true);
}
@Override
@ -100,7 +94,7 @@ public class AdminList extends FreedomService
}
updateTables();
FLog.info("Loaded " + nameTable.size() + " admins (" + nameTable.size() + " active) and " + ipTable.size() + " IPs.");
FLog.info("Loaded " + allAdmins.size() + " admins (" + nameTable.size() + " active, " + ipTable.size() + " IPs)");
}
public void save()
@ -119,17 +113,6 @@ public class AdminList extends FreedomService
config.save();
}
public void save(Admin admin)
{
if (!allAdmins.values().contains(admin))
{ // Ensure admin is present
addAdmin(admin, false);
}
admin.saveTo(config.createSection(admin.getConfigKey()));
config.save();
}
public synchronized boolean isAdminSync(CommandSender sender)
{
return isAdmin(sender);
@ -142,7 +125,9 @@ public class AdminList extends FreedomService
return true;
}
return getAdmin((Player) sender) != null;
Admin admin = getAdmin((Player) sender);
return admin != null && admin.isActive();
}
public boolean isSeniorAdmin(CommandSender sender)
@ -168,22 +153,41 @@ public class AdminList extends FreedomService
public Admin getAdmin(Player player)
{
// Find admin
String ip = Ips.getIp(player);
Admin admin = getEntryByIp(ip, true);
Admin admin = getEntryByName(player.getName());
if (admin == null && Bukkit.getOnlineMode())
{
admin = getEntryByName(player.getName());
// Add new IP
// Admin by name
if (admin != null)
{
// Check if we're in online mode,
// Or the players IP is in the admin entry
if (Bukkit.getOnlineMode() || admin.getIps().contains(ip))
{
if (!admin.getIps().contains(ip))
{
// Add the new IP if we have to
admin.addIp(ip);
save(admin);
save();
updateTables();
}
return admin;
}
return admin;
// Impostor
}
// Admin by ip
admin = getEntryByIp(ip);
if (admin != null)
{
// Set the new username
admin.setName(player.getName());
save();
updateTables();
}
return null;
}
public Admin getEntryByName(String name)
@ -193,16 +197,15 @@ public class AdminList extends FreedomService
public Admin getEntryByIp(String ip)
{
return getEntryByIp(ip, false);
return ipTable.get(ip);
}
public Admin getEntryByIp(String needleIp, boolean fuzzy)
public Admin getEntryByIpFuzzy(String needleIp)
{
Admin admin = ipTable.get(needleIp);
if (admin != null || !fuzzy)
final Admin directAdmin = getEntryByIp(needleIp);
if (directAdmin != null)
{
return admin;
return directAdmin;
}
for (String ip : ipTable.keySet())
@ -212,7 +215,8 @@ public class AdminList extends FreedomService
return ipTable.get(ip);
}
}
return admin;
return null;
}
public void updateLastLogin(Player player)
@ -225,7 +229,7 @@ public class AdminList extends FreedomService
admin.setLastLogin(new Date());
admin.setName(player.getName());
save(admin);
save();
}
public boolean isAdminImpostor(Player player)
@ -245,11 +249,6 @@ public class AdminList extends FreedomService
}
public boolean addAdmin(Admin admin)
{
return addAdmin(admin, false);
}
public boolean addAdmin(Admin admin, boolean overwrite)
{
if (!admin.isValid())
{
@ -259,11 +258,6 @@ public class AdminList extends FreedomService
final String key = admin.getConfigKey();
if (!overwrite && allAdmins.containsKey(key))
{
return false;
}
// Store admin, update views
allAdmins.put(key, admin);
updateTables();
@ -277,6 +271,14 @@ public class AdminList extends FreedomService
public boolean removeAdmin(Admin admin)
{
if (admin.getRank().isAtLeast(Rank.TELNET_ADMIN))
{
if (plugin.btb != null)
{
plugin.btb.killTelnetSessions(admin.getName());
}
}
// Remove admin, update views
if (allAdmins.remove(admin.getConfigKey()) == null)
{
@ -327,28 +329,6 @@ public class AdminList extends FreedomService
return ipTable.keySet();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
final Player player = event.getPlayer();
final FPlayer fPlayer = plugin.pl.getPlayer(player);
if (plugin.al.isAdmin(player))
{
// Verify strict IP match
if (plugin.al.isIdentityMatched(player))
{
fPlayer.setSuperadminIdVerified(true);
plugin.al.updateLastLogin(player);
}
else
{
fPlayer.setSuperadminIdVerified(false);
FUtil.bcastMsg("Warning: " + player.getName() + " is an admin, but is using an account not registered to one of their ip-list.", ChatColor.RED);
}
}
}
public void deactivateOldEntries(boolean verbose)
{
for (Admin admin : allAdmins.values())
@ -372,7 +352,6 @@ public class AdminList extends FreedomService
}
admin.setActive(false);
Command_logs.deactivateSuperadmin(admin);
}
save();

View File

@ -67,6 +67,7 @@ public class Ban implements ConfigLoadable, ConfigSavable, Validatable
dedupeIps();
this.by = by;
this.expiryUnix = FUtil.getUnixTime(expire);
this.reason = reason;
}
//

View File

@ -36,7 +36,7 @@ public class BanManager extends FreedomService
public BanManager(TotalFreedomMod plugin)
{
super(plugin);
this.config = new YamlConfig(TotalFreedomMod.plugin, "bans.yml");
this.config = new YamlConfig(plugin, "bans.yml");
}
@Override

View File

@ -36,7 +36,7 @@ public class PermbanList extends FreedomService
permbannedNames.clear();
permbannedIps.clear();
final YamlConfig config = new YamlConfig(TotalFreedomMod.plugin, CONFIG_FILENAME, true);
final YamlConfig config = new YamlConfig(plugin, CONFIG_FILENAME, true);
config.load();
for (String name : config.getKeys(false))

View File

@ -108,6 +108,14 @@ public class BlockBlocker extends FreedomService
}
break;
}
case STRUCTURE_BLOCK:
case STRUCTURE_VOID:
{
player.sendMessage(ChatColor.GRAY + "Structure blocks are disabled.");
event.setCancelled(true);
break;
}
}
}

View File

@ -33,9 +33,6 @@ public class InteractBlocker extends FreedomService
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event)
{
final Player player = event.getPlayer();
final FPlayer playerdata = plugin.pl.getPlayer(player);
switch (event.getAction())
{
case RIGHT_CLICK_AIR:
@ -98,6 +95,14 @@ public class InteractBlocker extends FreedomService
event.setCancelled(true);
break;
}
case SIGN:
case SIGN_POST:
case WALL_SIGN:
{
player.sendMessage(ChatColor.GRAY + "Sign interaction is currently disabled.");
break;
}
}
}
}

View File

@ -0,0 +1,62 @@
package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.projectiles.ProjectileSource;
public class PotionBlocker extends FreedomService
{
public static final int POTION_BLOCK_RADIUS_SQUARED = 20 * 20;
public PotionBlocker(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onThrowPotion(PotionSplashEvent event)
{
ProjectileSource source = event.getEntity().getShooter();
if (!(source instanceof Player))
{
event.setCancelled(true);
return;
}
Player thrower = (Player) source;
if (plugin.al.isAdmin(thrower))
{
return;
}
for (Player player : thrower.getWorld().getPlayers())
{
if (thrower.getLocation().distanceSquared(player.getLocation()) < POTION_BLOCK_RADIUS_SQUARED)
{
thrower.sendMessage(ChatColor.RED + "You cannot use splash potions close to other players.");
event.setCancelled(true);
return;
}
}
}
}

View File

@ -1,6 +1,7 @@
package me.totalfreedom.totalfreedommod.blocking.command;
import lombok.Getter;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -38,7 +39,7 @@ public class CommandBlockerEntry
{
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
{
FUtil.autoEject((Player) sender, "You used a prohibited command: " + command);
TotalFreedomMod.plugin().ae.autoEject((Player) sender, "You used a prohibited command: " + command);
FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
return;
}

View File

@ -40,7 +40,7 @@ public enum CommandBlockerRank
return TELNET;
}
Admin admin = TotalFreedomMod.plugin.al.getAdmin(sender);
Admin admin = TotalFreedomMod.plugin().al.getAdmin(sender);
if (admin != null)
{
if (admin.getRank() == Rank.SENIOR_ADMIN)

View File

@ -1,21 +1,29 @@
package me.totalfreedom.totalfreedommod.bridge;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import me.totalfreedom.bukkittelnet.BukkitTelnet;
import me.totalfreedom.bukkittelnet.api.TelnetCommandEvent;
import me.totalfreedom.bukkittelnet.api.TelnetPreLoginEvent;
import me.totalfreedom.bukkittelnet.api.TelnetRequestDataTagsEvent;
import me.totalfreedom.bukkittelnet.session.ClientSession;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.plugin.Plugin;
public class BukkitTelnetBridge extends FreedomService
{
private BukkitTelnet bukkitTelnetPlugin = null;
public BukkitTelnetBridge(TotalFreedomMod plugin)
{
super(plugin);
@ -41,9 +49,9 @@ public class BukkitTelnetBridge extends FreedomService
return;
}
final Admin admin = plugin.al.getEntryByIp(ip, true);
final Admin admin = plugin.al.getEntryByIpFuzzy(ip);
if (admin == null || !admin.isActive() || !admin.getRank().hasConsole())
if (admin == null || !admin.isActive() || !admin.getRank().hasConsoleVariant())
{
return;
}
@ -94,4 +102,69 @@ public class BukkitTelnetBridge extends FreedomService
playerTags.put("tfm.essentialsBridge.getNickname", plugin.esb.getNickname(player.getName()));
}
}
public BukkitTelnet getBukkitTelnetPlugin()
{
if (bukkitTelnetPlugin == null)
{
try
{
final Plugin bukkitTelnet = server.getPluginManager().getPlugin("BukkitTelnet");
if (bukkitTelnet != null)
{
if (bukkitTelnet instanceof BukkitTelnet)
{
bukkitTelnetPlugin = (BukkitTelnet) bukkitTelnet;
}
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
return bukkitTelnetPlugin;
}
public void killTelnetSessions(final String name)
{
try
{
final List<ClientSession> sessionsToRemove = new ArrayList<>();
final BukkitTelnet telnet = getBukkitTelnetPlugin();
if (telnet != null)
{
final Iterator<ClientSession> it = telnet.appender.getSessions().iterator();
while (it.hasNext())
{
final ClientSession session = it.next();
if (name != null && name.equalsIgnoreCase(session.getUserName()))
{
sessionsToRemove.add(session);
}
}
for (final ClientSession session : sessionsToRemove)
{
try
{
telnet.appender.removeSession(session);
session.syncTerminateSession();
}
catch (Exception ex)
{
FLog.severe("Error removing single telnet session: " + ex.getMessage());
}
}
FLog.info(sessionsToRemove.size() + " telnet session(s) removed.");
}
}
catch (Exception ex)
{
FLog.severe("Error removing telnet sessions: " + ex.getMessage());
}
}
}

View File

@ -0,0 +1,138 @@
package me.totalfreedom.totalfreedommod.bridge;
//import me.libraryaddict.disguise.DisallowedDisguises;
//import me.libraryaddict.disguise.LibsDisguises;
//import me.libraryaddict.disguise.DisguiseAPI;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.entity.Player;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class LibsDisguisesBridge extends FreedomService
{
// private LibsDisguises libsDisguisesPlugin = null;
public LibsDisguisesBridge(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
/*
public LibsDisguises getLibsDisguisesPlugin()
{
if (libsDisguisesPlugin == null)
{
try
{
final Plugin libsDisguises = server.getPluginManager().getPlugin("LibsDisguises");
if (libsDisguises != null)
{
if (libsDisguises instanceof LibsDisguises)
{
libsDisguisesPlugin = (LibsDisguises) libsDisguises;
}
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
return libsDisguisesPlugin;
}
public Boolean isDisguised(Player player)
{
try
{
final LibsDisguises libsDisguises = getLibsDisguisesPlugin();
if (libsDisguises != null)
{
return DisguiseAPI.isDisguised(player);
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
return null;
}
public void undisguiseAll(boolean admins)
{
try
{
final LibsDisguises libsDisguises = getLibsDisguisesPlugin();
if (libsDisguises == null)
{
return;
}
for (Player player : server.getOnlinePlayers())
{
if (DisguiseAPI.isDisguised(player))
{
if (!admins && plugin.al.isAdmin(player))
{
continue;
}
DisguiseAPI.undisguiseToAll(player);
}
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
public void setDisguisesEnabled(boolean state)
{
final LibsDisguises libsDisguises = getLibsDisguisesPlugin();
if (libsDisguises == null)
{
return;
}
if (state)
{
DisguiseAPI.enableDisguises();
}
else
{
DisguiseAPI.disableDisguises();
}
}
public boolean isDisguisesEnabled()
{
return !DisallowedDisguises.disabled;
}
public boolean isPluginEnabled()
{
Plugin ld = getLibsDisguisesPlugin();
if (ld == null)
{
return false;
}
return ld.isEnabled();
}*/
}

View File

@ -2,8 +2,16 @@ package me.totalfreedom.totalfreedommod.bridge;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.worldedit.LimitChangedEvent;
import me.totalfreedom.worldedit.SelectionChangedEvent;
// These imports are not in the latest releases of WorldEdit, and the new versions of WorldEdit do not build properly. This will need to be reverted once the new WorldEdit builds are building properly.
//
//import me.totalfreedom.worldedit.LimitChangedEvent;
//import me.totalfreedom.worldedit.SelectionChangedEvent;
//
//The following two imports are a temporary measure as mentioned above.
//
import me.StevenLawson.worldedit.LimitChangedEvent;
import me.StevenLawson.worldedit.SelectionChangedEvent;
//
import net.pravian.aero.component.PluginListener;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

View File

@ -13,6 +13,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerKickEvent;
public class Cager extends FreedomService
{
@ -95,6 +96,18 @@ public class Cager extends FreedomService
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerKick(PlayerKickEvent event)
{
FPlayer player = plugin.pl.getPlayer(event.getPlayer());
CageData cage = player.getCageData();
if (cage.isCaged())
{
cage.playerQuit();
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent event)
{

View File

@ -24,7 +24,7 @@ public class CommandLoader extends FreedomService
protected void onStart()
{
handler.clearCommands();
handler.setExecutorFactory(new FreedomCommandExecutor.FreedomExecutorFactory());
handler.setExecutorFactory(new FreedomCommandExecutor.FreedomExecutorFactory(plugin));
handler.setCommandClassPrefix("Command_");
handler.setPermissionMessage(ChatColor.RED + "You do not have permission to use this command.");
handler.setOnlyConsoleMessage(ChatColor.RED + "This command can only be used from the console.");

View File

@ -33,7 +33,7 @@ public class Command_adminchat extends FreedomCommand
}
else
{
FUtil.adminChatMessage(sender, StringUtils.join(args, " "));
plugin.cm.adminChat(sender, StringUtils.join(args, " "));
}
return true;

View File

@ -0,0 +1,56 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Quickly change your own gamemode to adventure, or define someone's username to change theirs.", usage = "/<command> <-a | [partialname]>", aliases = "gma")
public class Command_adventure extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
if (isConsole())
{
sender.sendMessage("When used from the console, you must define a target player.");
return true;
}
playerSender.setGameMode(GameMode.ADVENTURE);
msg("Gamemode set to adventure.");
return true;
}
if (args[0].equals("-a"))
{
for (Player targetPlayer : server.getOnlinePlayers())
{
targetPlayer.setGameMode(GameMode.ADVENTURE);
}
FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to adventure", false);
return true;
}
Player player = getPlayer(args[0]);
if (player == null)
{
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
msg("Setting " + player.getName() + " to game mode adventure");
msg(player, sender.getName() + " set your game mode to adventure");
player.setGameMode(GameMode.ADVENTURE);
return true;
}
}

View File

@ -0,0 +1,26 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Make an announcement", usage = "/<command> <message>")
public class Command_announce extends FreedomCommand
{
@Override
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
plugin.an.announce(StringUtils.join(args, " "));
return true;
}
}

View File

@ -3,12 +3,13 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Block all commands for a specific player.", usage = "/<command> <purge | <partialname>>", aliases = "blockcommands,blockcommand")
@CommandParameters(description = "Block all commands for a specific player.", usage = "/<command> <-a | purge | <player>>", aliases = "blockcommands,blockcommand,bc,bcmd")
public class Command_blockcmd extends FreedomCommand
{
@ -20,7 +21,7 @@ public class Command_blockcmd extends FreedomCommand
return false;
}
if (args[0].equalsIgnoreCase("purge"))
if (args[0].equals("purge"))
{
FUtil.adminAction(sender.getName(), "Unblocking commands for all players", true);
int counter = 0;
@ -37,6 +38,26 @@ public class Command_blockcmd extends FreedomCommand
return true;
}
if (args[0].equals("-a"))
{
FUtil.adminAction(sender.getName(), "Blocking commands for all non-admins", true);
int counter = 0;
for (Player player : server.getOnlinePlayers())
{
if (isAdmin(player))
{
continue;
}
counter += 1;
plugin.pl.getPlayer(player).setCommandsBlocked(true);
msg(player, "Your commands have been blocked by an admin.", ChatColor.RED);
}
msg("Blocked commands for " + counter + " players.");
return true;
}
final Player player = getPlayer(args[0]);
if (player == null)
@ -45,7 +66,7 @@ public class Command_blockcmd extends FreedomCommand
return true;
}
if (isAdmin(sender))
if (isAdmin(player))
{
msg(player.getName() + " is a Superadmin, and cannot have their commands blocked.");
return true;

View File

@ -12,15 +12,19 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Essentials Interface Command - Color your current nickname.", usage = "/<command> <color>")
public class Command_colorme extends FreedomCommand {
public class Command_colorme extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
if ("list".equalsIgnoreCase(args[0])) {
if ("list".equalsIgnoreCase(args[0]))
{
msg("Colors: " + StringUtils.join(FUtil.CHAT_COLOR_NAMES.keySet(), ", "));
return true;
}
@ -28,15 +32,18 @@ public class Command_colorme extends FreedomCommand {
final String needle = args[0].trim().toLowerCase();
ChatColor color = null;
final Iterator<Map.Entry<String, ChatColor>> it = FUtil.CHAT_COLOR_NAMES.entrySet().iterator();
while (it.hasNext()) {
while (it.hasNext())
{
final Map.Entry<String, ChatColor> entry = it.next();
if (entry.getKey().contains(needle)) {
if (entry.getKey().contains(needle))
{
color = entry.getValue();
break;
}
}
if (color == null) {
if (color == null)
{
msg("Invalid color: " + needle + " - Use \"/colorme list\" to list colors.");
return true;
}

View File

@ -8,37 +8,30 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Quickly change your own gamemode to creative, or define someone's username to change theirs.", usage = "/<command> [partialname]", aliases = "gmc")
@CommandParameters(description = "Quickly change your own gamemode to creative, or define someone's username to change theirs.", usage = "/<command> <-a | [partialname]>", aliases = "gmc")
public class Command_creative extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (senderIsConsole)
{
if (args.length == 0)
{
sender.sendMessage("When used from the console, you must define a target user to change gamemode on.");
return true;
}
}
Player player;
if (args.length == 0)
if (isConsole())
{
player = playerSender;
}
else
{
if (args[0].equalsIgnoreCase("-a"))
{
if (!isAdmin(sender))
{
noPerms();
sender.sendMessage("When used from the console, you must define a target player.");
return true;
}
playerSender.setGameMode(GameMode.CREATIVE);
msg("Gamemode set to creative.");
return true;
}
checkRank(Rank.SUPER_ADMIN);
if (args[0].equals("-a"))
{
for (Player targetPlayer : server.getOnlinePlayers())
{
targetPlayer.setGameMode(GameMode.CREATIVE);
@ -48,13 +41,7 @@ public class Command_creative extends FreedomCommand
return true;
}
if (!(senderIsConsole || isAdmin(sender)))
{
msg("Only superadmins can change other user's gamemode.");
return true;
}
player = getPlayer(args[0]);
Player player = getPlayer(args[0]);
if (player == null)
{
@ -62,10 +49,8 @@ public class Command_creative extends FreedomCommand
return true;
}
}
msg("Setting " + player.getName() + " to game mode 'Creative'.");
msg(player, sender.getName() + " set your game mode to 'Creative'.");
msg("Setting " + player.getName() + " to game mode creative");
msg(player, sender.getName() + " set your game mode to creative");
player.setGameMode(GameMode.CREATIVE);
return true;

View File

@ -0,0 +1,47 @@
package me.totalfreedom.totalfreedommod.command;
//import me.libraryaddict.disguise.DisallowedDisguises;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Toggle the disguise plugin", usage = "/<command>", aliases = "dtoggle")
public class Command_disguisetoggle extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{/*
if (!plugin.ldb.isPluginEnabled())
{
msg(ChatColor.RED + "LibsDisguises is not enabled.");
return true;
}
FUtil.adminAction(sender.getName(), (DisallowedDisguises.disabled ? "Enabling" : "Disabling") + " " +
"Disguises", false);
if (plugin.ldb.isDisguisesEnabled())
{
plugin.ldb.undisguiseAll(true);
plugin.ldb.setDisguisesEnabled(false);
}
else
{
plugin.ldb.setDisguisesEnabled(true);
}
msg("Disguises are now " + (!DisallowedDisguises.disabled ? "enabled." : "disabled."));
return true;
*/
msg("This command has been disabled for technical reasons. Contact a developer for additional information.");
return true;
}
}

View File

@ -13,7 +13,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters(description = "For the bad Superadmins", usage = "/<command> <playername>")
@CommandParameters(description = "For the bad admins", usage = "/<command> <playername>")
public class Command_doom extends FreedomCommand
{
@ -72,7 +72,7 @@ public class Command_doom extends FreedomCommand
player.setFireTicks(10000);
// Generate explosion
player.getWorld().createExplosion(player.getLocation(), 4F);
player.getWorld().createExplosion(player.getLocation(), 0F, false);
// Shoot the player in the sky
player.setVelocity(player.getVelocity().clone().add(new Vector(0, 20, 0)));
@ -99,7 +99,7 @@ public class Command_doom extends FreedomCommand
FUtil.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + ip, true);
// generate explosion
player.getWorld().createExplosion(player.getLocation(), 4F);
player.getWorld().createExplosion(player.getLocation(), 0F, false);
// kick player
player.kickPlayer(ChatColor.RED + "FUCKOFF, and get your shit together!");

View File

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
@ -21,11 +21,11 @@ public class Command_enchant extends FreedomCommand
return false;
}
ItemStack itemInHand = playerSender.getItemInHand();
ItemStack item = playerSender.getEquipment().getItemInMainHand();
if (itemInHand == null)
if (item == null || item.getType() == Material.AIR)
{
msg("You are holding an invalid item.");
msg("You have to hold an item to enchant it");
return true;
}
@ -36,7 +36,7 @@ public class Command_enchant extends FreedomCommand
StringBuilder possible_ench = new StringBuilder("Possible enchantments for held item: ");
for (Enchantment ench : Enchantment.values())
{
if (ench.canEnchantItem(itemInHand))
if (ench.canEnchantItem(item))
{
has_enchantments = true;
possible_ench.append(ench.getName()).append(", ");
@ -58,14 +58,14 @@ public class Command_enchant extends FreedomCommand
{
try
{
if (ench.canEnchantItem(itemInHand))
if (ench.canEnchantItem(item))
{
itemInHand.addEnchantment(ench, ench.getMaxLevel());
item.addEnchantment(ench, ench.getMaxLevel());
}
}
catch (Exception ex)
{
FLog.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + playerSender.getName() + ".");
msg("Could not add enchantment: " + ench.getName());
}
}
@ -73,9 +73,9 @@ public class Command_enchant extends FreedomCommand
}
else if (args[0].equalsIgnoreCase("reset"))
{
for (Enchantment ench : itemInHand.getEnchantments().keySet())
for (Enchantment ench : item.getEnchantments().keySet())
{
itemInHand.removeEnchantment(ench);
item.removeEnchantment(ench);
}
msg("Removed all enchantments.");
@ -105,9 +105,9 @@ public class Command_enchant extends FreedomCommand
if (args[0].equalsIgnoreCase("add"))
{
if (ench.canEnchantItem(itemInHand))
if (ench.canEnchantItem(item))
{
itemInHand.addEnchantment(ench, ench.getMaxLevel());
item.addEnchantment(ench, ench.getMaxLevel());
msg("Added enchantment: " + ench.getName());
}
@ -118,7 +118,7 @@ public class Command_enchant extends FreedomCommand
}
else if (args[0].equals("remove"))
{
itemInHand.removeEnchantment(ench);
item.removeEnchantment(ench);
msg("Removed enchantment: " + ench.getName());
}

View File

@ -14,7 +14,7 @@ public class Command_ender extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
FUtil.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_the_end");
plugin.wm.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_the_end");
return true;
}
}

View File

@ -15,7 +15,7 @@ public class Command_entitywipe extends FreedomCommand
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
FUtil.adminAction(sender.getName(), "Removing all server entities.", true);
msg((plugin.ew.wipeEntities(true, true)) + " entities removed.");
msg((plugin.ew.wipeEntities(true)) + " entities removed.");
return true;
}

View File

@ -29,8 +29,6 @@ public class Command_freeze extends FreedomCommand
}
FUtil.adminAction(sender.getName(), "Enabling global player freeze", false);
msg("Players are now frozen.");
for (Player player : server.getOnlinePlayers())
{
if (!isAdmin(player))
@ -38,6 +36,8 @@ public class Command_freeze extends FreedomCommand
msg(player, "You have been frozen due to rulebreakers, you will be unfrozen soon.", ChatColor.RED);
}
}
msg("Players are now frozen.");
return true;
}

View File

@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "You'll never even see it coming.", usage = "/<command>")
@CommandParameters(description = "You'll never even see it coming.", usage = "/<command> <on [radius (default=25)] | off>")
public class Command_fuckoff extends FreedomCommand
{

View File

@ -167,7 +167,7 @@ public class Command_gadmin extends FreedomCommand
case OP:
{
FUtil.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false);
target.setOp(false);
target.setOp(true);
target.sendMessage(FreedomCommand.YOU_ARE_OP);
break;

View File

@ -73,7 +73,7 @@ public class Command_glist extends FreedomCommand
final String reason = args.length > 2 ? StringUtils.join(args, " ", 2, args.length) : null;
Ban ban = Ban.forPlayerName(player, sender, null, reason);
Ban ban = Ban.forPlayerName(username, sender, null, reason);
for (String ip : ips)
{
ban.addIp(ip);

View File

@ -21,6 +21,7 @@ public class Command_gtfo extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
return false;

View File

@ -45,6 +45,12 @@ public class Command_health extends FreedomCommand
Thread.sleep(2500);
final double ticksPerSecond = tickMeter.stopTicking();
// Plugin was disabled during async task
if (!plugin.isEnabled())
{
return;
}
new BukkitRunnable()
{
@Override

View File

@ -11,20 +11,20 @@ import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Shows (optionally smites) invisisible players", usage = "/<command> (smite)")
@CommandParameters(description = "Shows (and optionally clears) invisisible players", usage = "/<command> [clear]")
public class Command_invis extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
boolean smite = false;
boolean clear = false;
if (args.length >= 1)
{
if (args[0].equalsIgnoreCase("smite"))
if (args[0].equalsIgnoreCase("clear"))
{
FUtil.adminAction(sender.getName(), "Smiting all invisible players", true);
smite = true;
FUtil.adminAction(sender.getName(), "Clearing invisibility for all players", false);
clear = true;
}
else
{
@ -33,17 +33,17 @@ public class Command_invis extends FreedomCommand
}
List<String> players = new ArrayList<>();
int smites = 0;
int clears = 0;
for (Player player : server.getOnlinePlayers())
{
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
{
players.add(player.getName());
if (smite && !plugin.al.isAdmin(player))
if (clear && !plugin.al.isAdmin(player))
{
player.setHealth(0.0);
smites++;
player.removePotionEffect(PotionEffectType.INVISIBILITY);
clears++;
}
}
}
@ -54,9 +54,9 @@ public class Command_invis extends FreedomCommand
return true;
}
if (smite)
if (clear)
{
msg("Smitten " + smites + " players");
msg("Cleared invisibility effect from " + clears + " players");
}
else
{

View File

@ -0,0 +1,61 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Kick a player.", usage = "/<command> <player> [reason]", aliases = "k")
public class Command_kick extends FreedomCommand
{
@Override
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
return false;
}
Player player = getPlayer(args[0]);
if (player == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
if (isAdmin(player))
{
msg("Admins can not be kicked", ChatColor.RED);
return true;
}
String reason = null;
if (args.length > 1)
{
reason = StringUtils.join(args, " ", 1, args.length);
}
StringBuilder builder = new StringBuilder()
.append(ChatColor.RED).append("You have been kicked from the server.")
.append("\n").append(ChatColor.RED).append("Kicked by: ").append(ChatColor.GOLD).append(sender.getName());
if (reason != null)
{
builder.append("\n").append(ChatColor.RED).append("Reason: ").append(ChatColor.GOLD).append(reason);
FUtil.adminAction(sender.getName(), "Kicking " + player.getName() + " - Reason: " + reason, true);
}
else
{
FUtil.adminAction(sender.getName(), "Kicking " + player.getName(), true);
}
player.kickPlayer(builder.toString());
return true;
}
}

View File

@ -2,6 +2,8 @@ package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils;
@ -10,16 +12,17 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i]", aliases = "who")
@CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.BOTH)
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i | -f]", aliases = "who")
public class Command_list extends FreedomCommand
{
private static enum ListFilter
{
ALL,
PLAYERS,
ADMINS,
FAMOUS_PLAYERS,
IMPOSTORS;
}
@ -45,22 +48,24 @@ public class Command_list extends FreedomCommand
final ListFilter listFilter;
if (args.length == 1)
{
if ("-a".equals(args[0]))
switch (args[0])
{
case "-a":
listFilter = ListFilter.ADMINS;
}
else if ("-i".equals(args[0]))
{
break;
case "-i":
listFilter = ListFilter.IMPOSTORS;
}
else
{
break;
case "-f":
listFilter = ListFilter.FAMOUS_PLAYERS;
break;
default:
return false;
}
}
else
{
listFilter = ListFilter.ALL;
listFilter = ListFilter.PLAYERS;
}
final StringBuilder onlineStats = new StringBuilder();
@ -83,11 +88,20 @@ public class Command_list extends FreedomCommand
continue;
}
names.add(plugin.rm.getDisplay(player).getColoredTag() + player.getName());
if (listFilter == ListFilter.FAMOUS_PLAYERS && !ConfigEntry.FAMOUS_PLAYERS.getList().contains(player.getName().toLowerCase()))
{
continue;
}
Displayable display = plugin.rm.getDisplay(player);
names.add(display.getColoredTag() + player.getName());
}
String playerType = listFilter == null ? "players" : listFilter.toString().toLowerCase().replace('_', ' ');
onlineUsers.append("Connected ");
onlineUsers.append(listFilter == ListFilter.ADMINS ? "admins: " : "players: ");
onlineUsers.append(playerType + ": ");
onlineUsers.append(StringUtils.join(names, ChatColor.WHITE + ", "));
if (senderIsConsole)

View File

@ -1,25 +1,10 @@
package me.totalfreedom.totalfreedommod.command;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Register your connection with the TFM logviewer.", usage = "/<command> [off]")
@ -29,141 +14,13 @@ public class Command_logs extends FreedomCommand
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
LogsRegistrationMode mode = LogsRegistrationMode.UPDATE;
if (args.length == 1)
LogsRegistrationMode mode = LogsRegistrationMode.ADD;
if (args.length == 1 && "off".equalsIgnoreCase(args[0]))
{
mode = ("off".equals(args[0]) ? LogsRegistrationMode.DELETE : LogsRegistrationMode.UPDATE);
mode = LogsRegistrationMode.DELETE;
}
updateLogsRegistration(sender, playerSender, mode);
plugin.lv.updateLogsRegistration(sender, playerSender, mode);
return true;
}
public static void updateLogsRegistration(final CommandSender sender, final Player target, final LogsRegistrationMode mode)
{
updateLogsRegistration(sender, target.getName(), target.getAddress().getAddress().getHostAddress().trim(), mode);
}
public static void updateLogsRegistration(final CommandSender sender, final String targetName, final String targetIP, final LogsRegistrationMode mode)
{
final String logsRegisterUrl = ConfigEntry.LOGS_URL.getString();
final String logsRegisterPassword = ConfigEntry.LOGS_SECRET.getString();
if (logsRegisterUrl == null || logsRegisterPassword == null || logsRegisterUrl.isEmpty() || logsRegisterPassword.isEmpty())
{
return;
}
new BukkitRunnable()
{
@Override
public void run()
{
try
{
if (sender != null)
{
sender.sendMessage(ChatColor.YELLOW + "Connecting...");
}
URL url = new URLBuilder(logsRegisterUrl)
.addQueryParameter("mode", mode.toString())
.addQueryParameter("password", logsRegisterPassword)
.addQueryParameter("name", targetName)
.addQueryParameter("ip", targetIP)
.getURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(1000 * 5);
connection.setReadTimeout(1000 * 5);
connection.setUseCaches(false);
connection.setRequestMethod("HEAD");
final int responseCode = connection.getResponseCode();
if (sender != null)
{
new BukkitRunnable()
{
@Override
public void run()
{
if (responseCode == 200)
{
sender.sendMessage(ChatColor.GREEN + "Registration " + mode.toString() + "d.");
}
else
{
sender.sendMessage(ChatColor.RED + "Error contacting logs registration server.");
}
}
}.runTask(TotalFreedomMod.plugin);
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
}.runTaskAsynchronously(TotalFreedomMod.plugin);
}
public static void deactivateSuperadmin(Admin superadmin)
{
for (String ip : superadmin.getIps())
{
updateLogsRegistration(null, superadmin.getName(), ip, Command_logs.LogsRegistrationMode.DELETE);
}
}
public static enum LogsRegistrationMode
{
UPDATE("update"), DELETE("delete");
private final String mode;
private LogsRegistrationMode(String mode)
{
this.mode = mode;
}
@Override
public String toString()
{
return mode;
}
}
private static class URLBuilder
{
private final String requestPath;
private final Map<String, String> queryStringMap = new HashMap<>();
public URLBuilder(String requestPath)
{
this.requestPath = requestPath;
}
public URLBuilder addQueryParameter(String key, String value)
{
queryStringMap.put(key, value);
return this;
}
public URL getURL() throws MalformedURLException
{
List<String> pairs = new ArrayList<>();
Iterator<Entry<String, String>> it = queryStringMap.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> pair = it.next();
pairs.add(pair.getKey() + "=" + pair.getValue());
}
return new URL(requestPath + "?" + StringUtils.join(pairs, "&"));
}
}
}

View File

@ -1,6 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
@ -21,7 +22,7 @@ public class Command_mobpurge extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
msg("Purging all mobs...");
FUtil.adminAction(sender.getName(), "Purging all mobs", true);
msg(purgeMobs() + " mobs removed.");
return true;
}

View File

@ -38,7 +38,7 @@ public class Command_mp44 extends FreedomCommand
msg("mp44 is ARMED! Left click with gunpowder to start firing, left click again to quit.", ChatColor.GREEN);
msg("Type /mp44 sling to disable. -by Madgeek1450", ChatColor.GREEN);
playerSender.setItemInHand(new ItemStack(Material.SULPHUR, 1));
playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.SULPHUR, 1));
}
else
{

View File

@ -0,0 +1,170 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Arrays;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.util.ChatUtils;
import net.pravian.aero.util.Ips;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Manage my admin entry", usage = "/<command> [-o <admin>] <clearips | clearip <ip> | setlogin <message> | clearlogin>")
public class Command_myadmin extends FreedomCommand
{
@Override
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
checkPlayer();
checkRank(Rank.SUPER_ADMIN);
if (args.length < 1)
{
return false;
}
Player init = null;
Admin target = getAdmin(playerSender);
Player targetPlayer = playerSender;
// -o switch
if (args[0].equals("-o"))
{
checkRank(Rank.SENIOR_ADMIN);
init = playerSender;
targetPlayer = getPlayer(args[1]);
if (targetPlayer == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
target = getAdmin(targetPlayer);
if (target == null)
{
msg("That player is not admin", ChatColor.RED);
return true;
}
// Shift 2
args = Arrays.copyOfRange(args, 2, args.length);
if (args.length < 1)
{
return false;
}
}
final String targetIp = Ips.getIp(targetPlayer);
switch (args[0])
{
case "clearips":
{
if (args.length != 1)
{
return false; // Double check: the player might mean "clearip"
}
if (init == null)
{
FUtil.adminAction(sender.getName(), "Clearing my supered IPs", true);
}
else
{
FUtil.adminAction(sender.getName(), "Clearing " + target.getName() + "' supered IPs", true);
}
int counter = target.getIps().size() - 1;
target.clearIPs();
target.addIp(targetIp);
plugin.al.save();
msg(counter + " IPs removed.");
msg(targetPlayer, target.getIps().get(0) + " is now your only IP address");
return true;
}
case "clearip":
{
if (args.length != 2)
{
return false; // Double check: the player might mean "clearips"
}
if (!target.getIps().contains(args[1]))
{
if (init == null)
{
msg("That IP is not registered to you.");
}
else
{
msg("That IP does not belong to that player.");
}
return true;
}
if (targetIp.equals(args[1]))
{
if (init == null)
{
msg("You cannot remove your current IP.");
}
else
{
msg("You cannot remove that admin's current IP.");
}
return true;
}
FUtil.adminAction(sender.getName(), "Removing a supered IP" + (init == null ? "" : " from " + targetPlayer.getName() + "'s IPs"), true);
target.removeIp(args[1]);
plugin.al.save();
plugin.al.updateTables();
msg("Removed IP " + args[1]);
msg("Current IPs: " + StringUtils.join(target.getIps(), ", "));
return true;
}
case "setlogin":
{
if (args.length < 2)
{
return false;
}
String msg = StringUtils.join(args, " ", 1, args.length);
FUtil.adminAction(sender.getName(), "Setting personal login message" + (init == null ? "" : " for " + targetPlayer.getName()), false);
target.setLoginMessage(msg);
msg((init == null ? "Your" : targetPlayer.getName() + "'s") + " login message is now: ");
msg("> " + ChatColor.AQUA + targetPlayer.getName() + " is " + ChatUtils.colorize(target.getLoginMessage()));
plugin.al.save();
plugin.al.updateTables();
return true;
}
case "clearlogin":
{
FUtil.adminAction(sender.getName(), "Clearing personal login message" + (init == null ? "" : " for " + targetPlayer.getName()), false);
target.setLoginMessage(null);
plugin.al.save();
plugin.al.updateTables();
return true;
}
default:
{
return false;
}
}
}
}

View File

@ -14,7 +14,7 @@ public class Command_nether extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
FUtil.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_nether");
plugin.wm.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_nether");
return true;
}
}

View File

@ -23,12 +23,12 @@ public class Command_nickclean extends FreedomCommand
ChatColor.UNDERLINE,
ChatColor.BLACK
};
private static final Pattern REGEX = Pattern.compile(ChatColor.COLOR_CHAR + "[" + StringUtils.join(BLOCKED, "") + "]");
private static final Pattern REGEX = Pattern.compile(ChatColor.COLOR_CHAR + "[" + StringUtils.join(BLOCKED, "") + "]", Pattern.CASE_INSENSITIVE);
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
FUtil.adminAction(sender.getName(), "Cleaning all nicknames.", false);
FUtil.adminAction(sender.getName(), "Cleaning all nicknames", false);
for (final Player player : server.getOnlinePlayers())
{

View File

@ -1,7 +1,6 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -44,26 +43,27 @@ public class Command_onlinemode extends FreedomCommand
return false;
}
try
{
plugin.si.setOnlineMode(onlineMode);
if (onlineMode)
{
for (Player player : server.getOnlinePlayers())
{
player.kickPlayer("Server is activating \"online-mode=true\". Please reconnect.");
}
}
FUtil.adminAction(sender.getName(), "Turning player validation " + (onlineMode ? "on" : "off") + ".", true);
server.reload();
}
catch (Exception ex)
{
FLog.severe(ex);
}
// try
// {
// plugin.si.setOnlineMode(onlineMode);
//
// if (onlineMode)
// {
// for (Player player : server.getOnlinePlayers())
// {
// player.kickPlayer("Server is activating \"online-mode=true\". Please reconnect.");
// }
// }
//
// FUtil.adminAction(sender.getName(), "Turning player validation " + (onlineMode ? "on" : "off") + ".", true);
//
// server.reload();
// }
// catch (Exception ex)
// {
// FLog.severe(ex);
// }
FUtil.adminAction(sender.getName(), "Online-Mode toggling is temporarily disabled.", true);
}
return true;

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Collection;
import java.util.List;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
@ -15,7 +16,7 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Overlord - control this server in-game", usage = "access", aliases = "ov")
public class Command_overlord extends FreedomCommand
public class Command_ov extends FreedomCommand
{
@Override
@ -25,8 +26,8 @@ public class Command_overlord extends FreedomCommand
{
try
{
List<?> ips = (List) MainConfig.getDefaults().get(ConfigEntry.OVERLORD_IPS.getConfigName());
if (!ips.contains(Ips.getIp(playerSender)))
Object ips = plugin.config.getDefaults().get(ConfigEntry.OVERLORD_IPS.getConfigName());
if (ips instanceof Collection && !((Collection) ips).contains(Ips.getIp(playerSender)))
{
throw new Exception();
}

View File

@ -25,11 +25,11 @@ public class Command_permban extends FreedomCommand
}
msg("Reloading permban list...", ChatColor.RED);
plugin.pb.stop();
plugin.pb.start();
plugin.pm.stop();
plugin.pm.start();
msg("Reloaded permban list.");
msg(plugin.pb.getPermbannedIps().size() + " IPs and "
+ plugin.pb.getPermbannedNames().size() + " usernames loaded.");
msg(plugin.pm.getPermbannedIps().size() + " IPs and "
+ plugin.pm.getPermbannedNames().size() + " usernames loaded.");
return true;
}

View File

@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH)
@CommandPermissions(level = Rank.TELNET_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Manage plugins", usage = "/<command> <<enable | disable | reload> <pluginname>> | list>", aliases = "plc")
public class Command_plugincontrol extends FreedomCommand
{

View File

@ -44,12 +44,19 @@ public class Command_premium extends FreedomCommand
{
try
{
final URL getUrl = new URL("https://minecraft.net/haspaid.jsp?user=" + name);
final URL getUrl = new URL("http://axis.iaero.me/accstatus?username=" + name + "&format=plain");
final URLConnection urlConnection = getUrl.openConnection();
// Read the response
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
final String message = ("false".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes");
in.close();
final String message;
try ( // Read the response
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())))
{
message = (!"PREMIUM".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes");
}
if (!plugin.isEnabled())
{
return;
}
new BukkitRunnable()
{

View File

@ -19,7 +19,7 @@ public class Command_purgeall extends FreedomCommand
FUtil.adminAction(sender.getName(), "Purging all player data", true);
// Purge entities
plugin.ew.wipeEntities(true, true);
plugin.ew.wipeEntities(true);
for (Player player : server.getOnlinePlayers())
{

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -14,26 +15,26 @@ public class Command_rank extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (senderIsConsole && args.length < 1)
if (isConsole() && args.length == 0)
{
for (Player player : server.getOnlinePlayers())
{
msg(player.getName() + " is " + plugin.rm.getDisplay(player).getColoredLoginMessage());
msg(message(player));
}
return true;
}
if (args.length == 0)
{
msg(message(playerSender));
return true;
}
if (args.length > 1)
{
return false;
}
if (args.length == 0)
{
msg(sender.getName() + " is " + plugin.rm.getDisplay(sender).getColoredLoginMessage(), ChatColor.AQUA);
return true;
}
final Player player = getPlayer(args[0]);
if (player == null)
@ -42,8 +43,33 @@ public class Command_rank extends FreedomCommand
return true;
}
msg(player.getName() + " is " + plugin.rm.getDisplay(player).getColoredLoginMessage(), ChatColor.AQUA);
msg(message(player));
return true;
}
public String message(Player player)
{
Displayable display = plugin.rm.getDisplay(player);
Rank rank = plugin.rm.getRank(player);
StringBuilder sb = new StringBuilder();
sb
.append(ChatColor.AQUA)
.append(player.getName())
.append(" is ")
.append(display.getColoredLoginMessage());
if (rank != display)
{
sb
.append(ChatColor.AQUA)
.append(" (")
.append(rank.getColoredName())
.append(ChatColor.AQUA)
.append(')');
}
return sb.toString();
}
}

View File

@ -46,7 +46,7 @@ public class Command_report extends FreedomCommand
}
String report = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
FUtil.reportAction(playerSender, player, report);
plugin.cm.reportAction(playerSender, player, report);
msg(ChatColor.GREEN + "Thank you, your report has been successfully logged.");

View File

@ -7,8 +7,10 @@ import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -42,9 +44,9 @@ public class Command_ro extends FreedomCommand
}
}
if (fromMaterial == null)
if (fromMaterial == null || fromMaterial == Material.AIR || !fromMaterial.isBlock())
{
msg("Invalid block: " + materialName, ChatColor.RED);
msg("Invalid material: " + materialName, ChatColor.RED);
return true;
}
@ -105,7 +107,7 @@ public class Command_ro extends FreedomCommand
for (final Material material : materials)
{
affected += FUtil.replaceBlocks(player.getLocation(), material, Material.AIR, radius);
affected += replaceBlocks(player.getLocation(), material, Material.AIR, radius);
}
}
}
@ -116,7 +118,7 @@ public class Command_ro extends FreedomCommand
for (Material material : materials)
{
FUtil.adminAction(sender.getName(), "Removing all " + names + " within " + radius + " blocks of " + targetPlayer.getName(), false);
affected += FUtil.replaceBlocks(targetPlayer.getLocation(), material, Material.AIR, radius);
affected += replaceBlocks(targetPlayer.getLocation(), material, Material.AIR, radius);
}
}
}
@ -125,4 +127,32 @@ public class Command_ro extends FreedomCommand
return true;
}
public static int replaceBlocks(Location center, Material fromMaterial, Material toMaterial, int radius)
{
int affected = 0;
Block centerBlock = center.getBlock();
for (int xOffset = -radius; xOffset <= radius; xOffset++)
{
for (int yOffset = -radius; yOffset <= radius; yOffset++)
{
for (int zOffset = -radius; zOffset <= radius; zOffset++)
{
Block block = centerBlock.getRelative(xOffset, yOffset, zOffset);
if (block.getType().equals(fromMaterial))
{
if (block.getLocation().distanceSquared(center) < (radius * radius))
{
block.setType(toMaterial);
affected++;
}
}
}
}
}
return affected;
}
}

View File

@ -13,7 +13,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Manage admins.", usage = "/<command> <list | clean | reload | clearme [ip] | setrank <username> <rank> | <add | remove | info> <username>>")
@CommandParameters(description = "Manage admins.", usage = "/<command> <list | clean | reload | | setrank <username> <rank> | <add | remove | info> <username>>")
public class Command_saconfig extends FreedomCommand
{
@ -37,6 +37,7 @@ public class Command_saconfig extends FreedomCommand
case "clean":
{
checkConsole();
checkRank(Rank.TELNET_ADMIN);
FUtil.adminAction(sender.getName(), "Cleaning admin list", true);
plugin.al.deactivateOldEntries(true);
@ -55,71 +56,30 @@ public class Command_saconfig extends FreedomCommand
return true;
}
case "clearme":
{
checkPlayer();
checkRank(Rank.SUPER_ADMIN);
final Admin admin = plugin.al.getAdmin(playerSender);
if (admin == null)
{
msg("Could not find your admin entry! Please notify a developer.", ChatColor.RED);
return true;
}
final String ip = Ips.getIp(playerSender);
if (args.length == 1)
{
FUtil.adminAction(sender.getName(), "Cleaning my supered IPs", true);
int counter = admin.getIps().size() - 1;
admin.clearIPs();
admin.addIp(ip);
plugin.al.save(admin);
msg(counter + " IPs removed.");
msg(admin.getIps().get(0) + " is now your only IP address");
}
else
{
if (!admin.getIps().contains(args[1]))
{
msg("That IP is not registered to you.");
}
else if (ip.equals(args[1]))
{
msg("You cannot remove your current IP.");
}
else
{
FUtil.adminAction(sender.getName(), "Removing a supered IP", true);
admin.removeIp(args[1]);
plugin.al.save(admin);
msg("Removed IP " + args[1]);
msg("Current IPs: " + StringUtils.join(admin.getIps(), ", "));
}
}
return true;
}
case "setrank":
{
checkConsole();
checkNotHostConsole();
checkRank(Rank.SENIOR_CONSOLE);
if (args.length < 3)
{
return false;
}
checkConsole();
checkRank(Rank.SENIOR_CONSOLE);
Rank rank = Rank.findRank(args[2]);
if (rank == null)
{
msg("Unknown rank: " + rank);
return true;
}
if (rank.isConsole())
{
msg("You cannot set players to a console rank");
return true;
}
if (!rank.isAtLeast(Rank.SUPER_ADMIN))
{
msg("Rank must be superadmin or higher.", ChatColor.RED);
@ -133,8 +93,10 @@ public class Command_saconfig extends FreedomCommand
return true;
}
FUtil.adminAction(sender.getName(), "Setting " + admin.getName() + "'s rank to " + rank.getName(), true);
admin.setRank(rank);
plugin.al.save(admin);
plugin.al.save();
msg("Set " + admin.getName() + "'s rank to " + rank.getName());
return true;
@ -182,16 +144,16 @@ public class Command_saconfig extends FreedomCommand
checkConsole();
checkRank(Rank.TELNET_ADMIN);
// Player already an admin?
final Player player = getPlayer(args[1]);
if (plugin.al.isAdmin(player))
if (player != null && plugin.al.isAdmin(player))
{
msg("That player is already admin.");
return true;
}
// Find the old admin entry
String name = player != null ? player.getName() : args[1];
Admin admin = null;
for (Admin loopAdmin : plugin.al.getAllAdmins().values())
{
@ -202,29 +164,8 @@ public class Command_saconfig extends FreedomCommand
}
}
if (admin != null) // Existing admin
if (admin == null) // New admin
{
FUtil.adminAction(sender.getName(), "Readding " + admin.getName() + " to the admin list", true);
if (player != null)
{
admin.loadFrom(player); // Reset IP, username
}
admin.setActive(true);
admin.setLastLogin(new Date());
if (player != null)
{
admin.addIp(Ips.getIp(player));
}
plugin.al.save(admin);
plugin.al.updateTables();
}
else // New admin
{
if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
@ -233,7 +174,22 @@ public class Command_saconfig extends FreedomCommand
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true);
plugin.al.addAdmin(new Admin(player));
}
else // Existing admin
{
FUtil.adminAction(sender.getName(), "Readding " + admin.getName() + " to the admin list", true);
if (player != null)
{
admin.setName(player.getName());
admin.addIp(Ips.getIp(player));
}
admin.setActive(true);
admin.setLastLogin(new Date());
plugin.al.save();
plugin.al.updateTables();
}
if (player != null)
@ -260,7 +216,7 @@ public class Command_saconfig extends FreedomCommand
checkRank(Rank.TELNET_ADMIN);
Player player = getPlayer(args[1]);
Admin admin = player == null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
Admin admin = player != null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
if (admin == null)
{
@ -270,7 +226,7 @@ public class Command_saconfig extends FreedomCommand
FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true);
admin.setActive(false);
plugin.al.save(admin);
plugin.al.save();
plugin.al.updateTables();
return true;
}

View File

@ -1,29 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.ServiceChecker.ServiceStatus;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
@CommandParameters(description = "Shows the status of all Mojang services", usage = "/<command>")
public class Command_services extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
msg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE);
for (ServiceStatus service : plugin.sc.getAllStatuses())
{
msg(service.getFormattedStatus());
}
msg("Version" + ChatColor.WHITE + ": " + plugin.sc.getVersion(), ChatColor.DARK_PURPLE);
msg("Last Check" + ChatColor.WHITE + ": " + plugin.sc.getLastCheck(), ChatColor.DARK_PURPLE);
return true;
}
}

View File

@ -7,8 +7,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Sets everyone's Worldedit block modification limit to 500.", usage = "/<command>")
public class Command_setl extends FreedomCommand
@CommandParameters(description = "Sets everyone's Worldedit block modification limit to the default.", usage = "/<command>", aliases = "setl,swl")
public class Command_setlimit extends FreedomCommand
{
@Override

View File

@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -11,45 +12,60 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Someone being a little bitch? Smite them down...", usage = "/<command> [playername]")
@CommandParameters(description = "Someone being a little bitch? Smite them down...", usage = "/<command> <player> [reason]")
public class Command_smite extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
if (args.length < 1)
{
return false;
}
final Player player = getPlayer(args[0]);
String reason = null;
if (args.length > 1)
{
reason = StringUtils.join(args, " ", 1, args.length);
}
if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
smite(player);
smite(player, reason);
return true;
}
public static void smite(final Player player)
public static void smite(Player player)
{
smite(player, null);
}
public static void smite(Player player, String reason)
{
FUtil.bcastMsg(player.getName() + " has been a naughty, naughty boy.", ChatColor.RED);
//Deop
if (reason != null)
{
FUtil.bcastMsg(" Reason: " + reason, ChatColor.YELLOW);
}
// Deop
player.setOp(false);
//Set gamemode to survival:
// Set gamemode to survival
player.setGameMode(GameMode.SURVIVAL);
//Clear inventory:
// Clear inventory
player.getInventory().clear();
//Strike with lightning effect:
// Strike with lightning effect
final Location targetPos = player.getLocation();
final World world = player.getWorld();
for (int x = -1; x <= 1; x++)
@ -61,7 +77,12 @@ public class Command_smite extends FreedomCommand
}
}
//Kill:
// Kill
player.setHealth(0.0);
if (reason != null)
{
player.sendMessage(ChatColor.RED + "You've been smitten. Reason: " + ChatColor.YELLOW + reason);
}
}
}

View File

@ -0,0 +1,78 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Make an announcement", usage = "/<command> <mobtype> [amount]")
public class Command_spawnmob extends FreedomCommand
{
@Override
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
EntityType type = null;
for (EntityType loop : EntityType.values())
{
if (loop.getName().equalsIgnoreCase(args[0]))
{
type = loop;
break;
}
}
if (type == null)
{
msg("Unknown entity type: " + args[0], ChatColor.RED);
return true;
}
if (!type.isSpawnable() || !type.isAlive())
{
msg("Can not spawn entity type: " + type.getName());
return true;
}
int amount = 1;
if (args.length > 1)
{
try
{
amount = Integer.parseInt(args[1]);
}
catch (NumberFormatException nfex)
{
msg("Invalid amount: " + args[1], ChatColor.RED);
return true;
}
}
if (amount > 10 || amount < 1)
{
msg("Invalid amount: " + args[1] + ". Must be 1-10.", ChatColor.RED);
return true;
}
Location l = playerSender.getLocation();
World w = playerSender.getWorld();
msg("Spawning " + amount + " of " + type.getName());
for (int i = 0; i < amount; amount++)
{
w.spawnEntity(l, type);
}
return true;
}
}

View File

@ -3,24 +3,27 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Mutes a player with brute force.", usage = "/<command> [<player> [-s] | list | purge | all]", aliases = "mute")
@CommandParameters(description = "Mutes a player with brute force.", usage = "/<command> [[-s] <player> [reason] | list | purge | all]", aliases = "mute")
public class Command_stfu extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0 || args.length > 2)
if (args.length == 0)
{
return false;
}
if (args[0].equalsIgnoreCase("list"))
if (args[0].equals("list"))
{
msg("Muted players:");
FPlayer info;
@ -38,8 +41,11 @@ public class Command_stfu extends FreedomCommand
{
msg("- none");
}
return true;
}
else if (args[0].equalsIgnoreCase("purge"))
if (args[0].equals("purge"))
{
FUtil.adminAction(sender.getName(), "Unmuting all players.", true);
FPlayer info;
@ -54,8 +60,10 @@ public class Command_stfu extends FreedomCommand
}
}
msg("Unmuted " + count + " players.");
return true;
}
else if (args[0].equalsIgnoreCase("all"))
if (args[0].equals("all"))
{
FUtil.adminAction(sender.getName(), "Muting all non-Superadmins", true);
@ -72,43 +80,70 @@ public class Command_stfu extends FreedomCommand
}
msg("Muted " + counter + " players.");
return true;
}
else
{
final Player player = getPlayer(args[0]);
// -s option (smite)
boolean smite = args[0].equals("-s");
if (smite)
{
args = ArrayUtils.subarray(args, 1, args.length);
if (args.length < 1)
{
return false;
}
}
final Player player = getPlayer(args[0]);
if (player == null)
{
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
String reason = null;
if (args.length > 1)
{
reason = StringUtils.join(args, " ", 1, args.length);
}
FPlayer playerdata = plugin.pl.getPlayer(player);
if (playerdata.isMuted())
{
FUtil.adminAction(sender.getName(), "Unmuting " + player.getName(), true);
playerdata.setMuted(false);
msg("Unmuted " + player.getName());
msg(player, "You have been unmuted.", ChatColor.RED);
}
else
{
if (!plugin.al.isAdmin(player))
if (plugin.al.isAdmin(player))
{
msg(player.getName() + " is a superadmin, and can't be muted.");
return true;
}
FUtil.adminAction(sender.getName(), "Muting " + player.getName(), true);
playerdata.setMuted(true);
if (args.length == 2 && args[1].equalsIgnoreCase("-s"))
if (smite)
{
Command_smite.smite(player);
}
msg("Muted " + player.getName());
if (reason != null)
{
msg(player, "You have been muted. Reason: " + reason, ChatColor.RED);
}
else
{
msg(player.getName() + " is a superadmin, and can't be muted.");
}
msg(player, "You have been muted.", ChatColor.RED);
}
msg("Muted " + player.getName());
}
return true;

View File

@ -14,32 +14,24 @@ public class Command_survival extends FreedomCommand
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (senderIsConsole)
{
if (args.length == 0)
{
msg("When used from the console, you must define a target user to change gamemode on.");
return true;
}
}
Player player;
if (args.length == 0)
if (isConsole())
{
player = playerSender;
}
else
{
if (args[0].equalsIgnoreCase("-a"))
{
if (!plugin.al.isAdmin(sender) || senderIsConsole)
{
noPerms();
sender.sendMessage("When used from the console, you must define a target player.");
return true;
}
playerSender.setGameMode(GameMode.SURVIVAL);
msg("Gamemode set to survival.");
return true;
}
checkRank(Rank.SUPER_ADMIN);
if (args[0].equals("-a"))
{
for (Player targetPlayer : server.getOnlinePlayers())
{
targetPlayer.setGameMode(GameMode.SURVIVAL);
@ -49,27 +41,17 @@ public class Command_survival extends FreedomCommand
return true;
}
if (senderIsConsole || plugin.al.isAdmin(sender))
{
player = getPlayer(args[0]);
Player player = getPlayer(args[0]);
if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
}
else
{
msg("Only superadmins can change other user's gamemode.");
return true;
}
}
msg("Setting " + player.getName() + " to game mode 'Survival'.");
player.sendMessage(sender.getName() + " set your game mode to 'Survival'.");
msg("Setting " + player.getName() + " to game mode survival.");
msg(player, sender.getName() + " set your game mode to survival.");
player.setGameMode(GameMode.SURVIVAL);
return true;
}
}

View File

@ -29,8 +29,18 @@ public class Command_tagnyan extends FreedomCommand
tag.append(FUtil.randomChatColor()).append(c);
}
String tagStr = tag.toString();
for (String word : Command_tag.FORBIDDEN_WORDS)
{
if (tagStr.contains(word))
{
msg("That tag contains a forbidden word.");
return true;
}
}
final FPlayer data = plugin.pl.getPlayer(playerSender);
data.setTag(tag.toString());
data.setTag(tagStr);
msg("Set tag to " + tag);

View File

@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.banning.Ban;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
@ -10,14 +11,14 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/<command> <partialname>", aliases = "noob")
@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/<command> <player> [reason]", aliases = "noob")
public class Command_tban extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
if (args.length < 1)
{
return false;
}
@ -30,6 +31,16 @@ public class Command_tban extends FreedomCommand
return true;
}
String reason;
if (args.length > 1)
{
reason = StringUtils.join(args, " ", 1, args.length);
}
else
{
reason = "You have been temporarily banned for 5 minutes.";
}
// strike with lightning effect:
final Location targetPos = player.getLocation();
for (int x = -1; x <= 1; x++)
@ -42,7 +53,7 @@ public class Command_tban extends FreedomCommand
}
FUtil.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
plugin.bm.addBan(Ban.forPlayer(player, sender, FUtil.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
plugin.bm.addBan(Ban.forPlayer(player, sender, FUtil.parseDateOffset("5m"), reason));
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");

View File

@ -1,70 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import java.io.File;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters(description = "Update server files.", usage = "/<command>")
public class Command_tfupdate extends FreedomCommand
{
public static final String[] FILES
=
{
};
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (FILES.length == 0)
{
msg("This command is disabled.");
return true;
}
if (!sender.getName().equalsIgnoreCase("madgeek1450"))
{
noPerms();
return true;
}
for (final String url : FILES)
{
new BukkitRunnable()
{
@Override
public void run()
{
try
{
FLog.info("Downloading: " + url);
File file = new File("./updates/" + url.substring(url.lastIndexOf("/") + 1));
if (file.exists())
{
file.delete();
}
if (!file.getParentFile().exists())
{
file.getParentFile().mkdirs();
}
FUtil.downloadFile(url, file, true);
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
}.runTaskAsynchronously(plugin);
}
return true;
}
}

View File

@ -28,9 +28,9 @@ public class Command_toggle extends FreedomCommand
msg("- prelog");
msg("- lockdown");
msg("- petprotect");
msg("- droptoggle");
msg("- nonuke");
msg("- explosives");
msg("- entitywipe");
msg("- nonuke [range] [count]");
msg("- explosives [radius]");
return false;
}
@ -92,7 +92,7 @@ public class Command_toggle extends FreedomCommand
return true;
}
if (args[0].equals("droptoggle"))
if (args[0].equals("entitywipe"))
{
toggle("Automatic entity wiping is", ConfigEntry.AUTO_ENTITY_WIPE);
return true;

View File

@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
@ -30,7 +31,7 @@ public class Command_tossmob extends FreedomCommand
FPlayer playerData = plugin.pl.getPlayer(playerSender);
EntityType creature = EntityType.PIG;
EntityType type = null;
if (args.length >= 1)
{
if ("off".equals(args[0]))
@ -42,19 +43,32 @@ public class Command_tossmob extends FreedomCommand
if (args[0].equalsIgnoreCase("list"))
{
msg("Supported mobs: " + StringUtils.join(FUtil.MOB_TYPES.keySet(), ", "), ChatColor.GREEN);
StringBuilder sb = new StringBuilder();
for (EntityType loop : EntityType.values())
{
if (loop.isAlive())
{
sb.append(" ").append(DepreciationAggregator.getName_EntityType(loop));
}
}
msg("Supported mobs: " + sb.toString().trim(), ChatColor.GREEN);
return true;
}
try
for (EntityType loopType : EntityType.values())
{
creature = FUtil.getEntityType(args[0]);
if (DepreciationAggregator.getName_EntityType(loopType).toLowerCase().equalsIgnoreCase(args[0]))
{
type = loopType;
break;
}
catch (Exception ex)
}
if (type == null)
{
msg(args[0] + " is not a supported mob type. Using a pig instead.", ChatColor.RED);
msg("By the way, you can type /tossmob list to see all possible mobs.", ChatColor.RED);
creature = EntityType.PIG;
type = EntityType.PIG;
}
}
@ -79,12 +93,12 @@ public class Command_tossmob extends FreedomCommand
speed = 5.0;
}
playerData.enableMobThrower(creature, speed);
msg("MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + ".", ChatColor.GREEN);
playerData.enableMobThrower(type, speed);
msg("MobThrower is enabled. Creature: " + type + " - Speed: " + speed + ".", ChatColor.GREEN);
msg("Left click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN);
msg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN);
playerSender.setItemInHand(new ItemStack(Material.BONE, 1));
playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.BONE, 1));
return true;
}

View File

@ -14,8 +14,8 @@ import org.bukkit.entity.Player;
* See https://github.com/TotalFreedom/License - This file may not be edited or removed.
*/
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
@CommandParameters(description = "Shows information about TotalFreedomMod or reloads it", usage = "/<command> [reload]")
public class Command_tfm extends FreedomCommand
@CommandParameters(description = "Shows information about TotalFreedomMod or reloads it", usage = "/<command> [reload]", aliases = "tfm")
public class Command_totalfreedommod extends FreedomCommand
{
@Override
@ -34,7 +34,7 @@ public class Command_tfm extends FreedomCommand
return true;
}
MainConfig.load();
plugin.config.load();
plugin.services.stop();
plugin.services.start();
@ -52,8 +52,9 @@ public class Command_tfm extends FreedomCommand
msg("Running on " + ConfigEntry.SERVER_NAME.getString() + ".", ChatColor.GOLD);
msg("Created by Madgeek1450 and Prozza.", ChatColor.GOLD);
msg(String.format("Version "
+ ChatColor.BLUE + "%s.%s " + ChatColor.GOLD + "("
+ ChatColor.BLUE + "%s %s.%s " + ChatColor.GOLD + "("
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + ")",
build.codename,
build.version,
build.number,
build.head), ChatColor.GOLD);

View File

@ -23,111 +23,21 @@ import org.bukkit.plugin.RegisteredListener;
public class Command_trail extends FreedomCommand
{
private static Listener movementListener = null;
private static final List<Player> trailPlayers = new ArrayList<>();
private static final Random RANDOM = new Random();
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length > 0 && "off".equals(args[0]))
{
trailPlayers.remove(playerSender);
plugin.tr.remove(playerSender);
msg("Trail disabled.");
}
else
{
if (!trailPlayers.contains(playerSender))
{
trailPlayers.add(playerSender);
}
plugin.tr.add(playerSender);
msg("Trail enabled. Use \"/trail off\" to disable.");
}
if (!trailPlayers.isEmpty())
{
registerMovementHandler();
}
else
{
unregisterMovementHandler();
}
return true;
}
private static void registerMovementHandler()
{
if (getRegisteredListener(movementListener) == null)
{
Bukkit.getPluginManager().registerEvents(movementListener = new Listener()
{
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent event)
{
Player player = event.getPlayer();
if (trailPlayers.contains(player))
{
Block fromBlock = event.getFrom().getBlock();
if (fromBlock.isEmpty())
{
Block toBlock = event.getTo().getBlock();
if (!fromBlock.equals(toBlock))
{
fromBlock.setType(Material.WOOL);
DepreciationAggregator.setData_Block(fromBlock, (byte) RANDOM.nextInt(16));
}
}
}
}
}, TotalFreedomMod.plugin);
}
}
private static void unregisterMovementHandler()
{
Listener registeredListener = getRegisteredListener(movementListener);
if (registeredListener != null)
{
PlayerMoveEvent.getHandlerList().unregister(registeredListener);
}
}
private static Listener getRegisteredListener(Listener listener)
{
RegisteredListener[] registeredListeners = PlayerMoveEvent.getHandlerList().getRegisteredListeners();
for (RegisteredListener registeredListener : registeredListeners)
{
if (registeredListener.getListener() == listener)
{
return listener;
}
}
return null;
}
public static void startTrail(Player player)
{
if (!trailPlayers.contains(player))
{
trailPlayers.add(player);
}
if (!trailPlayers.isEmpty())
{
registerMovementHandler();
}
}
public static void stopTrail(Player player)
{
trailPlayers.remove(player);
if (trailPlayers.isEmpty())
{
unregisterMovementHandler();
}
}
}

View File

@ -0,0 +1,41 @@
package me.totalfreedom.totalfreedommod.command;
//import me.libraryaddict.disguise.DisallowedDisguises;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Undisguise all players on the server", usage = "/<command>", aliases = "uall")
public class Command_undisguiseall extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ /*
if (!plugin.ldb.isPluginEnabled())
{
msg("LibsDisguises is not enabled.");
return true;
}
if (DisallowedDisguises.disabled)
{
msg("Disguises are not enabled.");
return true;
}
FUtil.adminAction(sender.getName(), "Undisguising all non-admins", true);
plugin.ldb.undisguiseAll(false);
return true;
*/
msg("This command has been disabled for technical reasons. Contact a developer for additional information.");
return true;
}
}

View File

@ -0,0 +1,43 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Unloads chunks not currently in use", usage = "/<command>", aliases = "rc")
public class Command_unloadchunks extends FreedomCommand {
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
FUtil.adminAction(sender.getName(), "Unloading unused chunks", false);
int numChunks = 0;
for (World world : server.getWorlds()) {
numChunks += unloadUnusedChunks(world);
}
FUtil.playerMsg(sender, numChunks + " chunks unloaded.");
return true;
}
private int unloadUnusedChunks(World world) {
int numChunks = 0;
for (Chunk loadedChunk : world.getLoadedChunks()) {
if (!world.isChunkInUse(loadedChunk.getX(), loadedChunk.getZ())) {
if (world.unloadChunk(loadedChunk)) {
numChunks++;
}
}
}
return numChunks;
}
}

View File

@ -158,8 +158,10 @@ public class Command_whitelist extends FreedomCommand
//purge
if (args[0].equalsIgnoreCase("purge"))
{
FUtil.adminAction(sender.getName(), "Removing all players from the whitelist.", false);
msg("Removed " + plugin.si.purgeWhitelist() + " players from the whitelist.");
// FUtil.adminAction(sender.getName(), "Removing all players from the whitelist.", false);
// msg("Removed " + plugin.si.purgeWhitelist() + " players from the whitelist.");
FUtil.adminAction(sender.getName(), "Whitelist purging is temporarily disabled.", true);
return true;
}

View File

@ -12,7 +12,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "See who has a block and optionally smite.", usage = "/<command> <item> [smite]", aliases = "wh")
@CommandParameters(description = "See who has a block and optionally clears the item.", usage = "/<command> <item> clear", aliases = "wh")
public class Command_whohas extends FreedomCommand
{
@ -24,7 +24,7 @@ public class Command_whohas extends FreedomCommand
return false;
}
final boolean doSmite = args.length >= 2 && "smite".equalsIgnoreCase(args[1]);
final boolean doClear = args.length >= 2 && "clear".equalsIgnoreCase(args[1]);
final String materialName = args[0];
Material material = Material.matchMaterial(materialName);
@ -52,9 +52,9 @@ public class Command_whohas extends FreedomCommand
if (player.getInventory().contains(material))
{
players.add(player.getName());
if (doSmite && !plugin.al.isAdmin(player))
if (doClear && !plugin.al.isAdmin(player))
{
Command_smite.smite(player);
player.getInventory().remove(material);
}
}
}

View File

@ -1,5 +1,7 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Arrays;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
@ -12,6 +14,13 @@ import org.bukkit.entity.Player;
public class Command_wildcard extends FreedomCommand
{
public static final List<String> BLOCKED_COMMANDS = Arrays.asList(
"wildcard",
"gtfo",
"doom",
"saconfig"
);
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
@ -20,24 +29,16 @@ public class Command_wildcard extends FreedomCommand
return false;
}
if (args[0].equals("wildcard"))
Command runCmd = server.getPluginCommand(args[0]);
if (runCmd == null)
{
msg("What the hell are you trying to do, you stupid idiot...", ChatColor.RED);
msg("Unknown command: " + args[0], ChatColor.RED);
return true;
}
if (args[0].equals("gtfo"))
if (BLOCKED_COMMANDS.contains(runCmd.getName()))
{
msg("Nice try", ChatColor.RED);
return true;
}
if (args[0].equals("doom"))
{
msg("Look, we all hate people, but this is not the way to deal with it, doom is evil enough!", ChatColor.RED);
return true;
}
if (args[0].equals("saconfig"))
{
msg("WOA, WTF are you trying to do???", ChatColor.RED);
msg("Did you really think that was going to work?", ChatColor.RED);
return true;
}
@ -51,9 +52,9 @@ public class Command_wildcard extends FreedomCommand
for (Player player : server.getOnlinePlayers())
{
String out_command = baseCommand.replaceAll("\\x3f", player.getName());
msg("Running Command: " + out_command);
server.dispatchCommand(sender, out_command);
String runCommand = baseCommand.replaceAll("\\x3f", player.getName());
msg("Running Command: " + runCommand);
server.dispatchCommand(sender, runCommand);
}
return true;

View File

@ -15,7 +15,7 @@ public class Command_wipeflatlands extends FreedomCommand
@Override
public boolean run(final CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
FUtil.setSavedFlag("do_wipe_flatlands", true);
plugin.sf.setSavedFlag("do_wipe_flatlands", true);
FUtil.bcastMsg("Server is going offline for flatlands wipe.", ChatColor.GRAY);

View File

@ -4,8 +4,9 @@ import lombok.Getter;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.RankBase;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.command.AbstractCommandBase;
import net.pravian.aero.util.Players;
import org.bukkit.ChatColor;
@ -83,7 +84,15 @@ public abstract class FreedomCommand extends AbstractCommandBase<TotalFreedomMod
}
}
protected void checkRank(RankBase rank)
protected void checkNotHostConsole()
{
if (isConsole() && FUtil.isFromHostConsole(sender.getName()))
{
throw new CommandFailException("This command can not be used from the host console.");
}
}
protected void checkRank(Rank rank)
{
if (!plugin.rm.getRank(sender).isAtLeast(rank))
{

View File

@ -3,7 +3,6 @@ package me.totalfreedom.totalfreedommod.command;
import java.util.Arrays;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.rank.RankBase;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.command.AeroCommandBase;
@ -20,9 +19,12 @@ import org.bukkit.entity.Player;
public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends AbstractCommandExecutor<C>
{
public FreedomCommandExecutor(AeroCommandHandler<?> handler, String name, C command)
private final TotalFreedomMod plugin;
public FreedomCommandExecutor(TotalFreedomMod plugin, AeroCommandHandler<?> handler, String name, C command)
{
super(handler, name, command);
this.plugin = plugin;
}
protected FreedomCommand getCommand()
@ -45,9 +47,25 @@ public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends Abstra
return;
}
String aliasString = params.aliases();
if (aliasString.length() > 0)
{
pluginCommand.setAliases(Arrays.asList(params.aliases().split(",")));
}
pluginCommand.setDescription(params.description());
pluginCommand.setUsage(params.usage());
// Check if permisions are correctly set up
CommandPermissions perms = command.getPerms();
if (perms != null)
{
if (perms.level().isConsole())
{
FLog.warning("[Command] " + pluginCommand.getName() + " - permission is set to a console rank, "
+ "should be set to player variant with 'source = SourceType.ONLY_CONSOLE'");
}
}
}
@Override
@ -125,7 +143,7 @@ public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends Abstra
// Player permissions
if (player != null)
{
Rank rank = TotalFreedomMod.plugin.rm.getRank(player);
Rank rank = plugin.rm.getRank(player);
boolean result = rank.isAtLeast(perms.level());
if (!result && sendMsg)
{
@ -135,7 +153,7 @@ public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends Abstra
}
// Console permissions
RankBase rank = TotalFreedomMod.plugin.rm.getRank(sender);
Rank rank = plugin.rm.getRank(sender);
boolean result = rank.isAtLeast(perms.level());
if (!result && sendMsg)
{
@ -147,10 +165,17 @@ public class FreedomCommandExecutor<C extends AeroCommandBase<?>> extends Abstra
public static class FreedomExecutorFactory implements AeroCommandExecutorFactory
{
private final TotalFreedomMod plugin;
public FreedomExecutorFactory(TotalFreedomMod plugin)
{
this.plugin = plugin;
}
@Override
public AeroCommandExecutor<? extends AeroCommandBase<?>> newExecutor(AeroCommandHandler<?> handler, String name, AeroCommandBase<?> command)
{
return new FreedomCommandExecutor<>(handler, name, command);
return new FreedomCommandExecutor<>(plugin, handler, name, command);
}
}

View File

@ -1,34 +0,0 @@
package me.totalfreedom.totalfreedommod.config;
import java.io.File;
import java.util.UUID;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
public class ConfigConverter
{
public static void convert()
{
for (File file : new File(TotalFreedomMod.plugin.getDataFolder(), "players").listFiles())
{
if (file.isDirectory())
{
continue;
}
final UUID uuid;
try
{
uuid = UUID.fromString(file.getName().split(".")[0]);
}
catch (IllegalArgumentException ex)
{
continue;
}
}
}
}

View File

@ -1,6 +1,7 @@
package me.totalfreedom.totalfreedommod.config;
import java.util.List;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
public enum ConfigEntry
{
@ -106,51 +107,62 @@ public enum ConfigEntry
public String getString()
{
return MainConfig.getString(this);
return getConfig().getString(this);
}
public String setString(String value)
{
MainConfig.setString(this, value);
getConfig().setString(this, value);
return value;
}
public Double getDouble()
{
return MainConfig.getDouble(this);
return getConfig().getDouble(this);
}
public Double setDouble(Double value)
{
MainConfig.setDouble(this, value);
getConfig().setDouble(this, value);
return value;
}
public Boolean getBoolean()
{
return MainConfig.getBoolean(this);
return getConfig().getBoolean(this);
}
public Boolean setBoolean(Boolean value)
{
MainConfig.setBoolean(this, value);
getConfig().setBoolean(this, value);
return value;
}
public Integer getInteger()
{
return MainConfig.getInteger(this);
return getConfig().getInteger(this);
}
public Integer setInteger(Integer value)
{
MainConfig.setInteger(this, value);
getConfig().setInteger(this, value);
return value;
}
public List<?> getList()
{
return MainConfig.getList(this);
return getConfig().getList(this);
}
@SuppressWarnings("unchecked")
public List<String> getStringList()
{
return (List<String>) getList();
}
private MainConfig getConfig()
{
return TotalFreedomMod.plugin().config;
}
public static ConfigEntry findConfigEntry(String name)

View File

@ -9,41 +9,45 @@ import java.util.EnumMap;
import java.util.List;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.util.FLog;
import net.pravian.aero.component.PluginComponent;
import org.apache.commons.io.FileUtils;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
public class MainConfig
public class MainConfig extends PluginComponent<TotalFreedomMod>
{
public static final File CONFIG_FILE = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.CONFIG_FILENAME);
public static final String CONFIG_FILENAME = "config.yml";
//
private static final EnumMap<ConfigEntry, Object> ENTRY_MAP;
private static final TFM_Defaults DEFAULTS;
private final EnumMap<ConfigEntry, Object> entries;
private final ConfigDefaults defaults;
static
public MainConfig(TotalFreedomMod plugin)
{
ENTRY_MAP = new EnumMap<>(ConfigEntry.class);
super(plugin);
TFM_Defaults tempDefaults = null;
entries = new EnumMap<>(ConfigEntry.class);
ConfigDefaults tempDefaults = null;
try
{
try
{
InputStream defaultConfig = getDefaultConfig();
tempDefaults = new TFM_Defaults(defaultConfig);
try (InputStream defaultConfig = getDefaultConfig())
{
tempDefaults = new ConfigDefaults(defaultConfig);
for (ConfigEntry entry : ConfigEntry.values())
{
ENTRY_MAP.put(entry, tempDefaults.get(entry.getConfigName()));
entries.put(entry, tempDefaults.get(entry.getConfigName()));
}
}
defaultConfig.close();
}
catch (IOException ex)
{
FLog.severe(ex);
}
copyDefaultConfig(CONFIG_FILE);
copyDefaultConfig(getConfigFile());
load();
}
@ -52,21 +56,16 @@ public class MainConfig
FLog.severe(ex);
}
DEFAULTS = tempDefaults;
defaults = tempDefaults;
}
private MainConfig()
{
throw new AssertionError();
}
public static void load()
public void load()
{
try
{
YamlConfiguration config = new YamlConfiguration();
config.load(CONFIG_FILE);
config.load(getConfigFile());
for (ConfigEntry entry : ConfigEntry.values())
{
@ -76,7 +75,7 @@ public class MainConfig
Object value = config.get(path);
if (value == null || entry.getType().isAssignableFrom(value.getClass()))
{
ENTRY_MAP.put(entry, value);
entries.put(entry, value);
}
else
{
@ -90,21 +89,18 @@ public class MainConfig
}
}
}
catch (FileNotFoundException ex)
{
FLog.severe(ex);
}
catch (IOException ex)
{
FLog.severe(ex);
}
catch (InvalidConfigurationException ex)
catch (IOException | InvalidConfigurationException ex)
{
FLog.severe(ex);
}
}
public static String getString(ConfigEntry entry)
private File getConfigFile()
{
return new File(plugin.getDataFolder(), "config.yml");
}
public String getString(ConfigEntry entry)
{
try
{
@ -117,7 +113,7 @@ public class MainConfig
return null;
}
public static void setString(ConfigEntry entry, String value)
public void setString(ConfigEntry entry, String value)
{
try
{
@ -129,7 +125,7 @@ public class MainConfig
}
}
public static Double getDouble(ConfigEntry entry)
public Double getDouble(ConfigEntry entry)
{
try
{
@ -142,7 +138,7 @@ public class MainConfig
return null;
}
public static void setDouble(ConfigEntry entry, Double value)
public void setDouble(ConfigEntry entry, Double value)
{
try
{
@ -154,7 +150,7 @@ public class MainConfig
}
}
public static Boolean getBoolean(ConfigEntry entry)
public Boolean getBoolean(ConfigEntry entry)
{
try
{
@ -167,7 +163,7 @@ public class MainConfig
return null;
}
public static void setBoolean(ConfigEntry entry, Boolean value)
public void setBoolean(ConfigEntry entry, Boolean value)
{
try
{
@ -179,7 +175,7 @@ public class MainConfig
}
}
public static Integer getInteger(ConfigEntry entry)
public Integer getInteger(ConfigEntry entry)
{
try
{
@ -192,7 +188,7 @@ public class MainConfig
return null;
}
public static void setInteger(ConfigEntry entry, Integer value)
public void setInteger(ConfigEntry entry, Integer value)
{
try
{
@ -204,7 +200,7 @@ public class MainConfig
}
}
public static List getList(ConfigEntry entry)
public List getList(ConfigEntry entry)
{
try
{
@ -217,9 +213,9 @@ public class MainConfig
return null;
}
public static <T> T get(ConfigEntry entry, Class<T> type) throws IllegalArgumentException
public <T> T get(ConfigEntry entry, Class<T> type) throws IllegalArgumentException
{
Object value = ENTRY_MAP.get(entry);
Object value = entries.get(entry);
try
{
return type.cast(value);
@ -230,7 +226,7 @@ public class MainConfig
}
}
public static <T> void set(ConfigEntry entry, T value, Class<T> type) throws IllegalArgumentException
public <T> void set(ConfigEntry entry, T value, Class<T> type) throws IllegalArgumentException
{
if (!type.isAssignableFrom(entry.getType()))
{
@ -240,10 +236,10 @@ public class MainConfig
{
throw new IllegalArgumentException("Value is not of type " + type.getSimpleName());
}
ENTRY_MAP.put(entry, value);
entries.put(entry, value);
}
private static void copyDefaultConfig(File targetFile)
private void copyDefaultConfig(File targetFile)
{
if (targetFile.exists())
{
@ -254,9 +250,10 @@ public class MainConfig
try
{
InputStream defaultConfig = getDefaultConfig();
try (InputStream defaultConfig = getDefaultConfig())
{
FileUtils.copyInputStreamToFile(defaultConfig, targetFile);
defaultConfig.close();
}
}
catch (IOException ex)
{
@ -264,22 +261,22 @@ public class MainConfig
}
}
private static InputStream getDefaultConfig()
private InputStream getDefaultConfig()
{
return TotalFreedomMod.plugin.getResource(TotalFreedomMod.CONFIG_FILENAME);
return plugin.getResource(TotalFreedomMod.CONFIG_FILENAME);
}
public static TFM_Defaults getDefaults()
public ConfigDefaults getDefaults()
{
return DEFAULTS;
return defaults;
}
public static class TFM_Defaults
public static class ConfigDefaults
{
private YamlConfiguration defaults = null;
private TFM_Defaults(InputStream defaultConfig)
private ConfigDefaults(InputStream defaultConfig)
{
try
{

View File

@ -56,6 +56,12 @@ public class FreezeData
location = player.getLocation(); // Blockify location
FUtil.setFlying(player, true); // Avoid infinite falling
if (fPlayer.getPlugin().al.isAdminImpostor(player))
{
return; // Don't run unfreeze task for impostors
}
unfreeze = new BukkitRunnable()
{
@Override
@ -65,7 +71,7 @@ public class FreezeData
setFrozen(false);
}
}.runTaskLater(TotalFreedomMod.plugin, AUTO_PURGE_TICKS);
}.runTaskLater(fPlayer.getPlugin(), AUTO_PURGE_TICKS);
}
}

View File

@ -34,12 +34,12 @@ public class Freezer extends FreedomService
public void setGlobalFreeze(boolean frozen)
{
this.globalFreeze = true;
this.globalFreeze = frozen;
}
public void purge()
{
setGlobalFreeze(false);
this.globalFreeze = false;
for (Player player : server.getOnlinePlayers())
{

View File

@ -70,14 +70,14 @@ public class ItemFun extends FreedomService
if (!plugin.al.isSeniorAdmin(player))
{
final StringBuilder msg = new StringBuilder();
final char[] chars = (player.getName() + " is a clown.").toCharArray();
final char[] chars = ("You are a clown.").toCharArray();
for (char c : chars)
{
msg.append(FUtil.randomChatColor()).append(c);
}
FUtil.bcastMsg(msg.toString());
player.sendMessage(msg.toString());
player.getInventory().getItemInHand().setType(Material.POTATO_ITEM);
player.getEquipment().getItemInMainHand().setType(Material.POTATO_ITEM);
break;
}
@ -126,7 +126,7 @@ public class ItemFun extends FreedomService
break;
}
case CARROT:
case CARROT_ITEM:
{
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
@ -185,7 +185,7 @@ public class ItemFun extends FreedomService
tntBlock.setType(Material.AIR);
}
}
}.runTaskLater(TotalFreedomMod.plugin, 30L);
}.runTaskLater(plugin, 30L);
event.setCancelled(true);
break;
@ -220,7 +220,7 @@ public class ItemFun extends FreedomService
if (fPlayer.toggleMP44Firing())
{
fPlayer.startArrowShooter(TotalFreedomMod.plugin);
fPlayer.startArrowShooter(plugin);
}
else
{

View File

@ -0,0 +1,76 @@
package me.totalfreedom.totalfreedommod.fun;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent;
public class Trailer extends FreedomService
{
private final Random random = new Random();
private final Set<String> trailPlayers = new HashSet<>(); // player name
public Trailer(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event)
{
if (trailPlayers.isEmpty())
{
return;
}
if (!trailPlayers.contains(event.getPlayer().getName()))
{
return;
}
Block fromBlock = event.getFrom().getBlock();
if (!fromBlock.isEmpty())
{
return;
}
Block toBlock = event.getTo().getBlock();
if (fromBlock.equals(toBlock))
{
return;
}
fromBlock.setType(Material.WOOL);
DepreciationAggregator.setData_Block(fromBlock, (byte) random.nextInt(16));
}
public void remove(Player player)
{
trailPlayers.remove(player.getName());
}
public void add(Player player)
{
trailPlayers.add(player.getName());
}
}

Some files were not shown because too many files have changed in this diff Show More