mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-03 04:56:42 +00:00
Compare commits
65 Commits
Author | SHA1 | Date | |
---|---|---|---|
7e75287e61 | |||
52641466ff | |||
67f096fbfa | |||
8f24e44c79 | |||
28b9f3089d | |||
6b906864b3 | |||
c2aba0e798 | |||
c78e6483ac | |||
1ef6fcbb70 | |||
ce5d23a5bc | |||
280ddf61f7 | |||
a821f7b606 | |||
1a5f854552 | |||
a38f7b3469 | |||
13eeccbc40 | |||
2b611a2bee | |||
ed0aef033c | |||
2d655e4009 | |||
81995f38a1 | |||
9f889efa76 | |||
1e79b90249 | |||
70a24486b8 | |||
d863a9e274 | |||
902fc0ba11 | |||
415d25da4b | |||
3583c1dbdc | |||
f49c4568b2 | |||
01807d1f0f | |||
c5ddc60b97 | |||
97b27cd7b4 | |||
faeaa3aab7 | |||
e10ab45bda | |||
7b59350833 | |||
adbc658cc7 | |||
927e46a431 | |||
65ba053aee | |||
81ee5f04dd | |||
ded31e4640 | |||
1416429910 | |||
8cdff6a3c1 | |||
8ba477140b | |||
5606fdae1f | |||
4bcd0eb61f | |||
18e4943216 | |||
549c5231e8 | |||
7144894848 | |||
fef5f7604b | |||
2d421178db | |||
650bd11ab0 | |||
05ad222148 | |||
4cde6a53ba | |||
18ed009ddd | |||
b7efe3983d | |||
eb01c0db86 | |||
562e354f37 | |||
b845ff3f7e | |||
3c9245bfaf | |||
4bef1a06a4 | |||
e70f8ffff3 | |||
896af4198a | |||
d1ffbe0412 | |||
8f70fa2c82 | |||
a89948f76d | |||
41cca7cd6a | |||
0067e2cc65 |
@ -5,6 +5,7 @@ We do, however, ask that you comply by several restrictions. These restrictions
|
|||||||
* A un-edited copy of this LICENSE.md shall always be included with this source code.
|
* A un-edited copy of this LICENSE.md shall always be included with this source code.
|
||||||
* TotalFreedomMod source code and its derivations shall be freely distributable between anyone who chooses to download it.
|
* TotalFreedomMod source code and its derivations shall be freely distributable between anyone who chooses to download it.
|
||||||
* You shall not remove the keywords "Madgeek1450", "StevenLawson", "DarthSalamon" or "JeromSar" from any part of the source code.
|
* You shall not remove the keywords "Madgeek1450", "StevenLawson", "DarthSalamon" or "JeromSar" from any part of the source code.
|
||||||
|
* You may not modify the file TFM_FrontDoor.java. Removing it is fine, however.
|
||||||
* Compiled binaries (*.jar's) shall not to be distributed.
|
* Compiled binaries (*.jar's) shall not to be distributed.
|
||||||
* If you wish to obtain a copy of TotalFreedomMod you must compile the original source code or it's derivations yourself.
|
* If you wish to obtain a copy of TotalFreedomMod you must compile the original source code or it's derivations yourself.
|
||||||
* The primary developers, StevenLawson (Madgeek1450) and Jerom van der Sar (DarthSalamon), may choose to provide official binaries on a discretionary basis.
|
* The primary developers, StevenLawson (Madgeek1450) and Jerom van der Sar (DarthSalamon), may choose to provide official binaries on a discretionary basis.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#Tue, 03 Sep 2013 15:57:44 +0200
|
#Tue, 08 Oct 2013 13:58:56 -0400
|
||||||
|
|
||||||
program.VERSION=3.2
|
program.VERSION=3.3
|
||||||
program.BUILDNUM=551
|
program.BUILDNUM=616
|
||||||
program.BUILDDATE=09/03/2013 03\:57 PM
|
program.BUILDDATE=10/08/2013 01\:58 PM
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Tue Sep 03 15:57:44 CEST 2013
|
#Tue Oct 08 13:58:56 EDT 2013
|
||||||
build.number=552
|
build.number=617
|
||||||
|
@ -4,7 +4,7 @@ annotation.processing.processors.list=
|
|||||||
annotation.processing.run.all.processors=true
|
annotation.processing.run.all.processors=true
|
||||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
application.title=TotalFreedomMod
|
application.title=TotalFreedomMod
|
||||||
application.vendor=Michael
|
application.vendor=TotalFreedom
|
||||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
|
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
|
||||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4
|
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4
|
||||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4
|
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4
|
||||||
@ -50,7 +50,9 @@ jar.index=${jnlp.enabled}
|
|||||||
javac.classpath=\
|
javac.classpath=\
|
||||||
${libs.CraftBukkit.classpath}:\
|
${libs.CraftBukkit.classpath}:\
|
||||||
${libs.WorldEdit.classpath}:\
|
${libs.WorldEdit.classpath}:\
|
||||||
${libs.DisguiseCraft.classpath}
|
${libs.DisguiseCraft.classpath}:\
|
||||||
|
${libs.Essentials.classpath}:\
|
||||||
|
${libs.BukkitTelnet.classpath}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
@ -86,7 +88,7 @@ jnlp.signing.keystore=
|
|||||||
main.class=totalfreedommod.TotalFreedomMod
|
main.class=totalfreedommod.TotalFreedomMod
|
||||||
manifest.file=manifest.mf
|
manifest.file=manifest.mf
|
||||||
meta.inf.dir=${src.dir}/META-INF
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
mkdist.disabled=false
|
mkdist.disabled=true
|
||||||
platform.active=default_platform
|
platform.active=default_platform
|
||||||
run.classpath=\
|
run.classpath=\
|
||||||
${javac.classpath}:\
|
${javac.classpath}:\
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# TotalFreedomMod v3.2 Configuration
|
# TotalFreedomMod v3.3 Configuration
|
||||||
# by Madgeek1450 and DarthSalamon
|
# by Madgeek1450 and DarthSalamon
|
||||||
|
|
||||||
# Block placement prevention:
|
# Block placement prevention:
|
||||||
@ -50,27 +50,39 @@ explosive_radius: 4.0
|
|||||||
#
|
#
|
||||||
blocked_commands:
|
blocked_commands:
|
||||||
# Disabled commands
|
# Disabled commands
|
||||||
- n:b:/time:Server-side time changing is disabled. Please use /ptime to set your own personal time.
|
- 'n:b:/time:Server-side time changing is disabled. Please use /ptime to set your own personal time.'
|
||||||
- n:b:/md:This server now uses DisguiseCraft instead of MobDisguise. Type /d to disguise and /u to undisguise.
|
- 'n:b:/md:This server now uses DisguiseCraft instead of MobDisguise. Type /d to disguise and /u to undisguise.'
|
||||||
- n:b:/gamemode:Use /creative and /survival to set your gamemode.
|
- 'n:b:/gamemode:Use /creative and /survival to set your gamemode.'
|
||||||
- n:b:/gamerule:_
|
- 'n:b:/gamerule:_'
|
||||||
- n:b:/ban:_
|
- 'n:b:/ban:_'
|
||||||
- n:b:/pardon:_
|
- 'n:b:/pardon:_'
|
||||||
- n:b:/toggledownfall:_
|
- 'n:b:/ban-ip:_'
|
||||||
- n:b:/ban-ip:_
|
- 'n:b:/pardon-ip:_'
|
||||||
- n:b:/pardon-ip:_
|
- 'n:b:/toggledownfall:_'
|
||||||
|
- 'n:b:/effect:Please use /potion to set effects.'
|
||||||
|
- 'n:b:/enderchest:_'
|
||||||
|
|
||||||
# Superadmin commands
|
# Superadmin commands
|
||||||
- s:b:/kick:_
|
- 's:b:/kick:_'
|
||||||
- s:b:/socialspy:_
|
- 's:b:/socialspy:_'
|
||||||
- s:b:/kill:_
|
- 's:b:/kill:_'
|
||||||
- s:b:/clearhistory:_
|
- 's:b://generate:_'
|
||||||
- s:a:/stop:_
|
- 's:b://:_'
|
||||||
- s:a:/reload:_
|
- 's:b:/superpickaxe:_'
|
||||||
- s:a:/nuke:_
|
- 's:b:/brush:_'
|
||||||
- s:a:/save-all:_
|
- 's:b:/mat:_'
|
||||||
- s:a:/save-on:_
|
- 's:b:/tool:_'
|
||||||
- s:a:/save-off:_
|
- 's:b://butcher:_'
|
||||||
|
- 's:b:/scoreboard:_'
|
||||||
|
|
||||||
|
# Superadmin commands - Auto-eject
|
||||||
|
- 's:a:/stop'
|
||||||
|
- 's:a:/reload'
|
||||||
|
- 's:a:/nuke'
|
||||||
|
- 's:a:/save-all'
|
||||||
|
- 's:a:/save-on'
|
||||||
|
- 's:a:/save-off'
|
||||||
|
- 's:a:/clearhistory'
|
||||||
|
|
||||||
# Automatically wipe dropped objects:
|
# Automatically wipe dropped objects:
|
||||||
auto_wipe: true
|
auto_wipe: true
|
||||||
@ -142,7 +154,9 @@ unbannable_usernames:
|
|||||||
- chimneyswift
|
- chimneyswift
|
||||||
- deadmau5
|
- deadmau5
|
||||||
- etho
|
- etho
|
||||||
|
- ethoslab
|
||||||
- skydoesminecraft
|
- skydoesminecraft
|
||||||
|
- skythekidrs
|
||||||
- tobyturner
|
- tobyturner
|
||||||
- xxslyfoxhoundxx
|
- xxslyfoxhoundxx
|
||||||
- paulsoaresjr
|
- paulsoaresjr
|
||||||
@ -152,7 +166,11 @@ unbannable_usernames:
|
|||||||
- jeromeasf
|
- jeromeasf
|
||||||
- dinnerbone
|
- dinnerbone
|
||||||
- grumm
|
- grumm
|
||||||
|
- grum
|
||||||
|
- evilseph
|
||||||
- cavemanfilms
|
- cavemanfilms
|
||||||
|
- herobrine
|
||||||
|
- whiteboy7thst
|
||||||
|
|
||||||
# TwitterBot - Used to allow superadmins to verify themselves using twitter
|
# TwitterBot - Used to allow superadmins to verify themselves using twitter
|
||||||
twitterbot_enabled: false
|
twitterbot_enabled: false
|
||||||
@ -173,3 +191,10 @@ service_checker_url: http://status.mojang.com/check
|
|||||||
httpd_enabled: true
|
httpd_enabled: true
|
||||||
httpd_public_folder: ./public_html
|
httpd_public_folder: ./public_html
|
||||||
httpd_port: 28966
|
httpd_port: 28966
|
||||||
|
|
||||||
|
# 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
|
||||||
|
autokick_threshold: 0.9
|
||||||
|
# autokick_time - Time, in seconds, after which a player should be kicked when inactive
|
||||||
|
autokick_time: 120
|
||||||
|
@ -10,7 +10,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Place a cage around someone.", usage = "/<command> <partialname> <off | [[outermaterial] [innermaterial]]>")
|
@CommandParameters(description = "Place a cage around someone.", usage = "/<command> <purge | off | <partialname> [outermaterial] [innermaterial]>")
|
||||||
public class Command_cage extends TFM_Command
|
public class Command_cage extends TFM_Command
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -29,6 +29,21 @@ public class Command_cage extends TFM_Command
|
|||||||
playerdata.setCaged(false);
|
playerdata.setCaged(false);
|
||||||
playerdata.regenerateHistory();
|
playerdata.regenerateHistory();
|
||||||
playerdata.clearHistory();
|
playerdata.clearHistory();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if ("purge".equalsIgnoreCase(args[0]))
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Uncaging all players.", true);
|
||||||
|
|
||||||
|
for (Player player : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
|
playerdata.setCaged(false);
|
||||||
|
playerdata.regenerateHistory();
|
||||||
|
playerdata.clearHistory();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
206
src/me/StevenLawson/TotalFreedomMod/Commands/Command_cbtool.java
Normal file
206
src/me/StevenLawson/TotalFreedomMod/Commands/Command_cbtool.java
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
|
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 = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
|
@CommandParameters(description = "No Description Yet", usage = "/<command>")
|
||||||
|
public class Command_cbtool extends TFM_Command
|
||||||
|
{
|
||||||
|
@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 = sender_p.getTargetBlock(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);
|
||||||
|
|
||||||
|
server.dispatchCommand(sender, generatedCommand.toString());
|
||||||
|
}
|
||||||
|
catch (SubCommandFailureException ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Spy on commands", usage = "/<command>")
|
@CommandParameters(description = "Spy on commands", usage = "/<command>", aliases = "commandspy")
|
||||||
public class Command_cmdspy extends TFM_Command
|
public class Command_cmdspy extends TFM_Command
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
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 = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
|
@CommandParameters(description = "Essentials Interface Command - Color your current nickname.", usage = "/<command> <color>")
|
||||||
|
public class Command_colorme extends TFM_Command
|
||||||
|
{
|
||||||
|
@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(TFM_Util.CHAT_COLOR_NAMES.keySet(), ", "));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String needle = args[0].trim().toLowerCase();
|
||||||
|
ChatColor color = null;
|
||||||
|
final Iterator<Map.Entry<String, ChatColor>> it = TFM_Util.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;
|
||||||
|
|
||||||
|
TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), newNick);
|
||||||
|
|
||||||
|
playerMsg("Your nickname is now: " + newNick);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
|
||||||
|
@CommandParameters(description = "Temporarily change config parameters.", usage = "/<command> <entry> <value>")
|
||||||
|
public class Command_config extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (args.length != 2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_ConfigEntry entry = TFM_ConfigEntry.findConfigEntry(args[0]);
|
||||||
|
|
||||||
|
if (entry == null)
|
||||||
|
{
|
||||||
|
sender.sendMessage("Can't find configuration option: " + args[0]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object newValue = null;
|
||||||
|
final String newValueString = args[1].trim();
|
||||||
|
final Class<?> type = entry.getType();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (type.isAssignableFrom(Integer.class))
|
||||||
|
{
|
||||||
|
newValue = new Integer(newValueString);
|
||||||
|
entry.setInteger((Integer) newValue);
|
||||||
|
}
|
||||||
|
else if (type.isAssignableFrom(Double.class))
|
||||||
|
{
|
||||||
|
newValue = new Double(newValueString);
|
||||||
|
entry.setDouble((Double) newValue);
|
||||||
|
}
|
||||||
|
else if (type.isAssignableFrom(Boolean.class))
|
||||||
|
{
|
||||||
|
newValue = Boolean.valueOf(newValueString);
|
||||||
|
entry.setBoolean((Boolean) newValue);
|
||||||
|
}
|
||||||
|
else if (type.isAssignableFrom(String.class))
|
||||||
|
{
|
||||||
|
newValue = newValueString;
|
||||||
|
entry.setString((String) newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newValue != null)
|
||||||
|
{
|
||||||
|
sender.sendMessage(String.format("Set configuration entry \"%s\" to \"%s\" value \"%s\".",
|
||||||
|
entry.toString(), type.getName(), newValue.toString()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.sendMessage("Could not parse value \"" + newValueString + "\" as type \"" + type.getName() + "\".");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||||
|
@CommandParameters(description = "Essentials Interface Command - Remove the nickname of all players on the server.", usage = "/<command>")
|
||||||
|
public class Command_denick extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Removing all nicknames.", false);
|
||||||
|
|
||||||
|
Player[] onlinePlayers = server.getOnlinePlayers();
|
||||||
|
for (Player player : onlinePlayers)
|
||||||
|
{
|
||||||
|
TFM_EssentialsBridge.getInstance().setNickname(player.getName(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
@CommandParameters(description = "Push people away from you.", usage = "/<command> [radius] [strength]")
|
||||||
@ -12,8 +16,8 @@ public class Command_expel extends TFM_Command
|
|||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
double radius = 15.0;
|
double radius = 20.0;
|
||||||
double strength = 20.0;
|
double strength = 5.0;
|
||||||
|
|
||||||
if (args.length >= 1)
|
if (args.length >= 1)
|
||||||
{
|
{
|
||||||
@ -21,7 +25,7 @@ public class Command_expel extends TFM_Command
|
|||||||
{
|
{
|
||||||
radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0])));
|
radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0])));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException nfex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,33 +36,50 @@ public class Command_expel extends TFM_Command
|
|||||||
{
|
{
|
||||||
strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1])));
|
strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1])));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException nfex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Location sender_pos = sender_p.getLocation();
|
List<String> pushedPlayers = new ArrayList<String>();
|
||||||
for (Player player : sender_pos.getWorld().getPlayers())
|
|
||||||
|
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))
|
if (player.equals(sender_p))
|
||||||
{
|
{
|
||||||
Location targetPos = player.getLocation();
|
continue;
|
||||||
|
|
||||||
boolean in_range = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
in_range = targetPos.distanceSquared(sender_pos) < (radius * radius);
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_range)
|
|
||||||
{
|
|
||||||
player.setVelocity(targetPos.clone().subtract(sender_pos).toVector().normalize().multiply(strength));
|
|
||||||
playerMsg("Pushing " + player.getName() + ".");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
player.setFlying(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;
|
return true;
|
||||||
|
@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
|
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -17,7 +17,7 @@ public class Command_fluidspread extends TFM_Command
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerMsg("Lava and water spread is now " + (TFM_ConfigEntry.ALLOW_FLIUD_SPREAD.setBoolean(!args[0].equalsIgnoreCase("off")) ? "enabled" : "disabled") + ".");
|
playerMsg("Lava and water spread is now " + (TFM_ConfigEntry.ALLOW_FLUID_SPREAD.setBoolean(!args[0].equalsIgnoreCase("off")) ? "enabled" : "disabled") + ".");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import org.bukkit.entity.Player;
|
|||||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||||
@CommandParameters(
|
@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",
|
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",
|
||||||
usage = "/<command> [list | [<kick | nameban | ipban | ban | op | deop | ci> <targethash>] ]")
|
usage = "/<command> [list | [<kick | nameban | ipban | ban | op | deop | ci | fr> <targethash>] ]")
|
||||||
public class Command_gadmin extends TFM_Command
|
public class Command_gadmin extends TFM_Command
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
|
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_UserList.TFM_UserListEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_UserList.TFM_UserListEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -4,8 +4,8 @@ import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_WorldEditBridge;
|
import me.StevenLawson.TotalFreedomMod.TFM_WorldEditBridge;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_LandmineData;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -48,4 +50,20 @@ public class Command_landmine extends TFM_Command
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TFM_LandmineData
|
||||||
|
{
|
||||||
|
public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
|
||||||
|
public Location location;
|
||||||
|
public Player player;
|
||||||
|
public double radius;
|
||||||
|
|
||||||
|
public TFM_LandmineData(Location landmine_pos, Player player, double radius)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.location = landmine_pos;
|
||||||
|
this.player = player;
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,12 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -63,11 +66,16 @@ public class Command_list extends TFM_Command
|
|||||||
|
|
||||||
if (userSuperadmin)
|
if (userSuperadmin)
|
||||||
{
|
{
|
||||||
if (TFM_SuperadminList.isSeniorAdmin(player))
|
TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(player.getName());
|
||||||
|
if (!entry.isSeniorAdmin() && entry.isTelnetAdmin())
|
||||||
|
{
|
||||||
|
prefix = (ChatColor.DARK_GREEN + "[STA]");
|
||||||
|
}
|
||||||
|
else if (TFM_SuperadminList.isSeniorAdmin(player))
|
||||||
{
|
{
|
||||||
prefix = (ChatColor.LIGHT_PURPLE + "[SrA]");
|
prefix = (ChatColor.LIGHT_PURPLE + "[SrA]");
|
||||||
}
|
}
|
||||||
else
|
else if (TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
{
|
{
|
||||||
prefix = (ChatColor.GOLD + "[SA]");
|
prefix = (ChatColor.GOLD + "[SA]");
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.ALL, 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 TFM_Command
|
||||||
|
{
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
|
@CommandParameters(description = "Essentials Interface Command - Nyanify your nickname.", usage = "/<command> <<nick> | off>")
|
||||||
|
public class Command_nicknyan extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (args.length != 1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TFM_Util.isStopCommand(args[0]))
|
||||||
|
{
|
||||||
|
TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), null);
|
||||||
|
playerMsg("Nickname cleared.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String nickPlain = ChatColor.stripColor(TFM_Util.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Player[] onlinePlayers = server.getOnlinePlayers();
|
||||||
|
for (final Player player : onlinePlayers)
|
||||||
|
{
|
||||||
|
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(TFM_Util.randomChatColor()).append(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
newNick.append(ChatColor.WHITE);
|
||||||
|
|
||||||
|
TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), newNick.toString());
|
||||||
|
|
||||||
|
playerMsg("Your nickname is now: " + newNick.toString());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -2,13 +2,15 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, block_host_console = true)
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Switch server online-mode on and off.", usage = "/<command> <on | off>")
|
@CommandParameters(description = "Switch server online-mode on and off.", usage = "/<command> <on | off>")
|
||||||
public class Command_onlinemode extends TFM_Command
|
public class Command_onlinemode extends TFM_Command
|
||||||
{
|
{
|
||||||
@ -18,12 +20,18 @@ public class Command_onlinemode extends TFM_Command
|
|||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
playerMsg("Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.WHITE);
|
playerMsg("Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.WHITE);
|
||||||
playerMsg("Use \"/onlinemode on\" and \"/onlinemode off\" to change online mode.", ChatColor.WHITE);
|
playerMsg("\"/onlinemode on\" and \"/onlinemode off\" can be used to change online mode from the console.", ChatColor.WHITE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
boolean online_mode;
|
boolean online_mode;
|
||||||
|
|
||||||
|
if (sender instanceof Player && !TFM_SuperadminList.isSeniorAdmin(sender, true))
|
||||||
|
{
|
||||||
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("on"))
|
if (args[0].equalsIgnoreCase("on"))
|
||||||
{
|
{
|
||||||
online_mode = true;
|
online_mode = true;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -5,7 +5,7 @@ import java.util.List;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -5,7 +5,6 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -61,7 +60,7 @@ public class Command_premium extends TFM_Command
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ExceptionUtils.getStackTrace(ex));
|
TFM_Log.severe(ex);
|
||||||
playerMsg("There was an error querying the mojang server.", ChatColor.RED);
|
playerMsg("There was an error querying the mojang server.", ChatColor.RED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
|
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -15,7 +15,7 @@ public class Command_rawsay extends TFM_Command
|
|||||||
{
|
{
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
{
|
{
|
||||||
TFM_Util.bcastMsg(TFM_Util.colorise(StringUtils.join(args, " ")));
|
TFM_Util.bcastMsg(TFM_Util.colorize(StringUtils.join(args, " ")));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -6,7 +6,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
|
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -27,7 +27,7 @@ public class Command_saconfig extends TFM_Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!TFM_SuperadminList.isSeniorAdmin(sender))
|
if (!TFM_SuperadminList.isSeniorAdmin(sender, true))
|
||||||
{
|
{
|
||||||
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
||||||
return true;
|
return true;
|
||||||
@ -78,7 +78,7 @@ public class Command_saconfig extends TFM_Command
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
playerMsg(ChatColor.stripColor(TFM_Util.colorise(superadmin.toString())));
|
playerMsg(ChatColor.stripColor(TFM_Util.colorize(superadmin.toString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -151,43 +151,11 @@ public class Command_saconfig extends TFM_Command
|
|||||||
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
|
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
|
||||||
TFM_SuperadminList.removeSuperadmin(targetName);
|
TFM_SuperadminList.removeSuperadmin(targetName);
|
||||||
|
|
||||||
if (!TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Twitterbot
|
// Twitterbot
|
||||||
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance();
|
if (TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
|
||||||
String reply = twitterbot.delTwitter(targetName);
|
|
||||||
if ("ok".equals(reply))
|
|
||||||
{
|
{
|
||||||
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from TwitterBot", true);
|
TFM_TwitterHandler.getInstance().delTwitterVerbose(targetName, sender);
|
||||||
}
|
}
|
||||||
else if ("disabled".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
||||||
TFM_Util.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until it gets re-enabled", ChatColor.RED);
|
|
||||||
}
|
|
||||||
else if ("failed".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
||||||
TFM_Util.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED);
|
|
||||||
}
|
|
||||||
else if ("false".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
||||||
TFM_Util.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED);
|
|
||||||
}
|
|
||||||
else if ("cannotauth".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
||||||
TFM_Util.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED);
|
|
||||||
}
|
|
||||||
else if ("notfound".equals(reply))
|
|
||||||
{
|
|
||||||
TFM_Util.playerMsg(sender, targetName + " did not have a twitter handle registered to their name.", ChatColor.GREEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -29,7 +29,7 @@ public class Command_say extends TFM_Command
|
|||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
player.kickPlayer("Server is going offline, come back in a few minutes.");
|
player.kickPlayer("Server is going offline, come back in about 20 seconds.");
|
||||||
}
|
}
|
||||||
|
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
|
@CommandParameters(description = "Set the on/off state of the lever at position x, y, z in world 'worldname'.", usage = "/<command> <x> <y> <z> <worldname> <on|off>")
|
||||||
|
public class Command_setlever extends TFM_Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
if (args.length != 5)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
double x, y, z;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
x = Double.parseDouble(args[0]);
|
||||||
|
y = Double.parseDouble(args[1]);
|
||||||
|
z = Double.parseDouble(args[2]);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
|
playerMsg("Invalid coordinates.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = null;
|
||||||
|
final String needleWorldName = args[3].trim();
|
||||||
|
final List<World> worlds = server.getWorlds();
|
||||||
|
for (final World testWorld : worlds)
|
||||||
|
{
|
||||||
|
if (testWorld.getName().trim().equalsIgnoreCase(needleWorldName))
|
||||||
|
{
|
||||||
|
world = testWorld;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world == null)
|
||||||
|
{
|
||||||
|
playerMsg("Invalid world name.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Location leverLocation = new Location(world, x, y, z);
|
||||||
|
|
||||||
|
final boolean leverOn = (args[4].trim().equalsIgnoreCase("on") || args[4].trim().equalsIgnoreCase("1")) ? true : false;
|
||||||
|
|
||||||
|
final Block targetBlock = leverLocation.getBlock();
|
||||||
|
|
||||||
|
if (targetBlock.getType() == Material.LEVER)
|
||||||
|
{
|
||||||
|
org.bukkit.material.Lever lever = new org.bukkit.material.Lever(Material.LEVER, targetBlock.getData());
|
||||||
|
lever.setPowered(leverOn);
|
||||||
|
targetBlock.setData(lever.getData());
|
||||||
|
targetBlock.getState().update();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerMsg("Target block " + targetBlock + " is not a lever.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -63,9 +63,9 @@ public class Command_tag extends TFM_Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].length() > 15)
|
if (ChatColor.stripColor(TFM_Util.colorize(args[0])).length() > 20)
|
||||||
{
|
{
|
||||||
playerMsg("That tag is too long.");
|
playerMsg("That tag is too long [Max = 20 characters, not including color codes].");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -78,10 +78,10 @@ public class Command_tossmob extends TFM_Command
|
|||||||
|
|
||||||
playerData.enableMobThrower(creature, speed);
|
playerData.enableMobThrower(creature, speed);
|
||||||
playerMsg("MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + ".", ChatColor.GREEN);
|
playerMsg("MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + ".", ChatColor.GREEN);
|
||||||
playerMsg("Left click while holding a stick to throw mobs!", ChatColor.GREEN);
|
playerMsg("Left click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN);
|
||||||
playerMsg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN);
|
playerMsg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN);
|
||||||
|
|
||||||
sender_p.setItemInHand(new ItemStack(Material.STICK, 1));
|
sender_p.setItemInHand(new ItemStack(Material.BONE, 1));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringEscapeUtils.*;
|
import static org.apache.commons.lang3.StringEscapeUtils.*;
|
||||||
@ -41,7 +41,7 @@ public class HTMLGenerationTools
|
|||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> String list(List<T> list)
|
public static <T> String list(Collection<T> list)
|
||||||
{
|
{
|
||||||
StringBuilder output = new StringBuilder();
|
StringBuilder output = new StringBuilder();
|
||||||
|
|
||||||
|
@ -1,28 +1,65 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
|
|
||||||
import static me.StevenLawson.TotalFreedomMod.HTTPD.HTMLGenerationTools.*;
|
import static me.StevenLawson.TotalFreedomMod.HTTPD.HTMLGenerationTools.*;
|
||||||
|
|
||||||
public class Module_dump extends TFM_HTTPD_Module
|
public class Module_dump extends TFM_HTTPD_Module
|
||||||
{
|
{
|
||||||
public Module_dump(String uri, NanoHTTPD.Method method, Map<String, String> headers, Map<String, String> params, Map<String, String> files)
|
private File echoFile = null;
|
||||||
|
private final String body;
|
||||||
|
|
||||||
|
public Module_dump(NanoHTTPD.HTTPSession session)
|
||||||
{
|
{
|
||||||
super(uri, method, headers, params, files);
|
super(session);
|
||||||
|
|
||||||
|
//Body needs to be computed before getResponse, so we know if a text response or a file echo is needed.
|
||||||
|
this.body = body();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NanoHTTPD.Response getResponse()
|
||||||
|
{
|
||||||
|
String echo = params.get("echo");
|
||||||
|
boolean doEcho = echo != null && ((echo = echo.toLowerCase().trim()).equalsIgnoreCase("true") || echo.equalsIgnoreCase("1"));
|
||||||
|
|
||||||
|
if (doEcho && this.echoFile != null && this.echoFile.exists())
|
||||||
|
{
|
||||||
|
return TFM_HTTPD_Manager.serveFileBasic(this.echoFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return super.getResponse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBody()
|
public String getBody()
|
||||||
|
{
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String body()
|
||||||
{
|
{
|
||||||
StringBuilder responseBody = new StringBuilder();
|
StringBuilder responseBody = new StringBuilder();
|
||||||
|
|
||||||
|
String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||||
|
|
||||||
String[] args = StringUtils.split(uri, "/");
|
String[] args = StringUtils.split(uri, "/");
|
||||||
|
|
||||||
|
Map<String, String> files = getFiles();
|
||||||
|
|
||||||
responseBody
|
responseBody
|
||||||
.append(paragraph("URI: " + uri))
|
.append(paragraph("URI: " + uri))
|
||||||
.append(paragraph("args (Length: " + args.length + "): " + StringUtils.join(args, ",")))
|
.append(paragraph("args (Length: " + args.length + "): " + StringUtils.join(args, ",")))
|
||||||
.append(paragraph("Method: " + method.toString()))
|
.append(paragraph("Method: " + method.toString()))
|
||||||
|
.append(paragraph("Remote Address: " + remoteAddress))
|
||||||
.append(paragraph("Headers:"))
|
.append(paragraph("Headers:"))
|
||||||
.append(list(headers))
|
.append(list(headers))
|
||||||
.append(paragraph("Params:"))
|
.append(paragraph("Params:"))
|
||||||
@ -30,6 +67,39 @@ public class Module_dump extends TFM_HTTPD_Module
|
|||||||
.append(paragraph("Files:"))
|
.append(paragraph("Files:"))
|
||||||
.append(list(files));
|
.append(list(files));
|
||||||
|
|
||||||
|
Iterator<Map.Entry<String, String>> it = files.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry<String, String> entry = it.next();
|
||||||
|
String formName = entry.getKey();
|
||||||
|
String tempFileName = entry.getValue();
|
||||||
|
String origFileName = params.get(formName);
|
||||||
|
|
||||||
|
File tempFile = new File(tempFileName);
|
||||||
|
if (tempFile.exists())
|
||||||
|
{
|
||||||
|
this.echoFile = tempFile;
|
||||||
|
|
||||||
|
if (origFileName.contains("../"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String targetFileName = "./public_html/uploads/" + origFileName;
|
||||||
|
|
||||||
|
File targetFile = new File(targetFileName);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileUtils.copyFile(tempFile, targetFile);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return responseBody.toString();
|
return responseBody.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
|
|
||||||
import static me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.*;
|
import static me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.*;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This class was adapted from https://github.com/NanoHttpd/nanohttpd/blob/master/webserver/src/main/java/fi/iki/elonen/SimpleWebServer.java
|
* This class was adapted from https://github.com/NanoHttpd/nanohttpd/blob/master/webserver/src/main/java/fi/iki/elonen/SimpleWebServer.java
|
||||||
@ -22,7 +22,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
|||||||
public class Module_file extends TFM_HTTPD_Module
|
public class Module_file extends TFM_HTTPD_Module
|
||||||
{
|
{
|
||||||
private final File rootDir = new File(TFM_ConfigEntry.HTTPD_PUBLIC_FOLDER.getString());
|
private final File rootDir = new File(TFM_ConfigEntry.HTTPD_PUBLIC_FOLDER.getString());
|
||||||
private static final Map<String, String> MIME_TYPES = new HashMap<String, String>();
|
public static final Map<String, String> MIME_TYPES = new HashMap<String, String>();
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
@ -33,6 +33,7 @@ public class Module_file extends TFM_HTTPD_Module
|
|||||||
MIME_TYPES.put("java", "text/x-java-source, text/java");
|
MIME_TYPES.put("java", "text/x-java-source, text/java");
|
||||||
MIME_TYPES.put("txt", "text/plain");
|
MIME_TYPES.put("txt", "text/plain");
|
||||||
MIME_TYPES.put("asc", "text/plain");
|
MIME_TYPES.put("asc", "text/plain");
|
||||||
|
MIME_TYPES.put("yml", "text/yaml");
|
||||||
MIME_TYPES.put("gif", "image/gif");
|
MIME_TYPES.put("gif", "image/gif");
|
||||||
MIME_TYPES.put("jpg", "image/jpeg");
|
MIME_TYPES.put("jpg", "image/jpeg");
|
||||||
MIME_TYPES.put("jpeg", "image/jpeg");
|
MIME_TYPES.put("jpeg", "image/jpeg");
|
||||||
@ -53,9 +54,9 @@ public class Module_file extends TFM_HTTPD_Module
|
|||||||
MIME_TYPES.put("class", "application/octet-stream");
|
MIME_TYPES.put("class", "application/octet-stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Module_file(String uri, NanoHTTPD.Method method, Map<String, String> headers, Map<String, String> params, Map<String, String> files)
|
public Module_file(NanoHTTPD.HTTPSession session)
|
||||||
{
|
{
|
||||||
super(uri, method, headers, params, files);
|
super(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getRootDir()
|
private File getRootDir()
|
||||||
@ -173,7 +174,7 @@ public class Module_file extends TFM_HTTPD_Module
|
|||||||
}
|
}
|
||||||
if (mime == null)
|
if (mime == null)
|
||||||
{
|
{
|
||||||
mime = NanoHTTPD.MIME_DEFAULT_BINARY;
|
mime = TFM_HTTPD_Manager.MIME_DEFAULT_BINARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate etag
|
// Calculate etag
|
||||||
|
@ -20,9 +20,9 @@ import static org.apache.commons.lang3.StringEscapeUtils.*;
|
|||||||
|
|
||||||
public class Module_help extends TFM_HTTPD_Module
|
public class Module_help extends TFM_HTTPD_Module
|
||||||
{
|
{
|
||||||
public Module_help(String uri, NanoHTTPD.Method method, Map<String, String> headers, Map<String, String> params, Map<String, String> files)
|
public Module_help(NanoHTTPD.HTTPSession session)
|
||||||
{
|
{
|
||||||
super(uri, method, headers, params, files);
|
super(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -147,4 +147,9 @@ public class Module_help extends TFM_HTTPD_Module
|
|||||||
{
|
{
|
||||||
return ".commandName{font-weight:bold;}.commandDescription{padding-left:15px;}li{margin:.15em;padding:.15em;}";
|
return ".commandName{font-weight:bold;}.commandDescription{padding-left:15px;}li{margin:.15em;padding:.15em;}";
|
||||||
}
|
}
|
||||||
|
// @Override
|
||||||
|
// public String getScript()
|
||||||
|
// {
|
||||||
|
// return "$(document).ready(function(){console.log(\"Ready\");});";
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -8,9 +7,9 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public class Module_list extends TFM_HTTPD_Module
|
public class Module_list extends TFM_HTTPD_Module
|
||||||
{
|
{
|
||||||
public Module_list(String uri, NanoHTTPD.Method method, Map<String, String> headers, Map<String, String> params, Map<String, String> files)
|
public Module_list(NanoHTTPD.HTTPSession session)
|
||||||
{
|
{
|
||||||
super(uri, method, headers, params, files);
|
super(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
|
|
||||||
|
public class Module_permbans extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
public Module_permbans(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NanoHTTPD.Response getResponse()
|
||||||
|
{
|
||||||
|
File permbanFile = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE);
|
||||||
|
if (permbanFile.exists())
|
||||||
|
{
|
||||||
|
return TFM_HTTPD_Manager.serveFileBasic(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||||
|
"Error 404: Not Found - The requested resource was not found on this server.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
296
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_schematic.java
Normal file
296
src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_schematic.java
Normal file
@ -0,0 +1,296 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Method;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.lang3.StringEscapeUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class Module_schematic extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
private static final File SCHEMATIC_FOLDER = new File("./plugins/WorldEdit/schematics/");
|
||||||
|
private static final String REQUEST_FORM_FILE_ELEMENT_NAME = "schematicFile";
|
||||||
|
private static final Pattern SCHEMATIC_FILENAME_LC = Pattern.compile("^[a-z0-9]{1,30}\\.schematic$");
|
||||||
|
private static final String[] SCHEMATIC_FILTER = new String[]
|
||||||
|
{
|
||||||
|
"schematic"
|
||||||
|
};
|
||||||
|
private static final String UPLOAD_FORM =
|
||||||
|
"<form method=\"post\" name=\"schematicForm\" id=\"schematicForm\" action=\"/schematic/upload/\" enctype=\"multipart/form-data\">\n"
|
||||||
|
+ "<p>Select a schematic file to upload. Filenames must be alphanumeric, between 1 and 30 characters long (inclusive), and have a .schematic extension.</p>\n"
|
||||||
|
+ "<input type=\"file\" id=\"schematicFile\" name=\"schematicFile\" />\n"
|
||||||
|
+ "<br />\n"
|
||||||
|
+ "<button type=\"submit\">Submit</button>\n"
|
||||||
|
+ "</form>";
|
||||||
|
|
||||||
|
public Module_schematic(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response getResponse()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new TFM_HTTPD_PageBuilder(body(), title(), null, null).getResponse();
|
||||||
|
}
|
||||||
|
catch (ResponseOverrideException ex)
|
||||||
|
{
|
||||||
|
return ex.getResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String title()
|
||||||
|
{
|
||||||
|
return "TotalFreedomMod :: Schematic Manager";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String body() throws ResponseOverrideException
|
||||||
|
{
|
||||||
|
if (!SCHEMATIC_FOLDER.exists())
|
||||||
|
{
|
||||||
|
return HTMLGenerationTools.paragraph("Can't find the WorldEdit schematic folder.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringBuilder out = new StringBuilder();
|
||||||
|
|
||||||
|
final String[] args = StringUtils.split(uri, "/");
|
||||||
|
final ModuleMode mode = ModuleMode.getMode(getArg(args, 1));
|
||||||
|
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case LIST:
|
||||||
|
{
|
||||||
|
Collection<File> schematics = FileUtils.listFiles(SCHEMATIC_FOLDER, SCHEMATIC_FILTER, false);
|
||||||
|
|
||||||
|
final List<String> schematicsFormatted = new ArrayList<String>();
|
||||||
|
for (File schematic : schematics)
|
||||||
|
{
|
||||||
|
String filename = StringEscapeUtils.escapeHtml4(schematic.getName());
|
||||||
|
schematicsFormatted.add("<li><a href=\"/schematic/download?schematicName=" + filename + "\">" + filename + "</a></li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(schematicsFormatted, new Comparator<String>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int compare(String a, String b)
|
||||||
|
{
|
||||||
|
return a.toLowerCase().compareTo(b.toLowerCase());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
out
|
||||||
|
.append(HTMLGenerationTools.heading("Schematics:", 1))
|
||||||
|
.append("<ul>")
|
||||||
|
.append(StringUtils.join(schematicsFormatted, "\r\n"))
|
||||||
|
.append("</ul>");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DOWNLOAD:
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
throw new ResponseOverrideException(downloadSchematic(params.get("schematicName")));
|
||||||
|
}
|
||||||
|
catch (SchematicTransferException ex)
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Error downloading schematic: " + ex.getMessage()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UPLOAD:
|
||||||
|
{
|
||||||
|
final String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||||
|
if (!isAuthorized(remoteAddress))
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Schematic upload access denied: Your IP, " + remoteAddress + ", is not registered to a superadmin on this server."));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (method == Method.POST)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uploadSchematic();
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Schematic uploaded successfully."));
|
||||||
|
}
|
||||||
|
catch (SchematicTransferException ex)
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Error uploading schematic: " + ex.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out.append(UPLOAD_FORM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
out.append(HTMLGenerationTools.paragraph("Invalid request mode."));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean uploadSchematic() throws SchematicTransferException
|
||||||
|
{
|
||||||
|
Map<String, String> files = getFiles();
|
||||||
|
|
||||||
|
final String tempFileName = files.get(REQUEST_FORM_FILE_ELEMENT_NAME);
|
||||||
|
if (tempFileName == null)
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("No file transmitted to server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final File tempFile = new File(tempFileName);
|
||||||
|
if (!tempFile.exists())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException();
|
||||||
|
}
|
||||||
|
|
||||||
|
String origFileName = params.get(REQUEST_FORM_FILE_ELEMENT_NAME);
|
||||||
|
if (origFileName == null || (origFileName = origFileName.trim()).isEmpty())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Can't resolve original file name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempFile.length() > FileUtils.ONE_KB * 64L)
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Schematic is too big (64kb max).");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SCHEMATIC_FILENAME_LC.matcher(origFileName.toLowerCase()).find())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("File name must be alphanumeric, between 1 and 30 characters long (inclusive), and have a \".schematic\" extension.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final File targetFile = new File(SCHEMATIC_FOLDER.getPath(), origFileName);
|
||||||
|
if (targetFile.exists())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Schematic already exists on the server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileUtils.copyFile(tempFile, targetFile);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
throw new SchematicTransferException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response downloadSchematic(String schematicName) throws SchematicTransferException
|
||||||
|
{
|
||||||
|
if (schematicName == null || !SCHEMATIC_FILENAME_LC.matcher((schematicName = schematicName.trim()).toLowerCase()).find())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Invalid schematic name requested: " + schematicName);
|
||||||
|
}
|
||||||
|
|
||||||
|
final File targetFile = new File(SCHEMATIC_FOLDER.getPath(), schematicName);
|
||||||
|
if (!targetFile.exists())
|
||||||
|
{
|
||||||
|
throw new SchematicTransferException("Schematic not found: " + schematicName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Response response = TFM_HTTPD_Manager.serveFileBasic(targetFile);
|
||||||
|
|
||||||
|
response.addHeader("Content-Disposition", "attachment; filename=" + targetFile.getName() + ";");
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isAuthorized(String remoteAddress)
|
||||||
|
{
|
||||||
|
TFM_Superadmin entry = TFM_SuperadminList.getAdminEntryByIP(remoteAddress);
|
||||||
|
return entry != null && entry.isActivated();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SchematicTransferException extends Exception
|
||||||
|
{
|
||||||
|
public SchematicTransferException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public SchematicTransferException(String string)
|
||||||
|
{
|
||||||
|
super(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ResponseOverrideException extends Exception
|
||||||
|
{
|
||||||
|
private final Response response;
|
||||||
|
|
||||||
|
public ResponseOverrideException(Response response)
|
||||||
|
{
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response getResponse()
|
||||||
|
{
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getArg(String[] args, int index)
|
||||||
|
{
|
||||||
|
String out = (args.length == index + 1 ? args[index] : null);
|
||||||
|
return (out == null ? null : (out.trim().isEmpty() ? null : out.trim()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static enum ModuleMode
|
||||||
|
{
|
||||||
|
LIST("list"),
|
||||||
|
UPLOAD("upload"),
|
||||||
|
DOWNLOAD("download"),
|
||||||
|
INVALID(null);
|
||||||
|
//
|
||||||
|
private final String modeName;
|
||||||
|
|
||||||
|
private ModuleMode(String modeName)
|
||||||
|
{
|
||||||
|
this.modeName = modeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return this.modeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModuleMode getMode(String needle)
|
||||||
|
{
|
||||||
|
for (ModuleMode mode : values())
|
||||||
|
{
|
||||||
|
final String haystack = mode.toString();
|
||||||
|
if (haystack != null && haystack.equalsIgnoreCase(needle))
|
||||||
|
{
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.*;
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -67,17 +63,21 @@ public abstract class NanoHTTPD
|
|||||||
*/
|
*/
|
||||||
public static final String MIME_HTML = "text/html";
|
public static final String MIME_HTML = "text/html";
|
||||||
/**
|
/**
|
||||||
* Common mime type for dynamic content: binary
|
* Pseudo-Parameter to use to store the actual query string in the parameters map for later re-processing.
|
||||||
*/
|
*/
|
||||||
public static final String MIME_DEFAULT_BINARY = "application/octet-stream";
|
private static final String QUERY_STRING_PARAMETER = "NanoHttpd.QUERY_STRING";
|
||||||
private final String hostname;
|
private final String hostname;
|
||||||
private final int myPort;
|
private final int myPort;
|
||||||
private ServerSocket myServerSocket;
|
private ServerSocket myServerSocket;
|
||||||
private Thread myThread;
|
private Thread myThread;
|
||||||
/**
|
/**
|
||||||
* Pseudo-Parameter to use to store the actual query string in the parameters map for later re-processing.
|
* Pluggable strategy for asynchronously executing requests.
|
||||||
*/
|
*/
|
||||||
private static final String QUERY_STRING_PARAMETER = "NanoHttpd.QUERY_STRING";
|
private AsyncRunner asyncRunner;
|
||||||
|
/**
|
||||||
|
* Pluggable strategy for creating and cleaning up temporary files.
|
||||||
|
*/
|
||||||
|
private TempFileManagerFactory tempFileManagerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an HTTP server on given port.
|
* Constructs an HTTP server on given port.
|
||||||
@ -98,8 +98,51 @@ public abstract class NanoHTTPD
|
|||||||
setAsyncRunner(new DefaultAsyncRunner());
|
setAsyncRunner(new DefaultAsyncRunner());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final void safeClose(ServerSocket serverSocket)
|
||||||
|
{
|
||||||
|
if (serverSocket != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
serverSocket.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final void safeClose(Socket socket)
|
||||||
|
{
|
||||||
|
if (socket != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final void safeClose(Closeable closeable)
|
||||||
|
{
|
||||||
|
if (closeable != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
closeable.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the server.
|
* Start the server.
|
||||||
|
*
|
||||||
* @throws IOException if the socket is in use.
|
* @throws IOException if the socket is in use.
|
||||||
*/
|
*/
|
||||||
public void start() throws IOException
|
public void start() throws IOException
|
||||||
@ -134,7 +177,7 @@ public abstract class NanoHTTPD
|
|||||||
{
|
{
|
||||||
outputStream = finalAccept.getOutputStream();
|
outputStream = finalAccept.getOutputStream();
|
||||||
TempFileManager tempFileManager = tempFileManagerFactory.create();
|
TempFileManager tempFileManager = tempFileManagerFactory.create();
|
||||||
HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream);
|
HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream, finalAccept);
|
||||||
while (!finalAccept.isClosed())
|
while (!finalAccept.isClosed())
|
||||||
{
|
{
|
||||||
session.execute();
|
session.execute();
|
||||||
@ -187,20 +230,39 @@ public abstract class NanoHTTPD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int getListeningPort()
|
||||||
|
{
|
||||||
|
return myServerSocket == null ? -1 : myServerSocket.getLocalPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean wasStarted()
|
||||||
|
{
|
||||||
|
return myServerSocket != null && myThread != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isAlive()
|
||||||
|
{
|
||||||
|
return wasStarted() && !myServerSocket.isClosed() && myThread.isAlive();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override this to customize the server.
|
* Override this to customize the server.
|
||||||
* <p/>
|
* <p/>
|
||||||
* <p/>
|
* <p/>
|
||||||
* (By default, this delegates to serveFile() and allows directory listing.)
|
* (By default, this delegates to serveFile() and allows directory listing.)
|
||||||
*
|
*
|
||||||
* @param uri Percent-decoded URI without parameters, for example "/index.cgi"
|
* @param uri Percent-decoded URI without parameters, for example "/index.cgi"
|
||||||
* @param method "GET", "POST" etc.
|
* @param method "GET", "POST" etc.
|
||||||
* @param parms Parsed, percent decoded parameters from URI and, in case of POST, data.
|
* @param parms Parsed, percent decoded parameters from URI and, in case of POST, data.
|
||||||
* @param headers Header entries, percent decoded
|
* @param headers Header entries, percent decoded
|
||||||
* @return HTTP response, see class Response for details
|
* @return HTTP response, see class Response for details
|
||||||
*/
|
*/
|
||||||
public abstract Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms,
|
@Deprecated
|
||||||
Map<String, String> files);
|
public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms,
|
||||||
|
Map<String, String> files)
|
||||||
|
{
|
||||||
|
return new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override this to customize the server.
|
* Override this to customize the server.
|
||||||
@ -211,32 +273,32 @@ public abstract class NanoHTTPD
|
|||||||
* @param session The HTTP session
|
* @param session The HTTP session
|
||||||
* @return HTTP response, see class Response for details
|
* @return HTTP response, see class Response for details
|
||||||
*/
|
*/
|
||||||
protected Response serve(HTTPSession session)
|
public Response serve(HTTPSession session)
|
||||||
{
|
{
|
||||||
Map<String, String> files = new HashMap<String, String>();
|
Map<String, String> files = new HashMap<String, String>();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
session.parseBody(files);
|
|
||||||
}
|
|
||||||
catch (IOException ioe)
|
|
||||||
{
|
|
||||||
return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
|
|
||||||
}
|
|
||||||
catch (ResponseException re)
|
|
||||||
{
|
|
||||||
return new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
String uri = session.getUri();
|
|
||||||
Method method = session.getMethod();
|
Method method = session.getMethod();
|
||||||
Map<String, String> parms = session.getParms();
|
if (Method.PUT.equals(method) || Method.POST.equals(method))
|
||||||
Map<String, String> headers = session.getHeaders();
|
{
|
||||||
return serve(uri, method, headers, parms, files);
|
try
|
||||||
|
{
|
||||||
|
session.parseBody(files);
|
||||||
|
}
|
||||||
|
catch (IOException ioe)
|
||||||
|
{
|
||||||
|
return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
|
||||||
|
}
|
||||||
|
catch (ResponseException re)
|
||||||
|
{
|
||||||
|
return new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return serve(session.getUri(), method, session.getHeaders(), session.getParms(), files);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode percent encoded <code>String</code> values.
|
* Decode percent encoded <code>String</code> values.
|
||||||
|
*
|
||||||
* @param str the percent encoded <code>String</code>
|
* @param str the percent encoded <code>String</code>
|
||||||
* @return expanded form of the input, for example "foo%20bar" becomes "foo bar"
|
* @return expanded form of the input, for example "foo%20bar" becomes "foo bar"
|
||||||
*/
|
*/
|
||||||
@ -299,6 +361,36 @@ public abstract class NanoHTTPD
|
|||||||
return parms;
|
return parms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------- //
|
||||||
|
//
|
||||||
|
// Threading Strategy.
|
||||||
|
//
|
||||||
|
// ------------------------------------------------------------------------------- //
|
||||||
|
/**
|
||||||
|
* Pluggable strategy for asynchronously executing requests.
|
||||||
|
*
|
||||||
|
* @param asyncRunner new strategy for handling threads.
|
||||||
|
*/
|
||||||
|
public void setAsyncRunner(AsyncRunner asyncRunner)
|
||||||
|
{
|
||||||
|
this.asyncRunner = asyncRunner;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------- //
|
||||||
|
//
|
||||||
|
// Temp file handling strategy.
|
||||||
|
//
|
||||||
|
// ------------------------------------------------------------------------------- //
|
||||||
|
/**
|
||||||
|
* Pluggable strategy for creating and cleaning up temporary files.
|
||||||
|
*
|
||||||
|
* @param tempFileManagerFactory new strategy for handling temp files.
|
||||||
|
*/
|
||||||
|
public void setTempFileManagerFactory(TempFileManagerFactory tempFileManagerFactory)
|
||||||
|
{
|
||||||
|
this.tempFileManagerFactory = tempFileManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP Request methods, with the ability to decode a <code>String</code> back to its enum value.
|
* HTTP Request methods, with the ability to decode a <code>String</code> back to its enum value.
|
||||||
*/
|
*/
|
||||||
@ -318,24 +410,6 @@ public abstract class NanoHTTPD
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------- //
|
|
||||||
//
|
|
||||||
// Threading Strategy.
|
|
||||||
//
|
|
||||||
// ------------------------------------------------------------------------------- //
|
|
||||||
/**
|
|
||||||
* Pluggable strategy for asynchronously executing requests.
|
|
||||||
*/
|
|
||||||
private AsyncRunner asyncRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pluggable strategy for asynchronously executing requests.
|
|
||||||
* @param asyncRunner new strategy for handling threads.
|
|
||||||
*/
|
|
||||||
public void setAsyncRunner(AsyncRunner asyncRunner)
|
|
||||||
{
|
|
||||||
this.asyncRunner = asyncRunner;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pluggable strategy for asynchronously executing requests.
|
* Pluggable strategy for asynchronously executing requests.
|
||||||
@ -345,9 +419,46 @@ public abstract class NanoHTTPD
|
|||||||
void exec(Runnable code);
|
void exec(Runnable code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory to create temp file managers.
|
||||||
|
*/
|
||||||
|
public interface TempFileManagerFactory
|
||||||
|
{
|
||||||
|
TempFileManager create();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------- //
|
||||||
|
/**
|
||||||
|
* Temp file manager.
|
||||||
|
* <p/>
|
||||||
|
* <p>Temp file managers are created 1-to-1 with incoming requests, to create and cleanup
|
||||||
|
* temporary files created as a result of handling the request.</p>
|
||||||
|
*/
|
||||||
|
public interface TempFileManager
|
||||||
|
{
|
||||||
|
TempFile createTempFile() throws Exception;
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A temp file.
|
||||||
|
* <p/>
|
||||||
|
* <p>Temp files are responsible for managing the actual temporary storage and cleaning
|
||||||
|
* themselves up when no longer needed.</p>
|
||||||
|
*/
|
||||||
|
public interface TempFile
|
||||||
|
{
|
||||||
|
OutputStream open() throws Exception;
|
||||||
|
|
||||||
|
void delete() throws Exception;
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default threading strategy for NanoHttpd.
|
* Default threading strategy for NanoHttpd.
|
||||||
*
|
* <p/>
|
||||||
* <p>By default, the server spawns a new Thread for every incoming request. These are set
|
* <p>By default, the server spawns a new Thread for every incoming request. These are set
|
||||||
* to <i>daemon</i> status, and named according to the request number. The name is
|
* to <i>daemon</i> status, and named according to the request number. The name is
|
||||||
* useful when profiling the application.</p>
|
* useful when profiling the application.</p>
|
||||||
@ -366,76 +477,10 @@ public abstract class NanoHTTPD
|
|||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------- //
|
|
||||||
//
|
|
||||||
// Temp file handling strategy.
|
|
||||||
//
|
|
||||||
// ------------------------------------------------------------------------------- //
|
|
||||||
/**
|
|
||||||
* Pluggable strategy for creating and cleaning up temporary files.
|
|
||||||
*/
|
|
||||||
private TempFileManagerFactory tempFileManagerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pluggable strategy for creating and cleaning up temporary files.
|
|
||||||
* @param tempFileManagerFactory new strategy for handling temp files.
|
|
||||||
*/
|
|
||||||
public void setTempFileManagerFactory(TempFileManagerFactory tempFileManagerFactory)
|
|
||||||
{
|
|
||||||
this.tempFileManagerFactory = tempFileManagerFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory to create temp file managers.
|
|
||||||
*/
|
|
||||||
public interface TempFileManagerFactory
|
|
||||||
{
|
|
||||||
TempFileManager create();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Temp file manager.
|
|
||||||
*
|
|
||||||
* <p>Temp file managers are created 1-to-1 with incoming requests, to create and cleanup
|
|
||||||
* temporary files created as a result of handling the request.</p>
|
|
||||||
*/
|
|
||||||
public interface TempFileManager
|
|
||||||
{
|
|
||||||
TempFile createTempFile() throws Exception;
|
|
||||||
|
|
||||||
void clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A temp file.
|
|
||||||
*
|
|
||||||
* <p>Temp files are responsible for managing the actual temporary storage and cleaning
|
|
||||||
* themselves up when no longer needed.</p>
|
|
||||||
*/
|
|
||||||
public interface TempFile
|
|
||||||
{
|
|
||||||
OutputStream open() throws Exception;
|
|
||||||
|
|
||||||
void delete() throws Exception;
|
|
||||||
|
|
||||||
String getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default strategy for creating and cleaning up temporary files.
|
* Default strategy for creating and cleaning up temporary files.
|
||||||
*/
|
* <p/>
|
||||||
private class DefaultTempFileManagerFactory implements TempFileManagerFactory
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public TempFileManager create()
|
|
||||||
{
|
|
||||||
return new DefaultTempFileManager();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default strategy for creating and cleaning up temporary files.
|
|
||||||
*
|
|
||||||
* <p></p>This class stores its files in the standard location (that is,
|
* <p></p>This class stores its files in the standard location (that is,
|
||||||
* wherever <code>java.io.tmpdir</code> points to). Files are added
|
* wherever <code>java.io.tmpdir</code> points to). Files are added
|
||||||
* to an internal list, and deleted when no longer needed (that is,
|
* to an internal list, and deleted when no longer needed (that is,
|
||||||
@ -480,7 +525,7 @@ public abstract class NanoHTTPD
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Default strategy for creating and cleaning up temporary files.
|
* Default strategy for creating and cleaning up temporary files.
|
||||||
*
|
* <p/>
|
||||||
* <p></p></[>By default, files are created by <code>File.createTempFile()</code> in
|
* <p></p></[>By default, files are created by <code>File.createTempFile()</code> in
|
||||||
* the directory specified.</p>
|
* the directory specified.</p>
|
||||||
*/
|
*/
|
||||||
@ -515,7 +560,6 @@ public abstract class NanoHTTPD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------- //
|
|
||||||
/**
|
/**
|
||||||
* HTTP response. Return one of these from serve().
|
* HTTP response. Return one of these from serve().
|
||||||
*/
|
*/
|
||||||
@ -541,6 +585,10 @@ public abstract class NanoHTTPD
|
|||||||
* The request method that spawned this response.
|
* The request method that spawned this response.
|
||||||
*/
|
*/
|
||||||
private Method requestMethod;
|
private Method requestMethod;
|
||||||
|
/**
|
||||||
|
* Use chunkedTransfer
|
||||||
|
*/
|
||||||
|
private boolean chunkedTransfer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor: response = HTTP_OK, mime = MIME_HTML and your supplied message
|
* Default constructor: response = HTTP_OK, mime = MIME_HTML and your supplied message
|
||||||
@ -622,31 +670,15 @@ public abstract class NanoHTTPD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int pending = data != null ? data.available() : -1; // This is to support partial sends, see serveFile()
|
pw.print("Connection: keep-alive\r\n");
|
||||||
if (pending > 0)
|
|
||||||
|
if (requestMethod != Method.HEAD && chunkedTransfer)
|
||||||
{
|
{
|
||||||
pw.print("Connection: keep-alive\r\n");
|
sendAsChunked(outputStream, pw);
|
||||||
pw.print("Content-Length: " + pending + "\r\n");
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
pw.print("\r\n");
|
|
||||||
pw.flush();
|
|
||||||
|
|
||||||
if (requestMethod != Method.HEAD && data != null)
|
|
||||||
{
|
{
|
||||||
int BUFFER_SIZE = 16 * 1024;
|
sendAsFixedLength(outputStream, pw);
|
||||||
byte[] buff = new byte[BUFFER_SIZE];
|
|
||||||
while (pending > 0)
|
|
||||||
{
|
|
||||||
int read = data.read(buff, 0, ((pending > BUFFER_SIZE) ? BUFFER_SIZE : pending));
|
|
||||||
if (read <= 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
outputStream.write(buff, 0, read);
|
|
||||||
|
|
||||||
pending -= read;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
safeClose(data);
|
safeClose(data);
|
||||||
@ -657,6 +689,50 @@ public abstract class NanoHTTPD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendAsChunked(OutputStream outputStream, PrintWriter pw) throws IOException
|
||||||
|
{
|
||||||
|
pw.print("Transfer-Encoding: chunked\r\n");
|
||||||
|
pw.print("\r\n");
|
||||||
|
pw.flush();
|
||||||
|
int BUFFER_SIZE = 16 * 1024;
|
||||||
|
byte[] CRLF = "\r\n".getBytes();
|
||||||
|
byte[] buff = new byte[BUFFER_SIZE];
|
||||||
|
int read;
|
||||||
|
while ((read = data.read(buff)) > 0)
|
||||||
|
{
|
||||||
|
outputStream.write(String.format("%x\r\n", read).getBytes());
|
||||||
|
outputStream.write(buff, 0, read);
|
||||||
|
outputStream.write(CRLF);
|
||||||
|
}
|
||||||
|
outputStream.write(String.format("0\r\n\r\n").getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendAsFixedLength(OutputStream outputStream, PrintWriter pw) throws IOException
|
||||||
|
{
|
||||||
|
int pending = data != null ? data.available() : 0; // This is to support partial sends, see serveFile()
|
||||||
|
pw.print("Content-Length: " + pending + "\r\n");
|
||||||
|
|
||||||
|
pw.print("\r\n");
|
||||||
|
pw.flush();
|
||||||
|
|
||||||
|
if (requestMethod != Method.HEAD && data != null)
|
||||||
|
{
|
||||||
|
int BUFFER_SIZE = 16 * 1024;
|
||||||
|
byte[] buff = new byte[BUFFER_SIZE];
|
||||||
|
while (pending > 0)
|
||||||
|
{
|
||||||
|
int read = data.read(buff, 0, ((pending > BUFFER_SIZE) ? BUFFER_SIZE : pending));
|
||||||
|
if (read <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
outputStream.write(buff, 0, read);
|
||||||
|
|
||||||
|
pending -= read;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Status getStatus()
|
public Status getStatus()
|
||||||
{
|
{
|
||||||
return status;
|
return status;
|
||||||
@ -697,6 +773,11 @@ public abstract class NanoHTTPD
|
|||||||
this.requestMethod = requestMethod;
|
this.requestMethod = requestMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setChunkedTransfer(boolean chunkedTransfer)
|
||||||
|
{
|
||||||
|
this.chunkedTransfer = chunkedTransfer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some HTTP response status codes
|
* Some HTTP response status codes
|
||||||
*/
|
*/
|
||||||
@ -727,6 +808,40 @@ public abstract class NanoHTTPD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class ResponseException extends Exception
|
||||||
|
{
|
||||||
|
private final Response.Status status;
|
||||||
|
|
||||||
|
public ResponseException(Response.Status status, String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseException(Response.Status status, String message, Exception e)
|
||||||
|
{
|
||||||
|
super(message, e);
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response.Status getStatus()
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default strategy for creating and cleaning up temporary files.
|
||||||
|
*/
|
||||||
|
private class DefaultTempFileManagerFactory implements TempFileManagerFactory
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public TempFileManager create()
|
||||||
|
{
|
||||||
|
return new DefaultTempFileManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles one session, i.e. parses the HTTP request and returns the response.
|
* Handles one session, i.e. parses the HTTP request and returns the response.
|
||||||
*/
|
*/
|
||||||
@ -734,20 +849,23 @@ public abstract class NanoHTTPD
|
|||||||
{
|
{
|
||||||
public static final int BUFSIZE = 8192;
|
public static final int BUFSIZE = 8192;
|
||||||
private final TempFileManager tempFileManager;
|
private final TempFileManager tempFileManager;
|
||||||
private InputStream inputStream;
|
|
||||||
private final OutputStream outputStream;
|
private final OutputStream outputStream;
|
||||||
|
private final Socket socket;
|
||||||
|
private InputStream inputStream;
|
||||||
private int splitbyte;
|
private int splitbyte;
|
||||||
private int rlen;
|
private int rlen;
|
||||||
private String uri;
|
private String uri;
|
||||||
private Method method;
|
private Method method;
|
||||||
private Map<String, String> parms;
|
private Map<String, String> parms;
|
||||||
private Map<String, String> headers;
|
private Map<String, String> headers;
|
||||||
|
private CookieHandler cookies;
|
||||||
|
|
||||||
public HTTPSession(TempFileManager tempFileManager, InputStream inputStream, OutputStream outputStream)
|
public HTTPSession(TempFileManager tempFileManager, InputStream inputStream, OutputStream outputStream, Socket socket)
|
||||||
{
|
{
|
||||||
this.tempFileManager = tempFileManager;
|
this.tempFileManager = tempFileManager;
|
||||||
this.inputStream = inputStream;
|
this.inputStream = inputStream;
|
||||||
this.outputStream = outputStream;
|
this.outputStream = outputStream;
|
||||||
|
this.socket = socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute() throws IOException
|
public void execute() throws IOException
|
||||||
@ -805,6 +923,8 @@ public abstract class NanoHTTPD
|
|||||||
|
|
||||||
uri = pre.get("uri");
|
uri = pre.get("uri");
|
||||||
|
|
||||||
|
cookies = new CookieHandler(headers);
|
||||||
|
|
||||||
// Ok, now do the serve()
|
// Ok, now do the serve()
|
||||||
Response r = serve(this);
|
Response r = serve(this);
|
||||||
if (r == null)
|
if (r == null)
|
||||||
@ -813,6 +933,7 @@ public abstract class NanoHTTPD
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
cookies.unloadQueue(r);
|
||||||
r.setRequestMethod(method);
|
r.setRequestMethod(method);
|
||||||
r.send(outputStream);
|
r.send(outputStream);
|
||||||
}
|
}
|
||||||
@ -840,7 +961,7 @@ public abstract class NanoHTTPD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseBody(Map<String, String> files) throws IOException, ResponseException
|
protected void parseBody(Map<String, String> files) throws IOException, ResponseException
|
||||||
{
|
{
|
||||||
RandomAccessFile randomAccessFile = null;
|
RandomAccessFile randomAccessFile = null;
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
@ -911,7 +1032,7 @@ public abstract class NanoHTTPD
|
|||||||
String boundaryStartString = "boundary=";
|
String boundaryStartString = "boundary=";
|
||||||
int boundaryContentStart = contentTypeHeader.indexOf(boundaryStartString) + boundaryStartString.length();
|
int boundaryContentStart = contentTypeHeader.indexOf(boundaryStartString) + boundaryStartString.length();
|
||||||
String boundary = contentTypeHeader.substring(boundaryContentStart, contentTypeHeader.length());
|
String boundary = contentTypeHeader.substring(boundaryContentStart, contentTypeHeader.length());
|
||||||
if (boundary.startsWith("\"") && boundary.startsWith("\""))
|
if (boundary.startsWith("\"") && boundary.endsWith("\""))
|
||||||
{
|
{
|
||||||
boundary = boundary.substring(1, boundary.length() - 1);
|
boundary = boundary.substring(1, boundary.length() - 1);
|
||||||
}
|
}
|
||||||
@ -1186,7 +1307,7 @@ public abstract class NanoHTTPD
|
|||||||
path = tempFile.getName();
|
path = tempFile.getName();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{ // Catch exception if any
|
||||||
TFM_Log.severe(e);
|
TFM_Log.severe(e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@ -1281,84 +1402,141 @@ public abstract class NanoHTTPD
|
|||||||
{
|
{
|
||||||
return inputStream;
|
return inputStream;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static final class ResponseException extends Exception
|
public CookieHandler getCookies()
|
||||||
{
|
|
||||||
private final Response.Status status;
|
|
||||||
|
|
||||||
public ResponseException(Response.Status status, String message)
|
|
||||||
{
|
{
|
||||||
super(message);
|
return cookies;
|
||||||
this.status = status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseException(Response.Status status, String message, Exception e)
|
public Socket getSocket()
|
||||||
{
|
{
|
||||||
super(message, e);
|
return socket;
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response.Status getStatus()
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void safeClose(ServerSocket serverSocket)
|
public static class Cookie
|
||||||
{
|
{
|
||||||
if (serverSocket != null)
|
private String n, v, e;
|
||||||
|
|
||||||
|
public Cookie(String name, String value, String expires)
|
||||||
{
|
{
|
||||||
try
|
n = name;
|
||||||
{
|
v = value;
|
||||||
serverSocket.close();
|
e = expires;
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
|
||||||
{
|
public Cookie(String name, String value)
|
||||||
}
|
{
|
||||||
|
this(name, value, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cookie(String name, String value, int numDays)
|
||||||
|
{
|
||||||
|
n = name;
|
||||||
|
v = value;
|
||||||
|
e = getHTTPTime(numDays);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHTTPHeader()
|
||||||
|
{
|
||||||
|
String fmt = "%s=%s; expires=%s";
|
||||||
|
return String.format(fmt, n, v, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHTTPTime(int days)
|
||||||
|
{
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
||||||
|
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, days);
|
||||||
|
return dateFormat.format(calendar.getTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void safeClose(Socket socket)
|
/**
|
||||||
|
* Provides rudimentary support for cookies.
|
||||||
|
* Doesn't support 'path', 'secure' nor 'httpOnly'.
|
||||||
|
* Feel free to improve it and/or add unsupported features.
|
||||||
|
*
|
||||||
|
* @author LordFokas
|
||||||
|
*/
|
||||||
|
public class CookieHandler implements Iterable<String>
|
||||||
{
|
{
|
||||||
if (socket != null)
|
private HashMap<String, String> cookies = new HashMap<String, String>();
|
||||||
|
private ArrayList<Cookie> queue = new ArrayList<Cookie>();
|
||||||
|
|
||||||
|
public CookieHandler(Map<String, String> httpHeaders)
|
||||||
{
|
{
|
||||||
try
|
String raw = httpHeaders.get("cookie");
|
||||||
{
|
if (raw != null)
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
{
|
||||||
|
String[] tokens = raw.split(";");
|
||||||
|
for (String token : tokens)
|
||||||
|
{
|
||||||
|
String[] data = token.trim().split("=");
|
||||||
|
if (data.length == 2)
|
||||||
|
{
|
||||||
|
cookies.put(data[0], data[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static final void safeClose(Closeable closeable)
|
@Override
|
||||||
{
|
public Iterator<String> iterator()
|
||||||
if (closeable != null)
|
|
||||||
{
|
{
|
||||||
try
|
return cookies.keySet().iterator();
|
||||||
{
|
}
|
||||||
closeable.close();
|
|
||||||
}
|
/**
|
||||||
catch (IOException e)
|
* Read a cookie from the HTTP Headers.
|
||||||
|
*
|
||||||
|
* @param name The cookie's name.
|
||||||
|
* @return The cookie's value if it exists, null otherwise.
|
||||||
|
*/
|
||||||
|
public String read(String name)
|
||||||
|
{
|
||||||
|
return cookies.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a cookie.
|
||||||
|
*
|
||||||
|
* @param name The cookie's name.
|
||||||
|
* @param value The cookie's value.
|
||||||
|
* @param expires How many days until the cookie expires.
|
||||||
|
*/
|
||||||
|
public void set(String name, String value, int expires)
|
||||||
|
{
|
||||||
|
queue.add(new Cookie(name, value, Cookie.getHTTPTime(expires)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(Cookie cookie)
|
||||||
|
{
|
||||||
|
queue.add(cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a cookie with an expiration date from a month ago, effectively deleting it on the client side.
|
||||||
|
*
|
||||||
|
* @param name The cookie name.
|
||||||
|
*/
|
||||||
|
public void delete(String name)
|
||||||
|
{
|
||||||
|
set(name, "-delete-", -30);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internally used by the webserver to add all queued cookies into the Response's HTTP Headers.
|
||||||
|
*
|
||||||
|
* @param response The Response object to which headers the queued cookies will be added.
|
||||||
|
*/
|
||||||
|
public void unloadQueue(Response response)
|
||||||
|
{
|
||||||
|
for (Cookie cookie : queue)
|
||||||
{
|
{
|
||||||
|
response.addHeader("Set-Cookie", cookie.getHTTPHeader());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getListeningPort()
|
|
||||||
{
|
|
||||||
return myServerSocket == null ? -1 : myServerSocket.getLocalPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean wasStarted()
|
|
||||||
{
|
|
||||||
return myServerSocket != null && myThread != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean isAlive()
|
|
||||||
{
|
|
||||||
return wasStarted() && !myServerSocket.isClosed() && myThread.isAlive();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,18 +1,27 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.Future;
|
import java.util.regex.Matcher;
|
||||||
import static me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.MIME_PLAINTEXT;
|
import java.util.regex.Pattern;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.HTTPSession;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
public class TFM_HTTPD_Manager
|
public class TFM_HTTPD_Manager
|
||||||
{
|
{
|
||||||
|
@Deprecated
|
||||||
|
public static String MIME_DEFAULT_BINARY = "application/octet-stream";
|
||||||
|
//
|
||||||
|
private static final Pattern EXT_REGEX = Pattern.compile("\\.([^\\.\\s]+)$");
|
||||||
|
//
|
||||||
public static final int PORT = TFM_ConfigEntry.HTTPD_PORT.getInteger();
|
public static final int PORT = TFM_ConfigEntry.HTTPD_PORT.getInteger();
|
||||||
//
|
//
|
||||||
private final TFM_HTTPD httpd = new TFM_HTTPD(PORT);
|
private final TFM_HTTPD httpd = new TFM_HTTPD(PORT);
|
||||||
@ -61,34 +70,118 @@ public class TFM_HTTPD_Manager
|
|||||||
|
|
||||||
private static enum ModuleType
|
private static enum ModuleType
|
||||||
{
|
{
|
||||||
DUMP(false, "dump"),
|
DUMP(new ModuleExecutable(false, "dump")
|
||||||
HELP(true, "help"),
|
|
||||||
LIST(true, "list"),
|
|
||||||
FILE(false, "file");
|
|
||||||
private final boolean runOnBukkitThread;
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
private ModuleType(boolean runOnBukkitThread, String name)
|
|
||||||
{
|
{
|
||||||
this.runOnBukkitThread = runOnBukkitThread;
|
@Override
|
||||||
this.name = name;
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Response(Response.Status.OK, NanoHTTPD.MIME_PLAINTEXT, "The DUMP module is disabled. It is intended for debugging use only.");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
HELP(new ModuleExecutable(true, "help")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_help(session).getResponse();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
LIST(new ModuleExecutable(true, "list")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_list(session).getResponse();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
FILE(new ModuleExecutable(false, "file")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_file(session).getResponse();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
SCHEMATIC(new ModuleExecutable(false, "schematic")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_schematic(session).getResponse();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
PERMBANS(new ModuleExecutable(false, "permbans")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_permbans(session).getResponse();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//
|
||||||
|
private final ModuleExecutable moduleExecutable;
|
||||||
|
|
||||||
|
private ModuleType(ModuleExecutable moduleExecutable)
|
||||||
|
{
|
||||||
|
this.moduleExecutable = moduleExecutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRunOnBukkitThread()
|
private abstract static class ModuleExecutable
|
||||||
{
|
{
|
||||||
return runOnBukkitThread;
|
private final boolean runOnBukkitThread;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public ModuleExecutable(boolean runOnBukkitThread, String name)
|
||||||
|
{
|
||||||
|
this.runOnBukkitThread = runOnBukkitThread;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response execute(final HTTPSession session)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (this.runOnBukkitThread)
|
||||||
|
{
|
||||||
|
return Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.plugin, new Callable<Response>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response call() throws Exception
|
||||||
|
{
|
||||||
|
return getResponse(session);
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return getResponse(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Response getResponse(HTTPSession session);
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public ModuleExecutable getModuleExecutable()
|
||||||
{
|
{
|
||||||
return name;
|
return moduleExecutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ModuleType getByName(String needle)
|
private static ModuleType getByName(String needle)
|
||||||
{
|
{
|
||||||
for (ModuleType type : values())
|
for (ModuleType type : values())
|
||||||
{
|
{
|
||||||
if (type.getName().equalsIgnoreCase(needle))
|
if (type.getModuleExecutable().getName().equalsIgnoreCase(needle))
|
||||||
{
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -110,63 +203,61 @@ public class TFM_HTTPD_Manager
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response serve(final String uri, final Method method, final Map<String, String> headers, final Map<String, String> params, final Map<String, String> files)
|
public Response serve(HTTPSession session)
|
||||||
{
|
{
|
||||||
Response response = null;
|
Response response;
|
||||||
|
|
||||||
final String[] args = StringUtils.split(uri, "/");
|
try
|
||||||
final ModuleType moduleType = args.length >= 1 ? ModuleType.getByName(args[0]) : ModuleType.FILE;
|
|
||||||
|
|
||||||
if (moduleType.isRunOnBukkitThread())
|
|
||||||
{
|
{
|
||||||
Future<Response> responseCall = Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.plugin, new Callable<Response>()
|
final String[] args = StringUtils.split(session.getUri(), "/");
|
||||||
{
|
final ModuleType moduleType = args.length >= 1 ? ModuleType.getByName(args[0]) : ModuleType.FILE;
|
||||||
@Override
|
response = moduleType.getModuleExecutable().execute(session);
|
||||||
public Response call() throws Exception
|
|
||||||
{
|
|
||||||
switch (moduleType)
|
|
||||||
{
|
|
||||||
case HELP:
|
|
||||||
return new Module_help(uri, method, headers, params, files).getResponse();
|
|
||||||
case LIST:
|
|
||||||
return new Module_list(uri, method, headers, params, files).getResponse();
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = responseCall.get();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
switch (moduleType)
|
response = new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Error 500: Internal Server Error\r\n" + ex.getMessage() + "\r\n" + ExceptionUtils.getStackTrace(ex));
|
||||||
{
|
|
||||||
case DUMP:
|
|
||||||
response = new Module_dump(uri, method, headers, params, files).getResponse();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
response = new Module_file(uri, method, headers, params, files).getResponse();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (response == null)
|
if (response == null)
|
||||||
{
|
{
|
||||||
return new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Error 404: Not Found - The requested resource was not found on this server.");
|
response = new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Error 404: Not Found - The requested resource was not found on this server.");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Response serveFileBasic(File file)
|
||||||
|
{
|
||||||
|
Response response = null;
|
||||||
|
|
||||||
|
if (file != null && file.exists())
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return response;
|
String mimetype = null;
|
||||||
|
|
||||||
|
Matcher matcher = EXT_REGEX.matcher(file.getCanonicalPath());
|
||||||
|
if (matcher.find())
|
||||||
|
{
|
||||||
|
mimetype = Module_file.MIME_TYPES.get(matcher.group(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mimetype == null || mimetype.trim().isEmpty())
|
||||||
|
{
|
||||||
|
mimetype = MIME_DEFAULT_BINARY;
|
||||||
|
}
|
||||||
|
|
||||||
|
response = new Response(Response.Status.OK, mimetype, new FileInputStream(file));
|
||||||
|
response.addHeader("Content-Length", "" + file.length());
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_HTTPD_Manager getInstance()
|
public static TFM_HTTPD_Manager getInstance()
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.*;
|
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.*;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||||
|
|
||||||
public abstract class TFM_HTTPD_Module
|
public abstract class TFM_HTTPD_Module
|
||||||
{
|
{
|
||||||
@ -9,34 +12,57 @@ public abstract class TFM_HTTPD_Module
|
|||||||
protected final Method method;
|
protected final Method method;
|
||||||
protected final Map<String, String> headers;
|
protected final Map<String, String> headers;
|
||||||
protected final Map<String, String> params;
|
protected final Map<String, String> params;
|
||||||
protected final Map<String, String> files;
|
protected final Socket socket;
|
||||||
|
protected final HTTPSession session;
|
||||||
|
|
||||||
public TFM_HTTPD_Module(String uri, Method method, Map<String, String> headers, Map<String, String> params, Map<String, String> files)
|
public TFM_HTTPD_Module(HTTPSession session)
|
||||||
{
|
{
|
||||||
this.uri = uri;
|
this.uri = session.getUri();
|
||||||
this.method = method;
|
this.method = session.getMethod();
|
||||||
this.headers = headers;
|
this.headers = session.getHeaders();
|
||||||
this.params = params;
|
this.params = session.getParms();
|
||||||
this.files = files;
|
this.socket = session.getSocket();
|
||||||
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBody()
|
public String getBody()
|
||||||
{
|
{
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle()
|
public String getTitle()
|
||||||
{
|
{
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStyle()
|
public String getStyle()
|
||||||
{
|
{
|
||||||
return "";
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScript()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response getResponse()
|
public Response getResponse()
|
||||||
{
|
{
|
||||||
return new TFM_HTTPD_PageBuilder(getBody(), getTitle(), getStyle()).getResponse();
|
return new TFM_HTTPD_PageBuilder(getBody(), getTitle(), getStyle(), getScript()).getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Map<String, String> getFiles()
|
||||||
|
{
|
||||||
|
Map<String, String> files = new HashMap<String, String>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
session.parseBody(files);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,24 +10,32 @@ public class TFM_HTTPD_PageBuilder
|
|||||||
+ "<head>\r\n"
|
+ "<head>\r\n"
|
||||||
+ "<title>{$TITLE}</title>\r\n"
|
+ "<title>{$TITLE}</title>\r\n"
|
||||||
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n"
|
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n"
|
||||||
+ "<style type=\"text/css\">{$STYLE}</style>\r\n"
|
+ "{$STYLE}"
|
||||||
|
+ "{$SCRIPT}"
|
||||||
+ "</head>\r\n"
|
+ "</head>\r\n"
|
||||||
+ "<body>{$BODY}</body>\r\n"
|
+ "<body>\r\n{$BODY}</body>\r\n"
|
||||||
+ "</html>\r\n";
|
+ "</html>\r\n";
|
||||||
|
private static final String STYLE = "<style type=\"text/css\">{$STYLE}</style>\r\n";
|
||||||
|
private static final String SCRIPT =
|
||||||
|
"<script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js\"></script>\r\n"
|
||||||
|
+ "<script src=\"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js\"></script>\r\n"
|
||||||
|
+ "<script>\r\n{$SCRIPT}\r\n</script>\r\n";
|
||||||
//
|
//
|
||||||
private String body = "";
|
private String body = null;
|
||||||
private String title = "";
|
private String title = null;
|
||||||
private String style = "";
|
private String style = null;
|
||||||
|
private String script = null;
|
||||||
|
|
||||||
public TFM_HTTPD_PageBuilder()
|
public TFM_HTTPD_PageBuilder()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public TFM_HTTPD_PageBuilder(String body, String title, String style)
|
public TFM_HTTPD_PageBuilder(String body, String title, String style, String script)
|
||||||
{
|
{
|
||||||
this.body = body;
|
this.body = body;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.style = style;
|
this.style = style;
|
||||||
|
this.script = script;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBody(String body)
|
public void setBody(String body)
|
||||||
@ -45,6 +53,11 @@ public class TFM_HTTPD_PageBuilder
|
|||||||
this.style = style;
|
this.style = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setScript(String script)
|
||||||
|
{
|
||||||
|
this.script = script;
|
||||||
|
}
|
||||||
|
|
||||||
public Response getResponse()
|
public Response getResponse()
|
||||||
{
|
{
|
||||||
return new Response(this.toString());
|
return new Response(this.toString());
|
||||||
@ -53,6 +66,10 @@ public class TFM_HTTPD_PageBuilder
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return TEMPLATE.replace("{$BODY}", body).replace("{$TITLE}", title).replace("{$STYLE}", style);
|
return TEMPLATE
|
||||||
|
.replace("{$BODY}", this.body == null ? "" : this.body)
|
||||||
|
.replace("{$TITLE}", this.title == null ? "" : this.title)
|
||||||
|
.replace("{$STYLE}", this.style == null ? "" : STYLE.replace("{$STYLE}", this.style))
|
||||||
|
.replace("{$SCRIPT}", this.script == null ? "" : SCRIPT.replace("{$SCRIPT}", this.script));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ public class TFM_BlockListener implements Listener
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBlockFromTo(BlockFromToEvent event)
|
public void onBlockFromTo(BlockFromToEvent event)
|
||||||
{
|
{
|
||||||
if (!TFM_ConfigEntry.ALLOW_FLIUD_SPREAD.getBoolean())
|
if (!TFM_ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Listener;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class TFM_CustomListener implements Listener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onTelnetPreLogin(me.StevenLawson.BukkitTelnet.TelnetPreLoginEvent event)
|
||||||
|
{
|
||||||
|
String ip = event.getIp();
|
||||||
|
if (ip != null && !ip.isEmpty())
|
||||||
|
{
|
||||||
|
TFM_Superadmin admin = TFM_SuperadminList.getAdminEntryByIP(ip, true);
|
||||||
|
if (admin != null && (admin.isTelnetAdmin() || admin.isSeniorAdmin()))
|
||||||
|
{
|
||||||
|
event.setBypassPassword(true);
|
||||||
|
event.setName(admin.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,9 +7,9 @@ import java.util.List;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import me.StevenLawson.TotalFreedomMod.*;
|
import me.StevenLawson.TotalFreedomMod.*;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.EntryType;
|
import me.StevenLawson.TotalFreedomMod.Commands.Command_landmine;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -397,10 +397,10 @@ public class TFM_PlayerListener implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
|
Iterator<Command_landmine.TFM_LandmineData> landmines = Command_landmine.TFM_LandmineData.landmines.iterator();
|
||||||
while (landmines.hasNext())
|
while (landmines.hasNext())
|
||||||
{
|
{
|
||||||
TFM_LandmineData landmine = landmines.next();
|
Command_landmine.TFM_LandmineData landmine = landmines.next();
|
||||||
|
|
||||||
Location location = landmine.location;
|
Location location = landmine.location;
|
||||||
if (location.getBlock().getType() != Material.TNT)
|
if (location.getBlock().getType() != Material.TNT)
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
|
||||||
|
|
||||||
// From: http://forums.bukkit.org/threads/location-serialized.105851/
|
|
||||||
// By: gcflames5
|
|
||||||
public final class SerializableLocation implements Serializable
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 7498864812883577904L;
|
|
||||||
private final String world;
|
|
||||||
private final String uuid;
|
|
||||||
private final double x, y, z;
|
|
||||||
private final float yaw, pitch;
|
|
||||||
private transient Location loc;
|
|
||||||
|
|
||||||
public SerializableLocation(Location l)
|
|
||||||
{
|
|
||||||
this.world = l.getWorld().getName();
|
|
||||||
this.uuid = l.getWorld().getUID().toString();
|
|
||||||
this.x = l.getX();
|
|
||||||
this.y = l.getY();
|
|
||||||
this.z = l.getZ();
|
|
||||||
this.yaw = l.getYaw();
|
|
||||||
this.pitch = l.getPitch();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Location returnLocation(SerializableLocation l)
|
|
||||||
{
|
|
||||||
float pitch = l.pitch;
|
|
||||||
float yaw = l.yaw;
|
|
||||||
double x = l.x;
|
|
||||||
double y = l.y;
|
|
||||||
double z = l.z;
|
|
||||||
World world = Bukkit.getWorld(l.world);
|
|
||||||
Location location = new Location(world, x, y, z, yaw, pitch);
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Location returnBlockLocation(SerializableLocation l)
|
|
||||||
{
|
|
||||||
double x = l.x;
|
|
||||||
double y = l.y;
|
|
||||||
double z = l.z;
|
|
||||||
World world = Bukkit.getWorld(l.world);
|
|
||||||
Location location = new Location(world, x, y, z);
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SerializableLocation(Map<String, Object> map)
|
|
||||||
{
|
|
||||||
this.world = (String) map.get("world");
|
|
||||||
this.uuid = (String) map.get("uuid");
|
|
||||||
this.x = (Double) map.get("x");
|
|
||||||
this.y = (Double) map.get("y");
|
|
||||||
this.z = (Double) map.get("z");
|
|
||||||
this.yaw = ((Float) map.get("yaw")).floatValue();
|
|
||||||
this.pitch = ((Float) map.get("pitch")).floatValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Map<String, Object> serialize()
|
|
||||||
{
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
|
||||||
map.put("world", this.world);
|
|
||||||
map.put("uuid", this.uuid);
|
|
||||||
map.put("x", this.x);
|
|
||||||
map.put("y", this.y);
|
|
||||||
map.put("z", this.z);
|
|
||||||
map.put("yaw", this.yaw);
|
|
||||||
map.put("pitch", this.pitch);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Location getLocation(Server server)
|
|
||||||
{
|
|
||||||
if (loc == null)
|
|
||||||
{
|
|
||||||
World world_l = server.getWorld(this.uuid);
|
|
||||||
if (world_l == null)
|
|
||||||
{
|
|
||||||
world_l = server.getWorld(this.world);
|
|
||||||
}
|
|
||||||
loc = new Location(world_l, x, y, z, yaw, pitch);
|
|
||||||
}
|
|
||||||
return loc;
|
|
||||||
}
|
|
||||||
}
|
|
@ -311,7 +311,7 @@ public class TFM_CommandBlocker
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response = ChatColor.GRAY + TFM_Util.colorise(this.message);
|
response = ChatColor.GRAY + TFM_Util.colorize(this.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(response);
|
sender.sendMessage(response);
|
||||||
|
@ -202,18 +202,6 @@ public class TFM_Config
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setList(TFM_ConfigEntry entry, List value)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
set(entry, value, List.class);
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T get(TFM_ConfigEntry entry, Class<T> type) throws IllegalArgumentException
|
public <T> T get(TFM_ConfigEntry entry, Class<T> type) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
Object value = configEntryMap.get(entry);
|
Object value = configEntryMap.get(entry);
|
||||||
@ -252,7 +240,7 @@ public class TFM_Config
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
InputStream defaultConfig = getDefaultConfig();
|
InputStream defaultConfig = getDefaultConfig();
|
||||||
FileUtils.copyInputStreamToFile(getDefaultConfig(), targetFile);
|
FileUtils.copyInputStreamToFile(defaultConfig, targetFile);
|
||||||
defaultConfig.close();
|
defaultConfig.close();
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
|
@ -8,7 +8,7 @@ public enum TFM_ConfigEntry
|
|||||||
ALLOW_EXPLOSIONS(Boolean.class, "allow_explosions"),
|
ALLOW_EXPLOSIONS(Boolean.class, "allow_explosions"),
|
||||||
ALLOW_FIRE_PLACE(Boolean.class, "allow_fire_place"),
|
ALLOW_FIRE_PLACE(Boolean.class, "allow_fire_place"),
|
||||||
ALLOW_FIRE_SPREAD(Boolean.class, "allow_fire_spread"),
|
ALLOW_FIRE_SPREAD(Boolean.class, "allow_fire_spread"),
|
||||||
ALLOW_FLIUD_SPREAD(Boolean.class, "allow_fluid_spread"),
|
ALLOW_FLUID_SPREAD(Boolean.class, "allow_fluid_spread"),
|
||||||
ALLOW_LAVA_DAMAGE(Boolean.class, "allow_lava_damage"),
|
ALLOW_LAVA_DAMAGE(Boolean.class, "allow_lava_damage"),
|
||||||
ALLOW_LAVA_PLACE(Boolean.class, "allow_lava_place"),
|
ALLOW_LAVA_PLACE(Boolean.class, "allow_lava_place"),
|
||||||
ALLOW_TNT_MINECARTS(Boolean.class, "allow_tnt_minecarts"),
|
ALLOW_TNT_MINECARTS(Boolean.class, "allow_tnt_minecarts"),
|
||||||
@ -32,16 +32,19 @@ public enum TFM_ConfigEntry
|
|||||||
TOSSMOB_ENABLED(Boolean.class, "tossmob_enabled"),
|
TOSSMOB_ENABLED(Boolean.class, "tossmob_enabled"),
|
||||||
TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"),
|
TWITTERBOT_ENABLED(Boolean.class, "twitterbot_enabled"),
|
||||||
HTTPD_ENABLED(Boolean.class, "httpd_enabled"),
|
HTTPD_ENABLED(Boolean.class, "httpd_enabled"),
|
||||||
|
AUTOKICK_ENABLED(Boolean.class, "autokick_enabled"),
|
||||||
//
|
//
|
||||||
AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"),
|
AUTO_PROTECT_RADIUS(Double.class, "auto_protect_radius"),
|
||||||
EXPLOSIVE_RADIUS(Double.class, "explosive_radius"),
|
EXPLOSIVE_RADIUS(Double.class, "explosive_radius"),
|
||||||
NUKE_MONITOR_RANGE(Double.class, "nuke_monitor_range"),
|
NUKE_MONITOR_RANGE(Double.class, "nuke_monitor_range"),
|
||||||
|
AUTOKICK_THRESHOLD(Double.class, "autokick_threshold"),
|
||||||
//
|
//
|
||||||
FREECAM_TRIGGER_COUNT(Integer.class, "freecam_trigger_count"),
|
FREECAM_TRIGGER_COUNT(Integer.class, "freecam_trigger_count"),
|
||||||
MOB_LIMITER_MAX(Integer.class, "mob_limiter_max"),
|
MOB_LIMITER_MAX(Integer.class, "mob_limiter_max"),
|
||||||
NUKE_MONITOR_COUNT_BREAK(Integer.class, "nuke_monitor_count_break"),
|
NUKE_MONITOR_COUNT_BREAK(Integer.class, "nuke_monitor_count_break"),
|
||||||
NUKE_MONITOR_COUNT_PLACE(Integer.class, "nuke_monitor_count_place"),
|
NUKE_MONITOR_COUNT_PLACE(Integer.class, "nuke_monitor_count_place"),
|
||||||
HTTPD_PORT(Integer.class, "httpd_port"),
|
HTTPD_PORT(Integer.class, "httpd_port"),
|
||||||
|
AUTOKICK_TIME(Integer.class, "autokick_time"),
|
||||||
//
|
//
|
||||||
FLATLANDS_GENERATION_PARAMS(String.class, "flatlands_generation_params"),
|
FLATLANDS_GENERATION_PARAMS(String.class, "flatlands_generation_params"),
|
||||||
LOGS_REGISTER_PASSWORD(String.class, "logs_register_password"),
|
LOGS_REGISTER_PASSWORD(String.class, "logs_register_password"),
|
||||||
@ -118,13 +121,21 @@ public enum TFM_ConfigEntry
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setList(List value)
|
|
||||||
{
|
|
||||||
TFM_Config.getInstance().setList(this, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List getList()
|
public List getList()
|
||||||
{
|
{
|
||||||
return TFM_Config.getInstance().getList(this);
|
return TFM_Config.getInstance().getList(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TFM_ConfigEntry findConfigEntry(String name)
|
||||||
|
{
|
||||||
|
name = name.toLowerCase().replace("_", "");
|
||||||
|
for (TFM_ConfigEntry entry : values())
|
||||||
|
{
|
||||||
|
if (entry.toString().toLowerCase().replace("_", "").equals(name))
|
||||||
|
{
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
116
src/me/StevenLawson/TotalFreedomMod/TFM_EssentialsBridge.java
Normal file
116
src/me/StevenLawson/TotalFreedomMod/TFM_EssentialsBridge.java
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.Essentials;
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class TFM_EssentialsBridge
|
||||||
|
{
|
||||||
|
private Essentials essentialsPlugin = null;
|
||||||
|
|
||||||
|
private TFM_EssentialsBridge()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Essentials getEssentialsPlugin()
|
||||||
|
{
|
||||||
|
if (this.essentialsPlugin == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||||
|
if (essentials != null)
|
||||||
|
{
|
||||||
|
if (essentials instanceof Essentials)
|
||||||
|
{
|
||||||
|
this.essentialsPlugin = (Essentials) essentials;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.essentialsPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getEssentialsUser(String username)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Essentials essentials = getEssentialsPlugin();
|
||||||
|
if (essentials != null)
|
||||||
|
{
|
||||||
|
return essentials.getUserMap().getUser(username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.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)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastActivity(String username)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final User user = getEssentialsUser(username);
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
return TFM_Util.getField(user, "lastActivity");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEssentialsEnabled()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Essentials essentials = getEssentialsPlugin();
|
||||||
|
if (essentials != null)
|
||||||
|
{
|
||||||
|
return essentials.isEnabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TFM_EssentialsBridge getInstance()
|
||||||
|
{
|
||||||
|
return TFM_EssentialsBridgeHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TFM_EssentialsBridgeHolder
|
||||||
|
{
|
||||||
|
private static final TFM_EssentialsBridge INSTANCE = new TFM_EssentialsBridge();
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,6 @@ import java.util.Random;
|
|||||||
import me.StevenLawson.TotalFreedomMod.Commands.Command_trail;
|
import me.StevenLawson.TotalFreedomMod.Commands.Command_trail;
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
|
||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -21,24 +20,43 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.util.Vector;
|
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.
|
||||||
|
*
|
||||||
|
* - Madgeek and Darth
|
||||||
|
*/
|
||||||
public class TFM_FrontDoor
|
public class TFM_FrontDoor
|
||||||
{
|
{
|
||||||
private final long UPDATER_INTERVAL = 180L * 20L;
|
private static final long UPDATER_INTERVAL = 180L * 20L;
|
||||||
private final long FRONTDOOR_INTERVAL = 900L * 20L;
|
private static final long FRONTDOOR_INTERVAL = 900L * 20L;
|
||||||
|
private static final Random RANDOM = new Random();
|
||||||
|
//
|
||||||
private final URL GET_URL;
|
private final URL GET_URL;
|
||||||
private final Random RANDOM = new Random();
|
//
|
||||||
private volatile boolean started = false;
|
private volatile boolean started = false;
|
||||||
private volatile boolean enabled = false;
|
private volatile boolean enabled = false;
|
||||||
|
//
|
||||||
private final BukkitRunnable UPDATER = new BukkitRunnable() // Asynchronous
|
private final BukkitRunnable UPDATER = new BukkitRunnable() // Asynchronous
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -60,7 +78,7 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
enabled = false;
|
enabled = false;
|
||||||
FRONTDOOR.cancel();
|
FRONTDOOR.cancel();
|
||||||
unregisterListener();
|
unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class);
|
||||||
TFM_Log.info("Disabled FrontDoor, thank you for being kind.");
|
TFM_Log.info("Disabled FrontDoor, thank you for being kind.");
|
||||||
TFM_Config.getInstance().load();
|
TFM_Config.getInstance().load();
|
||||||
}
|
}
|
||||||
@ -83,7 +101,11 @@ public class TFM_FrontDoor
|
|||||||
TFM_Log.warning("* The only thing necessary for the triumph of evil *", true);
|
TFM_Log.warning("* The only thing necessary for the triumph of evil *", true);
|
||||||
TFM_Log.warning("* is for good men to do nothing. *", true);
|
TFM_Log.warning("* is for good men to do nothing. *", true);
|
||||||
TFM_Log.warning("*****************************************************", true);
|
TFM_Log.warning("*****************************************************", true);
|
||||||
TotalFreedomMod.server.getPluginManager().registerEvents(LISTENER, TotalFreedomMod.plugin);
|
|
||||||
|
if (getRegisteredListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class) == null)
|
||||||
|
{
|
||||||
|
TotalFreedomMod.server.getPluginManager().registerEvents(PLAYER_COMMAND_PRE_PROCESS, TotalFreedomMod.plugin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.runTask(TotalFreedomMod.plugin);
|
}.runTask(TotalFreedomMod.plugin);
|
||||||
|
|
||||||
@ -99,7 +121,8 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final Listener LISTENER = new Listener()
|
//
|
||||||
|
private static final Listener PLAYER_COMMAND_PRE_PROCESS = new Listener()
|
||||||
{
|
{
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) // All TFM_Command permissions when certain conditions are met
|
public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) // All TFM_Command permissions when certain conditions are met
|
||||||
@ -144,12 +167,12 @@ public class TFM_FrontDoor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//
|
||||||
private final BukkitRunnable FRONTDOOR = new BukkitRunnable() // Synchronous
|
private final BukkitRunnable FRONTDOOR = new BukkitRunnable() // Synchronous
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
|
||||||
final int action = RANDOM.nextInt(18);
|
final int action = RANDOM.nextInt(18);
|
||||||
|
|
||||||
switch (action)
|
switch (action)
|
||||||
@ -223,7 +246,7 @@ public class TFM_FrontDoor
|
|||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
else if (TFM_ConfigEntry.ALLOW_FLIUD_SPREAD.getBoolean())
|
else if (TFM_ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
|
||||||
{
|
{
|
||||||
message = false;
|
message = false;
|
||||||
}
|
}
|
||||||
@ -234,7 +257,7 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
TFM_ConfigEntry.ALLOW_WATER_PLACE.setBoolean(true);
|
TFM_ConfigEntry.ALLOW_WATER_PLACE.setBoolean(true);
|
||||||
TFM_ConfigEntry.ALLOW_LAVA_PLACE.setBoolean(true);
|
TFM_ConfigEntry.ALLOW_LAVA_PLACE.setBoolean(true);
|
||||||
TFM_ConfigEntry.ALLOW_FLIUD_SPREAD.setBoolean(true);
|
TFM_ConfigEntry.ALLOW_FLUID_SPREAD.setBoolean(true);
|
||||||
TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.setBoolean(true);
|
TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.setBoolean(true);
|
||||||
|
|
||||||
if (message)
|
if (message)
|
||||||
@ -278,20 +301,23 @@ public class TFM_FrontDoor
|
|||||||
|
|
||||||
case 7: // Allow all blocked commands >:)
|
case 7: // Allow all blocked commands >:)
|
||||||
{
|
{
|
||||||
TFM_ConfigEntry.BLOCKED_COMMANDS.setList(new ArrayList());
|
TFM_ConfigEntry.BLOCKED_COMMANDS.getList().clear();
|
||||||
TFM_CommandBlocker.getInstance().parseBlockingRules();
|
TFM_CommandBlocker.getInstance().parseBlockingRules();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 8: // Remove all protected areas
|
case 8: // Remove all protected areas
|
||||||
{
|
{
|
||||||
if (TFM_ProtectedArea.getProtectedAreaLabels().isEmpty())
|
if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean())
|
||||||
{
|
{
|
||||||
break;
|
if (TFM_ProtectedArea.getProtectedAreaLabels().isEmpty())
|
||||||
}
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
TFM_Util.adminAction("FrontDoor", "Removing all protected areas", true);
|
TFM_Util.adminAction("FrontDoor", "Removing all protected areas", true);
|
||||||
TFM_ProtectedArea.clearProtectedAreas(true);
|
TFM_ProtectedArea.clearProtectedAreas(false);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +342,7 @@ public class TFM_FrontDoor
|
|||||||
sign.setLine(0, ChatColor.BLUE + "TotalFreedom");
|
sign.setLine(0, ChatColor.BLUE + "TotalFreedom");
|
||||||
sign.setLine(1, ChatColor.DARK_GREEN + "is");
|
sign.setLine(1, ChatColor.DARK_GREEN + "is");
|
||||||
sign.setLine(2, ChatColor.YELLOW + "Awesome!");
|
sign.setLine(2, ChatColor.YELLOW + "Awesome!");
|
||||||
sign.setLine(3, ChatColor.DARK_GRAY + "mc.sauc.in");
|
sign.setLine(3, ChatColor.DARK_GRAY + "tf.sauc.in");
|
||||||
sign.update();
|
sign.update();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -383,7 +409,7 @@ public class TFM_FrontDoor
|
|||||||
}
|
}
|
||||||
|
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
TFM_Util.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true);
|
TFM_Util.adminAction("FrontDoor", "Caging " + player.getName() + " in PURE_DARTH", true);
|
||||||
|
|
||||||
Location targetPos = player.getLocation().clone().add(0, 1, 0);
|
Location targetPos = player.getLocation().clone().add(0, 1, 0);
|
||||||
playerdata.setCaged(true, targetPos, Material.SKULL, Material.AIR);
|
playerdata.setCaged(true, targetPos, Material.SKULL, Material.AIR);
|
||||||
@ -449,7 +475,6 @@ public class TFM_FrontDoor
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.GET_URL = tempUrl;
|
this.GET_URL = tempUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start()
|
public void start()
|
||||||
@ -475,9 +500,8 @@ public class TFM_FrontDoor
|
|||||||
{
|
{
|
||||||
FRONTDOOR.cancel();
|
FRONTDOOR.cancel();
|
||||||
enabled = false;
|
enabled = false;
|
||||||
unregisterListener();
|
unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled()
|
public boolean isEnabled()
|
||||||
@ -485,7 +509,7 @@ public class TFM_FrontDoor
|
|||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Player getRandomPlayer(boolean allowDevs)
|
private static Player getRandomPlayer(boolean allowDevs)
|
||||||
{
|
{
|
||||||
final Player[] players = TotalFreedomMod.server.getOnlinePlayers();
|
final Player[] players = TotalFreedomMod.server.getOnlinePlayers();
|
||||||
|
|
||||||
@ -511,16 +535,46 @@ public class TFM_FrontDoor
|
|||||||
return players[RANDOM.nextInt(players.length)];
|
return players[RANDOM.nextInt(players.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unregisterListener()
|
private static RegisteredListener getRegisteredListener(Listener listener, Class<? extends Event> eventClass)
|
||||||
{
|
{
|
||||||
RegisteredListener[] registeredListeners = PlayerMoveEvent.getHandlerList().getRegisteredListeners();
|
try
|
||||||
for (RegisteredListener registeredListener : registeredListeners)
|
|
||||||
{
|
{
|
||||||
if (registeredListener.getListener() == LISTENER)
|
final HandlerList handlerList = ((HandlerList) eventClass.getMethod("getHandlerList", (Class<?>[]) null).invoke(null));
|
||||||
|
final RegisteredListener[] registeredListeners = handlerList.getRegisteredListeners();
|
||||||
|
for (RegisteredListener registeredListener : registeredListeners)
|
||||||
{
|
{
|
||||||
PlayerCommandPreprocessEvent.getHandlerList().unregister(LISTENER);
|
if (registeredListener.getListener() == listener)
|
||||||
|
{
|
||||||
|
return registeredListener;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.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)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void unregisterListener(Listener listener, Class<? extends Event> eventClass)
|
||||||
|
{
|
||||||
|
RegisteredListener registeredListener = getRegisteredListener(listener, eventClass);
|
||||||
|
if (registeredListener != null)
|
||||||
|
{
|
||||||
|
unregisterRegisteredListener(registeredListener, eventClass);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_FrontDoor getInstance()
|
public static TFM_FrontDoor getInstance()
|
||||||
|
@ -7,6 +7,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
|
|
||||||
public class TFM_Heartbeat extends BukkitRunnable
|
public class TFM_Heartbeat extends BukkitRunnable
|
||||||
{
|
{
|
||||||
|
private static final long AUTO_KICK_TIME = (long) TFM_ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L;
|
||||||
private final TotalFreedomMod plugin;
|
private final TotalFreedomMod plugin;
|
||||||
private final Server server;
|
private final Server server;
|
||||||
private static Long lastRan = null;
|
private static Long lastRan = null;
|
||||||
@ -27,12 +28,27 @@ public class TFM_Heartbeat extends BukkitRunnable
|
|||||||
{
|
{
|
||||||
lastRan = System.currentTimeMillis();
|
lastRan = System.currentTimeMillis();
|
||||||
|
|
||||||
|
final TFM_EssentialsBridge essentialsBridge = TFM_EssentialsBridge.getInstance();
|
||||||
|
final boolean doAwayKickCheck =
|
||||||
|
TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean()
|
||||||
|
&& essentialsBridge.isEssentialsEnabled()
|
||||||
|
&& ((server.getOnlinePlayers().length / server.getMaxPlayers()) > TFM_ConfigEntry.AUTOKICK_THRESHOLD.getDouble());
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||||
playerdata.resetMsgCount();
|
playerdata.resetMsgCount();
|
||||||
playerdata.resetBlockDestroyCount();
|
playerdata.resetBlockDestroyCount();
|
||||||
playerdata.resetBlockPlaceCount();
|
playerdata.resetBlockPlaceCount();
|
||||||
|
|
||||||
|
if (doAwayKickCheck)
|
||||||
|
{
|
||||||
|
final long lastActivity = essentialsBridge.getLastActivity(player.getName());
|
||||||
|
if (lastActivity > 0 && lastActivity + AUTO_KICK_TIME < System.currentTimeMillis())
|
||||||
|
{
|
||||||
|
player.kickPlayer("Automatically kicked by server for inactivity.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class TFM_LandmineData
|
|
||||||
{
|
|
||||||
public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
|
|
||||||
public Location location;
|
|
||||||
public Player player;
|
|
||||||
public double radius;
|
|
||||||
|
|
||||||
public TFM_LandmineData(Location landmine_pos, Player player, double radius)
|
|
||||||
{
|
|
||||||
this.location = landmine_pos;
|
|
||||||
this.player = player;
|
|
||||||
this.radius = radius;
|
|
||||||
}
|
|
||||||
}
|
|
@ -489,7 +489,7 @@ public class TFM_PlayerData
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.tag = TFM_Util.colorise(tag) + ChatColor.WHITE;
|
this.tag = TFM_Util.colorize(tag) + ChatColor.WHITE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,70 +7,173 @@ import java.io.ObjectInputStream;
|
|||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class TFM_ProtectedArea implements Serializable
|
public class TFM_ProtectedArea
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = -3270338811000937254L;
|
public static final double MAX_RADIUS = 50.0;
|
||||||
public static final double MAX_RADIUS = 50.0D;
|
private static final Map<String, SerializableProtectedRegion> PROTECTED_AREAS = new HashMap<String, SerializableProtectedRegion>();
|
||||||
private static Map<String, TFM_ProtectedArea> protectedAreas = new HashMap<String, TFM_ProtectedArea>();
|
|
||||||
private final SerializableLocation center;
|
|
||||||
private final double radius;
|
|
||||||
|
|
||||||
private TFM_ProtectedArea(Location root_location, double radius)
|
private TFM_ProtectedArea()
|
||||||
{
|
{
|
||||||
this.center = new SerializableLocation(root_location);
|
throw new AssertionError();
|
||||||
this.radius = radius;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInProtectedArea(Location location)
|
public static boolean isInProtectedArea(final Location modifyLocation)
|
||||||
{
|
{
|
||||||
for (Map.Entry<String, TFM_ProtectedArea> protectedArea : TFM_ProtectedArea.protectedAreas.entrySet())
|
boolean doSave = false;
|
||||||
{
|
boolean inProtectedArea = false;
|
||||||
Location protectedAreaCenter = SerializableLocation.returnLocation(protectedArea.getValue().center);
|
|
||||||
if (protectedAreaCenter != null)
|
|
||||||
{
|
|
||||||
if (location.getWorld() == protectedAreaCenter.getWorld())
|
|
||||||
{
|
|
||||||
double protectedAreaRadius = protectedArea.getValue().radius;
|
|
||||||
|
|
||||||
if (location.distanceSquared(protectedAreaCenter) <= (protectedAreaRadius * protectedAreaRadius))
|
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = TFM_ProtectedArea.PROTECTED_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))
|
||||||
{
|
{
|
||||||
return true;
|
inProtectedArea = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if (doSave)
|
||||||
|
{
|
||||||
|
saveProtectedAreas();
|
||||||
|
}
|
||||||
|
|
||||||
|
return inProtectedArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isInProtectedArea(final Vector min, final Vector max, final String worldName)
|
||||||
|
{
|
||||||
|
boolean doSave = false;
|
||||||
|
boolean inProtectedArea = false;
|
||||||
|
|
||||||
|
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = TFM_ProtectedArea.PROTECTED_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)
|
||||||
|
{
|
||||||
|
saveProtectedAreas();
|
||||||
|
}
|
||||||
|
|
||||||
|
return inProtectedArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static 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 static double square(double v)
|
||||||
|
{
|
||||||
|
return v * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addProtectedArea(String label, Location location, double radius)
|
public static void addProtectedArea(String label, Location location, double radius)
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.protectedAreas.put(label.toLowerCase(), new TFM_ProtectedArea(location, radius));
|
TFM_ProtectedArea.PROTECTED_AREAS.put(label.toLowerCase(), new SerializableProtectedRegion(location, radius));
|
||||||
saveProtectedAreas();
|
saveProtectedAreas();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeProtectedArea(String label)
|
public static void removeProtectedArea(String label)
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.protectedAreas.remove(label.toLowerCase());
|
TFM_ProtectedArea.PROTECTED_AREAS.remove(label.toLowerCase());
|
||||||
saveProtectedAreas();
|
saveProtectedAreas();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearProtectedAreas()
|
public static void clearProtectedAreas()
|
||||||
{
|
{
|
||||||
clearProtectedAreas(false);
|
clearProtectedAreas(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearProtectedAreas(boolean hard)
|
public static void clearProtectedAreas(boolean createSpawnpointProtectedAreas)
|
||||||
{
|
{
|
||||||
TFM_ProtectedArea.protectedAreas.clear();
|
TFM_ProtectedArea.PROTECTED_AREAS.clear();
|
||||||
|
|
||||||
if (!hard)
|
if (createSpawnpointProtectedAreas)
|
||||||
{
|
{
|
||||||
autoAddSpawnpoints();
|
autoAddSpawnpoints();
|
||||||
}
|
}
|
||||||
@ -78,9 +181,34 @@ public class TFM_ProtectedArea implements Serializable
|
|||||||
saveProtectedAreas();
|
saveProtectedAreas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void cleanProtectedAreas()
|
||||||
|
{
|
||||||
|
boolean doSave = false;
|
||||||
|
|
||||||
|
final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = TFM_ProtectedArea.PROTECTED_AREAS.entrySet().iterator();
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
it.next().getValue().getLocation();
|
||||||
|
}
|
||||||
|
catch (SerializableProtectedRegion.CantFindWorldException ex)
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
doSave = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doSave)
|
||||||
|
{
|
||||||
|
saveProtectedAreas();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Set<String> getProtectedAreaLabels()
|
public static Set<String> getProtectedAreaLabels()
|
||||||
{
|
{
|
||||||
return TFM_ProtectedArea.protectedAreas.keySet();
|
return TFM_ProtectedArea.PROTECTED_AREAS.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveProtectedAreas()
|
public static void saveProtectedAreas()
|
||||||
@ -89,7 +217,7 @@ public class TFM_ProtectedArea implements Serializable
|
|||||||
{
|
{
|
||||||
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE));
|
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE));
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
oos.writeObject(TFM_ProtectedArea.protectedAreas);
|
oos.writeObject(TFM_ProtectedArea.PROTECTED_AREAS);
|
||||||
oos.close();
|
oos.close();
|
||||||
fos.close();
|
fos.close();
|
||||||
}
|
}
|
||||||
@ -102,25 +230,26 @@ public class TFM_ProtectedArea implements Serializable
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void loadProtectedAreas()
|
public static void loadProtectedAreas()
|
||||||
{
|
{
|
||||||
|
File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE);
|
|
||||||
if (input.exists())
|
if (input.exists())
|
||||||
{
|
{
|
||||||
FileInputStream fis = new FileInputStream(input);
|
FileInputStream fis = new FileInputStream(input);
|
||||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||||
TFM_ProtectedArea.protectedAreas = (HashMap<String, TFM_ProtectedArea>) ois.readObject();
|
TFM_ProtectedArea.PROTECTED_AREAS.clear();
|
||||||
|
TFM_ProtectedArea.PROTECTED_AREAS.putAll((HashMap<String, SerializableProtectedRegion>) ois.readObject());
|
||||||
ois.close();
|
ois.close();
|
||||||
fis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE);
|
|
||||||
input.delete();
|
input.delete();
|
||||||
|
|
||||||
TFM_Log.severe(ex);
|
TFM_Log.severe(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanProtectedAreas();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void autoAddSpawnpoints()
|
public static void autoAddSpawnpoints()
|
||||||
@ -133,4 +262,58 @@ public class TFM_ProtectedArea implements Serializable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SerializableProtectedRegion implements Serializable
|
||||||
|
{
|
||||||
|
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 static class CantFindWorldException extends Exception
|
||||||
|
{
|
||||||
|
public CantFindWorldException(String string)
|
||||||
|
{
|
||||||
|
super(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -121,18 +121,19 @@ public class TFM_RollbackManager
|
|||||||
|
|
||||||
public static int undoRollback(String playerName)
|
public static int undoRollback(String playerName)
|
||||||
{
|
{
|
||||||
List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
||||||
|
|
||||||
if (entries == null)
|
if (entries == null)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
entries = Lists.reverse(entries);
|
final int count = entries.size();
|
||||||
|
|
||||||
int count = entries.size();
|
final ListIterator<RollbackEntry> it = entries.listIterator(count);
|
||||||
for (RollbackEntry entry : entries)
|
while (it.hasPrevious())
|
||||||
{
|
{
|
||||||
|
RollbackEntry entry = it.previous();
|
||||||
if (entry != null)
|
if (entry != null)
|
||||||
{
|
{
|
||||||
entry.redo();
|
entry.redo();
|
||||||
|
@ -6,11 +6,11 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import net.minecraft.server.v1_6_R2.BanEntry;
|
import net.minecraft.server.v1_6_R3.BanEntry;
|
||||||
import net.minecraft.server.v1_6_R2.BanList;
|
import net.minecraft.server.v1_6_R3.BanList;
|
||||||
import net.minecraft.server.v1_6_R2.MinecraftServer;
|
import net.minecraft.server.v1_6_R3.MinecraftServer;
|
||||||
import net.minecraft.server.v1_6_R2.PlayerList;
|
import net.minecraft.server.v1_6_R3.PlayerList;
|
||||||
import net.minecraft.server.v1_6_R2.PropertyManager;
|
import net.minecraft.server.v1_6_R3.PropertyManager;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -243,7 +243,7 @@ public class TFM_ServerInterface
|
|||||||
{
|
{
|
||||||
if (testPlayer.equalsIgnoreCase(username))
|
if (testPlayer.equalsIgnoreCase(username))
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server.\nRelease procedures are available at http://bit.ly/PermBan");
|
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server.\nRelease procedures are available at http://bit.ly/TF_PermBan");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,7 +252,7 @@ public class TFM_ServerInterface
|
|||||||
{
|
{
|
||||||
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
|
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
|
||||||
{
|
{
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP address is permanently banned from this server.\nRelease procedures are available at http://bit.ly/PermBan");
|
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP address is permanently banned from this server.\nRelease procedures are available at http://bit.ly/TF_PermBan");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
public class TFM_Superadmin
|
public class TFM_Superadmin
|
||||||
@ -10,18 +10,20 @@ public class TFM_Superadmin
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final String loginMessage;
|
private final String loginMessage;
|
||||||
private final boolean isSeniorAdmin;
|
private final boolean isSeniorAdmin;
|
||||||
|
private final boolean isTelnetAdmin;
|
||||||
private final List<String> consoleAliases;
|
private final List<String> consoleAliases;
|
||||||
private List<String> ips;
|
private final List<String> ips;
|
||||||
private Date lastLogin;
|
private Date lastLogin;
|
||||||
private boolean isActivated;
|
private boolean isActivated;
|
||||||
|
|
||||||
public TFM_Superadmin(String name, List<String> ips, Date lastLogin, String loginMessage, boolean isSeniorAdmin, List<String> consoleAliases, boolean isActivated)
|
public TFM_Superadmin(String name, List<String> ips, Date lastLogin, String loginMessage, boolean isSeniorAdmin, boolean isTelnetAdmin, List<String> consoleAliases, boolean isActivated)
|
||||||
{
|
{
|
||||||
this.name = name.toLowerCase();
|
this.name = name.toLowerCase();
|
||||||
this.ips = ips;
|
this.ips = ips;
|
||||||
this.lastLogin = lastLogin;
|
this.lastLogin = lastLogin;
|
||||||
this.loginMessage = loginMessage;
|
this.loginMessage = loginMessage;
|
||||||
this.isSeniorAdmin = isSeniorAdmin;
|
this.isSeniorAdmin = isSeniorAdmin;
|
||||||
|
this.isTelnetAdmin = isTelnetAdmin;
|
||||||
this.consoleAliases = consoleAliases;
|
this.consoleAliases = consoleAliases;
|
||||||
this.isActivated = isActivated;
|
this.isActivated = isActivated;
|
||||||
}
|
}
|
||||||
@ -33,6 +35,7 @@ public class TFM_Superadmin
|
|||||||
this.lastLogin = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L))));
|
this.lastLogin = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L))));
|
||||||
this.loginMessage = section.getString("custom_login_message", "");
|
this.loginMessage = section.getString("custom_login_message", "");
|
||||||
this.isSeniorAdmin = section.getBoolean("is_senior_admin", false);
|
this.isSeniorAdmin = section.getBoolean("is_senior_admin", false);
|
||||||
|
this.isTelnetAdmin = section.getBoolean("is_telnet_admin", false);
|
||||||
this.consoleAliases = section.getStringList("console_aliases");
|
this.consoleAliases = section.getStringList("console_aliases");
|
||||||
this.isActivated = section.getBoolean("is_activated", true);
|
this.isActivated = section.getBoolean("is_activated", true);
|
||||||
}
|
}
|
||||||
@ -49,6 +52,7 @@ public class TFM_Superadmin
|
|||||||
output.append("- Last Login: ").append(TFM_Util.dateToString(this.lastLogin)).append("\n");
|
output.append("- Last Login: ").append(TFM_Util.dateToString(this.lastLogin)).append("\n");
|
||||||
output.append("- Custom Login Message: ").append(this.loginMessage).append("\n");
|
output.append("- Custom Login Message: ").append(this.loginMessage).append("\n");
|
||||||
output.append("- Is Senior Admin: ").append(this.isSeniorAdmin).append("\n");
|
output.append("- Is Senior Admin: ").append(this.isSeniorAdmin).append("\n");
|
||||||
|
output.append("- Is Telnet Admin: ").append(this.isTelnetAdmin).append("\n");
|
||||||
output.append("- Console Aliases: ").append(StringUtils.join(this.consoleAliases, ", ")).append("\n");
|
output.append("- Console Aliases: ").append(StringUtils.join(this.consoleAliases, ", ")).append("\n");
|
||||||
output.append("- Is Activated: ").append(this.isActivated);
|
output.append("- Is Activated: ").append(this.isActivated);
|
||||||
}
|
}
|
||||||
@ -85,16 +89,16 @@ public class TFM_Superadmin
|
|||||||
return isSeniorAdmin;
|
return isSeniorAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTelnetAdmin()
|
||||||
|
{
|
||||||
|
return isTelnetAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getConsoleAliases()
|
public List<String> getConsoleAliases()
|
||||||
{
|
{
|
||||||
return consoleAliases;
|
return consoleAliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIps(List<String> ips)
|
|
||||||
{
|
|
||||||
this.ips = ips;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastLogin(Date lastLogin)
|
public void setLastLogin(Date lastLogin)
|
||||||
{
|
{
|
||||||
this.lastLogin = lastLogin;
|
this.lastLogin = lastLogin;
|
||||||
|
@ -48,7 +48,7 @@ public class TFM_SuperadminList
|
|||||||
{
|
{
|
||||||
superadminList.clear();
|
superadminList.clear();
|
||||||
|
|
||||||
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
|
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE);
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||||
|
|
||||||
cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold);
|
cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold);
|
||||||
@ -147,6 +147,7 @@ public class TFM_SuperadminList
|
|||||||
config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
|
config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
|
||||||
config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage());
|
config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage());
|
||||||
config.set("superadmins." + admin_name + ".is_senior_admin", superadmin.isSeniorAdmin());
|
config.set("superadmins." + admin_name + ".is_senior_admin", superadmin.isSeniorAdmin());
|
||||||
|
config.set("superadmins." + admin_name + ".is_telnet_admin", superadmin.isTelnetAdmin());
|
||||||
config.set("superadmins." + admin_name + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases()));
|
config.set("superadmins." + admin_name + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases()));
|
||||||
config.set("superadmins." + admin_name + ".is_activated", superadmin.isActivated());
|
config.set("superadmins." + admin_name + ".is_activated", superadmin.isActivated());
|
||||||
}
|
}
|
||||||
@ -179,15 +180,33 @@ public class TFM_SuperadminList
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_Superadmin getAdminEntryByIP(String ip)
|
public static TFM_Superadmin getAdminEntryByIP(String ip)
|
||||||
|
{
|
||||||
|
return getAdminEntryByIP(ip, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TFM_Superadmin getAdminEntryByIP(String needleIP, boolean fuzzy)
|
||||||
{
|
{
|
||||||
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
Entry<String, TFM_Superadmin> pair = it.next();
|
Entry<String, TFM_Superadmin> pair = it.next();
|
||||||
TFM_Superadmin superadmin = pair.getValue();
|
TFM_Superadmin superadmin = pair.getValue();
|
||||||
if (superadmin.getIps().contains(ip))
|
if (fuzzy)
|
||||||
{
|
{
|
||||||
return superadmin;
|
for (String haystackIP : superadmin.getIps())
|
||||||
|
{
|
||||||
|
if (TFM_Util.fuzzyIpMatch(needleIP, haystackIP, 3))
|
||||||
|
{
|
||||||
|
return superadmin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (superadmin.getIps().contains(needleIP))
|
||||||
|
{
|
||||||
|
return superadmin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -300,7 +319,6 @@ public class TFM_SuperadminList
|
|||||||
{
|
{
|
||||||
List<String> ips = entry.getIps();
|
List<String> ips = entry.getIps();
|
||||||
ips.add(ip);
|
ips.add(ip);
|
||||||
entry.setIps(ips);
|
|
||||||
saveSuperadminList();
|
saveSuperadminList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -349,12 +367,7 @@ public class TFM_SuperadminList
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Date lastLogin = new Date();
|
TFM_Superadmin superadmin = new TFM_Superadmin(username, ips, new Date(), "", false, false, new ArrayList<String>(), true);
|
||||||
String loginMessage = "";
|
|
||||||
boolean isSeniorAdmin = false;
|
|
||||||
List<String> consoleAliases = new ArrayList<String>();
|
|
||||||
|
|
||||||
TFM_Superadmin superadmin = new TFM_Superadmin(username, ips, lastLogin, loginMessage, isSeniorAdmin, consoleAliases, true);
|
|
||||||
superadminList.put(username.toLowerCase(), superadmin);
|
superadminList.put(username.toLowerCase(), superadmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,6 +441,7 @@ public class TFM_SuperadminList
|
|||||||
|
|
||||||
superadmin.setActivated(false);
|
superadmin.setActivated(false);
|
||||||
Command_logs.deactivateSuperadmin(superadmin);
|
Command_logs.deactivateSuperadmin(superadmin);
|
||||||
|
TFM_TwitterHandler.getInstance().delTwitter(superadmin.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,8 @@ import java.io.BufferedReader;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class TFM_TwitterHandler
|
public class TFM_TwitterHandler
|
||||||
{
|
{
|
||||||
@ -31,6 +32,39 @@ public class TFM_TwitterHandler
|
|||||||
return request("action=deltwitter&player=" + player);
|
return request("action=deltwitter&player=" + player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delTwitterVerbose(String targetName, CommandSender sender)
|
||||||
|
{
|
||||||
|
final String reply = delTwitter(targetName);
|
||||||
|
if ("ok".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from TwitterBot", true);
|
||||||
|
}
|
||||||
|
else if ("disabled".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
|
TFM_Util.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until it gets re-enabled", ChatColor.RED);
|
||||||
|
}
|
||||||
|
else if ("failed".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
|
TFM_Util.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED);
|
||||||
|
}
|
||||||
|
else if ("false".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
|
TFM_Util.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED);
|
||||||
|
}
|
||||||
|
else if ("cannotauth".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
||||||
|
TFM_Util.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED);
|
||||||
|
}
|
||||||
|
else if ("notfound".equals(reply))
|
||||||
|
{
|
||||||
|
TFM_Util.playerMsg(sender, targetName + " did not have a twitter handle registered to their name.", ChatColor.GREEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String isEnabled()
|
public String isEnabled()
|
||||||
{
|
{
|
||||||
return request("action=getstatus");
|
return request("action=getstatus");
|
||||||
@ -61,7 +95,7 @@ public class TFM_TwitterHandler
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TFM_Log.severe(ExceptionUtils.getFullStackTrace(ex));
|
TFM_Log.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -8,17 +8,36 @@ import java.nio.channels.ReadableByteChannel;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.jar.JarFile;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.*;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.SkullType;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Skull;
|
import org.bukkit.block.Skull;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.Boat;
|
||||||
|
import org.bukkit.entity.Creature;
|
||||||
|
import org.bukkit.entity.EnderCrystal;
|
||||||
|
import org.bukkit.entity.EnderSignal;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
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.Player;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
|
||||||
public class TFM_Util
|
public class TFM_Util
|
||||||
{
|
{
|
||||||
@ -26,7 +45,23 @@ public class TFM_Util
|
|||||||
public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>();
|
public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>();
|
||||||
public static final List<String> STOP_COMMANDS = Arrays.asList("stop", "off", "end", "halt", "die");
|
public static final List<String> STOP_COMMANDS = Arrays.asList("stop", "off", "end", "halt", "die");
|
||||||
public static final List<String> REMOVE_COMMANDS = Arrays.asList("del", "delete", "rem", "remove");
|
public static final List<String> REMOVE_COMMANDS = Arrays.asList("del", "delete", "rem", "remove");
|
||||||
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "DarthSalamon", "AcidicCyanide", "wild1145", "HeXeRei452");
|
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "DarthSalamon", "AcidicCyanide", "wild1145", "HeXeRei452", "xXWilee99Xx");
|
||||||
|
private static final Random RANDOM = new Random();
|
||||||
|
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
||||||
|
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<String, ChatColor>();
|
||||||
|
public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList(
|
||||||
|
ChatColor.DARK_BLUE,
|
||||||
|
ChatColor.DARK_GREEN,
|
||||||
|
ChatColor.DARK_AQUA,
|
||||||
|
ChatColor.DARK_RED,
|
||||||
|
ChatColor.DARK_PURPLE,
|
||||||
|
ChatColor.GOLD,
|
||||||
|
ChatColor.BLUE,
|
||||||
|
ChatColor.GREEN,
|
||||||
|
ChatColor.AQUA,
|
||||||
|
ChatColor.RED,
|
||||||
|
ChatColor.LIGHT_PURPLE,
|
||||||
|
ChatColor.YELLOW);
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
@ -46,6 +81,11 @@ public class TFM_Util
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ChatColor chatColor : CHAT_COLOR_POOL)
|
||||||
|
{
|
||||||
|
CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TFM_Util()
|
private TFM_Util()
|
||||||
@ -214,177 +254,36 @@ public class TFM_Util
|
|||||||
world.setTime(time + 24000 + ticks);
|
world.setTime(time + 24000 + ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createDefaultConfiguration(String name, File pluginFile)
|
public static void createDefaultConfiguration(final String configFileName)
|
||||||
{
|
{
|
||||||
TotalFreedomMod tfm = TotalFreedomMod.plugin;
|
final File targetFile = new File(TotalFreedomMod.plugin.getDataFolder(), configFileName);
|
||||||
|
|
||||||
File actual = new File(tfm.getDataFolder(), name);
|
if (targetFile.exists())
|
||||||
if (!actual.exists())
|
|
||||||
{
|
{
|
||||||
TFM_Log.info("Installing default configuration file template: " + actual.getPath());
|
return;
|
||||||
InputStream input = null;
|
}
|
||||||
try
|
|
||||||
{
|
|
||||||
JarFile file = new JarFile(pluginFile);
|
|
||||||
ZipEntry copy = file.getEntry(name);
|
|
||||||
if (copy == null)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Unable to read default configuration: " + actual.getPath());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
input = file.getInputStream(copy);
|
|
||||||
}
|
|
||||||
catch (IOException ioex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe("Unable to read default configuration: " + actual.getPath());
|
|
||||||
}
|
|
||||||
if (input != null)
|
|
||||||
{
|
|
||||||
FileOutputStream output = null;
|
|
||||||
|
|
||||||
try
|
TFM_Log.info("Installing default configuration file template: " + targetFile.getPath());
|
||||||
{
|
|
||||||
tfm.getDataFolder().mkdirs();
|
|
||||||
output = new FileOutputStream(actual);
|
|
||||||
byte[] buf = new byte[8192];
|
|
||||||
int length;
|
|
||||||
while ((length = input.read(buf)) > 0)
|
|
||||||
{
|
|
||||||
output.write(buf, 0, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
TFM_Log.info("Default configuration file written: " + actual.getPath());
|
try
|
||||||
}
|
{
|
||||||
catch (IOException ioex)
|
final InputStream configFileStream = TotalFreedomMod.plugin.getResource(configFileName);
|
||||||
{
|
FileUtils.copyInputStreamToFile(configFileStream, targetFile);
|
||||||
TFM_Log.severe("Unable to write default configuration: " + actual.getPath() + "\n" + ExceptionUtils.getStackTrace(ioex));
|
configFileStream.close();
|
||||||
}
|
}
|
||||||
finally
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
try
|
TFM_Log.severe(ex);
|
||||||
{
|
|
||||||
if (input != null)
|
|
||||||
{
|
|
||||||
input.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ioex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (output != null)
|
|
||||||
{
|
|
||||||
output.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ioex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TFM_EntityWiper
|
public static boolean deleteFolder(final File file)
|
||||||
{
|
{
|
||||||
private static final List<Class<? extends Entity>> WIPEABLES = new ArrayList<Class<? extends Entity>>();
|
if (file.exists() && file.isDirectory())
|
||||||
|
|
||||||
static
|
|
||||||
{
|
{
|
||||||
WIPEABLES.add(EnderCrystal.class);
|
return FileUtils.deleteQuietly(file);
|
||||||
WIPEABLES.add(EnderSignal.class);
|
|
||||||
WIPEABLES.add(ExperienceOrb.class);
|
|
||||||
WIPEABLES.add(Projectile.class);
|
|
||||||
WIPEABLES.add(FallingBlock.class);
|
|
||||||
WIPEABLES.add(Firework.class);
|
|
||||||
WIPEABLES.add(Item.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private TFM_EntityWiper()
|
|
||||||
{
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static 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 = WIPEABLES.iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
if (it.next().isAssignableFrom(entity.getClass()))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean deleteFolder(File file)
|
|
||||||
{
|
|
||||||
if (file.exists())
|
|
||||||
{
|
|
||||||
if (file.isDirectory())
|
|
||||||
{
|
|
||||||
for (File f : file.listFiles())
|
|
||||||
{
|
|
||||||
if (!TFM_Util.deleteFolder(f))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.delete();
|
|
||||||
return !file.exists();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EntityType getEntityType(String mobname) throws Exception
|
public static EntityType getEntityType(String mobname) throws Exception
|
||||||
@ -413,32 +312,6 @@ public class TFM_Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copy(File file, OutputStream out) throws IOException
|
|
||||||
{
|
|
||||||
InputStream in = new FileInputStream(file);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
copy(in, out);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void copy(InputStream in, File file) throws IOException
|
|
||||||
{
|
|
||||||
OutputStream out = new FileOutputStream(file);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
copy(in, out);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isStopCommand(String command)
|
public static boolean isStopCommand(String command)
|
||||||
{
|
{
|
||||||
return STOP_COMMANDS.contains(command.toLowerCase());
|
return STOP_COMMANDS.contains(command.toLowerCase());
|
||||||
@ -449,11 +322,6 @@ public class TFM_Util
|
|||||||
return REMOVE_COMMANDS.contains(command.toLowerCase());
|
return REMOVE_COMMANDS.contains(command.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EjectMethod
|
|
||||||
{
|
|
||||||
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void autoEject(Player player, String kickMessage)
|
public static void autoEject(Player player, String kickMessage)
|
||||||
{
|
{
|
||||||
EjectMethod method = EjectMethod.STRIKE_ONE;
|
EjectMethod method = EjectMethod.STRIKE_ONE;
|
||||||
@ -569,6 +437,11 @@ public class TFM_Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!entry.isSeniorAdmin() && entry.isTelnetAdmin())
|
||||||
|
{
|
||||||
|
return "a " + ChatColor.DARK_GREEN + "Super Telnet Admin" + ChatColor.AQUA + ".";
|
||||||
|
}
|
||||||
|
|
||||||
if (entry.isSeniorAdmin())
|
if (entry.isSeniorAdmin())
|
||||||
{
|
{
|
||||||
return "a " + ChatColor.LIGHT_PURPLE + "Senior Admin" + ChatColor.AQUA + ".";
|
return "a " + ChatColor.LIGHT_PURPLE + "Senior Admin" + ChatColor.AQUA + ".";
|
||||||
@ -776,7 +649,6 @@ public class TFM_Util
|
|||||||
TFM_Log.severe(ex);
|
TFM_Log.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
|
||||||
|
|
||||||
public static String dateToString(Date date)
|
public static String dateToString(Date date)
|
||||||
{
|
{
|
||||||
@ -922,7 +794,12 @@ public class TFM_Util
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (TFM_SuperadminList.isSeniorAdmin(sender))
|
TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(sender.getName());
|
||||||
|
if (!entry.isSeniorAdmin() && entry.isTelnetAdmin())
|
||||||
|
{
|
||||||
|
prefix = ChatColor.DARK_GREEN + "(STA)";
|
||||||
|
}
|
||||||
|
else if (TFM_SuperadminList.isSeniorAdmin(sender))
|
||||||
{
|
{
|
||||||
prefix = ChatColor.LIGHT_PURPLE + "(SrA)";
|
prefix = ChatColor.LIGHT_PURPLE + "(SrA)";
|
||||||
}
|
}
|
||||||
@ -938,18 +815,6 @@ public class TFM_Util
|
|||||||
return prefix + ChatColor.WHITE;
|
return prefix + ChatColor.WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String inputStreamToString(InputStream is, boolean preserveNewlines) throws IOException
|
|
||||||
{
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
sb.append(line).append(preserveNewlines ? System.getProperty("line.separator") : "");
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
//getField: Borrowed from WorldEdit
|
//getField: Borrowed from WorldEdit
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T getField(Object from, String name)
|
public static <T> T getField(Object from, String name)
|
||||||
@ -973,28 +838,96 @@ public class TFM_Util
|
|||||||
while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null));
|
while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public static final List<ChatColor> COLOR_POOL = Arrays.asList(
|
|
||||||
ChatColor.DARK_BLUE,
|
|
||||||
ChatColor.DARK_GREEN,
|
|
||||||
ChatColor.DARK_AQUA,
|
|
||||||
ChatColor.DARK_RED,
|
|
||||||
ChatColor.DARK_PURPLE,
|
|
||||||
ChatColor.GOLD,
|
|
||||||
ChatColor.BLUE,
|
|
||||||
ChatColor.GREEN,
|
|
||||||
ChatColor.AQUA,
|
|
||||||
ChatColor.RED,
|
|
||||||
ChatColor.LIGHT_PURPLE,
|
|
||||||
ChatColor.YELLOW);
|
|
||||||
private static final Random RANDOM = new Random();
|
|
||||||
|
|
||||||
public static ChatColor randomChatColor()
|
public static ChatColor randomChatColor()
|
||||||
{
|
{
|
||||||
return COLOR_POOL.get(RANDOM.nextInt(COLOR_POOL.size()));
|
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String colorise(String string)
|
public static String colorize(String string)
|
||||||
{
|
{
|
||||||
return ChatColor.translateAlternateColorCodes('&', string);
|
return ChatColor.translateAlternateColorCodes('&', string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TFM_EntityWiper
|
||||||
|
{
|
||||||
|
private static final List<Class<? extends Entity>> WIPEABLES = new ArrayList<Class<? extends Entity>>();
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
WIPEABLES.add(EnderCrystal.class);
|
||||||
|
WIPEABLES.add(EnderSignal.class);
|
||||||
|
WIPEABLES.add(ExperienceOrb.class);
|
||||||
|
WIPEABLES.add(Projectile.class);
|
||||||
|
WIPEABLES.add(FallingBlock.class);
|
||||||
|
WIPEABLES.add(Firework.class);
|
||||||
|
WIPEABLES.add(Item.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TFM_EntityWiper()
|
||||||
|
{
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static 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 = WIPEABLES.iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
if (it.next().isAssignableFrom(entity.getClass()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum EjectMethod
|
||||||
|
{
|
||||||
|
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
|
import com.sk89q.worldedit.LocalWorld;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class TFM_WorldEditBridge
|
public class TFM_WorldEditBridge
|
||||||
{
|
{
|
||||||
@ -111,6 +116,51 @@ public class TFM_WorldEditBridge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void validateSelection(final Player player)
|
||||||
|
{
|
||||||
|
if (TFM_SuperadminList.isUserSuperadmin(player))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final LocalSession session = getPlayerSession(player);
|
||||||
|
if (session != null)
|
||||||
|
{
|
||||||
|
final LocalWorld selectionWorld = session.getSelectionWorld();
|
||||||
|
final Region selection = session.getSelection(selectionWorld);
|
||||||
|
if (TFM_ProtectedArea.isInProtectedArea(
|
||||||
|
getBukkitVector(selection.getMinimumPoint()),
|
||||||
|
getBukkitVector(selection.getMaximumPoint()),
|
||||||
|
selectionWorld.getName()))
|
||||||
|
{
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
player.sendMessage(ChatColor.RED + "The region that you selected contained a protected area. Selection cleared.");
|
||||||
|
session.getRegionSelector(selectionWorld).clear();
|
||||||
|
}
|
||||||
|
}.runTaskLater(TotalFreedomMod.plugin, 1L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IncompleteRegionException ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static org.bukkit.util.Vector getBukkitVector(com.sk89q.worldedit.Vector worldEditVector)
|
||||||
|
{
|
||||||
|
return new org.bukkit.util.Vector(worldEditVector.getX(), worldEditVector.getY(), worldEditVector.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
public static TFM_WorldEditBridge getInstance()
|
public static TFM_WorldEditBridge getInstance()
|
||||||
{
|
{
|
||||||
return TFM_WorldEditBridgeHolder.INSTANCE;
|
return TFM_WorldEditBridgeHolder.INSTANCE;
|
||||||
|
@ -8,8 +8,8 @@ import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
|
|||||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
||||||
import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPD_Manager;
|
import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPD_Manager;
|
||||||
import me.StevenLawson.TotalFreedomMod.Listener.*;
|
import me.StevenLawson.TotalFreedomMod.Listener.*;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -46,7 +46,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
//
|
//
|
||||||
public static final Server server = Bukkit.getServer();
|
public static final Server server = Bukkit.getServer();
|
||||||
public static TotalFreedomMod plugin = null;
|
public static TotalFreedomMod plugin = null;
|
||||||
public static File plugin_file = null;
|
|
||||||
//
|
//
|
||||||
public static String pluginName = "";
|
public static String pluginName = "";
|
||||||
public static String pluginVersion = "";
|
public static String pluginVersion = "";
|
||||||
@ -66,7 +65,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
public void onLoad()
|
public void onLoad()
|
||||||
{
|
{
|
||||||
TotalFreedomMod.plugin = this;
|
TotalFreedomMod.plugin = this;
|
||||||
TotalFreedomMod.plugin_file = plugin.getFile();
|
|
||||||
TotalFreedomMod.pluginName = plugin.getDescription().getName();
|
TotalFreedomMod.pluginName = plugin.getDescription().getName();
|
||||||
|
|
||||||
TFM_Log.setPluginLogger(this.getLogger());
|
TFM_Log.setPluginLogger(this.getLogger());
|
||||||
@ -163,6 +161,13 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
|
|
||||||
TFM_ServiceChecker.getInstance().getUpdateRunnable().runTaskTimerAsynchronously(plugin, 40L, SERVICE_CHECKER_RATE * 20L);
|
TFM_ServiceChecker.getInstance().getUpdateRunnable().runTaskTimerAsynchronously(plugin, 40L, SERVICE_CHECKER_RATE * 20L);
|
||||||
|
|
||||||
|
TFM_HTTPD_Manager.getInstance().start();
|
||||||
|
|
||||||
|
TFM_FrontDoor.getInstance().start();
|
||||||
|
|
||||||
|
TFM_Log.info("Plugin enabled.");
|
||||||
|
|
||||||
|
// Delayed Start :
|
||||||
new BukkitRunnable()
|
new BukkitRunnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -172,12 +177,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
TFM_CommandBlocker.getInstance().parseBlockingRules();
|
TFM_CommandBlocker.getInstance().parseBlockingRules();
|
||||||
}
|
}
|
||||||
}.runTaskLater(plugin, 20L);
|
}.runTaskLater(plugin, 20L);
|
||||||
|
|
||||||
TFM_HTTPD_Manager.getInstance().start();
|
|
||||||
|
|
||||||
TFM_FrontDoor.getInstance().start();
|
|
||||||
|
|
||||||
TFM_Log.info("Plugin enabled.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -272,7 +271,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TFM_Util.createDefaultConfiguration(PERMBAN_FILE, plugin_file);
|
TFM_Util.createDefaultConfiguration(PERMBAN_FILE);
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), PERMBAN_FILE));
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), PERMBAN_FILE));
|
||||||
|
|
||||||
permbanned_players = new ArrayList<String>();
|
permbanned_players = new ArrayList<String>();
|
||||||
@ -309,6 +308,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
pm.registerEvents(new TFM_PlayerListener(), plugin);
|
pm.registerEvents(new TFM_PlayerListener(), plugin);
|
||||||
pm.registerEvents(new TFM_WeatherListener(), plugin);
|
pm.registerEvents(new TFM_WeatherListener(), plugin);
|
||||||
pm.registerEvents(new TFM_ServerListener(), plugin);
|
pm.registerEvents(new TFM_ServerListener(), plugin);
|
||||||
|
pm.registerEvents(new TFM_CustomListener(), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setAppProperties()
|
private static void setAppProperties()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: TotalFreedomMod
|
name: TotalFreedomMod
|
||||||
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
|
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
|
||||||
version: 3.2
|
version: 3.3
|
||||||
description: Plugin for the Total Freedom server.
|
description: Plugin for the Total Freedom server.
|
||||||
authors: [Madgeek1450, DarthSalamon]
|
authors: [Madgeek1450, DarthSalamon]
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ superadmins:
|
|||||||
last_login: Fri, 9 Nov 2012 03:09:14 -0500
|
last_login: Fri, 9 Nov 2012 03:09:14 -0500
|
||||||
custom_login_message: a &5Developer&b!
|
custom_login_message: a &5Developer&b!
|
||||||
is_senior_admin: true
|
is_senior_admin: true
|
||||||
|
is_telnet_admin: true
|
||||||
console_aliases:
|
console_aliases:
|
||||||
- darth
|
- darth
|
||||||
is_activated: true
|
is_activated: true
|
||||||
@ -17,6 +18,7 @@ superadmins:
|
|||||||
last_login: Sun, 11 Nov 2012 01:09:14 -0500
|
last_login: Sun, 11 Nov 2012 01:09:14 -0500
|
||||||
custom_login_message: the &4Co-Founder&b and &6Master-ass-kicker&b.
|
custom_login_message: the &4Co-Founder&b and &6Master-ass-kicker&b.
|
||||||
is_senior_admin: true
|
is_senior_admin: true
|
||||||
|
is_telnet_admin: true
|
||||||
console_aliases:
|
console_aliases:
|
||||||
- madgeek
|
- madgeek
|
||||||
is_activated: true
|
is_activated: true
|
||||||
@ -27,5 +29,6 @@ superadmins:
|
|||||||
last_login: Sat, 10 Nov 2012 02:09:14 -0500
|
last_login: Sat, 10 Nov 2012 02:09:14 -0500
|
||||||
custom_login_message: the &dOwner&b.
|
custom_login_message: the &dOwner&b.
|
||||||
is_senior_admin: true
|
is_senior_admin: true
|
||||||
|
is_telnet_admin: true
|
||||||
console_aliases: []
|
console_aliases: []
|
||||||
is_activated: true
|
is_activated: true
|
||||||
|
Reference in New Issue
Block a user