mirror of
https://github.com/essentials/Essentials.git
synced 2025-09-03 03:32:42 +02:00
Merge branch 'master' into release
Conflicts: Essentials/src/com/earth2me/essentials/Essentials.java Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java Essentials/src/com/earth2me/essentials/commands/Commandspawner.java Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java Essentials/src/com/earth2me/essentials/register/payment/Methods.java Essentials/src/items.csv EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java lib/bukkit-0.0.1-SNAPSHOT.jar lib/craftbukkit-0.0.1-SNAPSHOT.jar
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -23,3 +23,6 @@
|
||||
/EssentialsXMPP/build/
|
||||
/EssentialsProtect/dist/
|
||||
/EssentialsProtect/build/
|
||||
/EssentialsPermissionsCommands/nbproject/private/
|
||||
/EssentialsPermissionsCommands/build/
|
||||
/EssentialsPermissionsCommands/dist/
|
@@ -636,6 +636,13 @@ is divided into following sections:
|
||||
<param name="call.target" value="jar"/>
|
||||
<param name="transfer.built-jar.properties" value="${built-jar.properties}"/>
|
||||
</antcall>
|
||||
<antcall target="-maybe-call-dep">
|
||||
<param name="call.built.properties" value="${built-jar.properties}"/>
|
||||
<param location="${project.EssentialsPermissionsCommands}" name="call.subproject"/>
|
||||
<param location="${project.EssentialsPermissionsCommands}/build.xml" name="call.script"/>
|
||||
<param name="call.target" value="jar"/>
|
||||
<param name="transfer.built-jar.properties" value="${built-jar.properties}"/>
|
||||
</antcall>
|
||||
<antcall target="-maybe-call-dep">
|
||||
<param name="call.built.properties" value="${built-jar.properties}"/>
|
||||
<param location="${project.EssentialsProtect}" name="call.subproject"/>
|
||||
@@ -650,6 +657,13 @@ is divided into following sections:
|
||||
<param name="call.target" value="jar"/>
|
||||
<param name="transfer.built-jar.properties" value="${built-jar.properties}"/>
|
||||
</antcall>
|
||||
<antcall target="-maybe-call-dep">
|
||||
<param name="call.built.properties" value="${built-jar.properties}"/>
|
||||
<param location="${project.EssentialsXMPP}" name="call.subproject"/>
|
||||
<param location="${project.EssentialsXMPP}/build.xml" name="call.script"/>
|
||||
<param name="call.target" value="jar"/>
|
||||
<param name="transfer.built-jar.properties" value="${built-jar.properties}"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
|
||||
<target depends="init" name="-check-automatic-build">
|
||||
@@ -1121,6 +1135,13 @@ is divided into following sections:
|
||||
<param name="call.target" value="clean"/>
|
||||
<param name="transfer.built-clean.properties" value="${built-clean.properties}"/>
|
||||
</antcall>
|
||||
<antcall target="-maybe-call-dep">
|
||||
<param name="call.built.properties" value="${built-clean.properties}"/>
|
||||
<param location="${project.EssentialsPermissionsCommands}" name="call.subproject"/>
|
||||
<param location="${project.EssentialsPermissionsCommands}/build.xml" name="call.script"/>
|
||||
<param name="call.target" value="clean"/>
|
||||
<param name="transfer.built-clean.properties" value="${built-clean.properties}"/>
|
||||
</antcall>
|
||||
<antcall target="-maybe-call-dep">
|
||||
<param name="call.built.properties" value="${built-clean.properties}"/>
|
||||
<param location="${project.EssentialsProtect}" name="call.subproject"/>
|
||||
@@ -1135,6 +1156,13 @@ is divided into following sections:
|
||||
<param name="call.target" value="clean"/>
|
||||
<param name="transfer.built-clean.properties" value="${built-clean.properties}"/>
|
||||
</antcall>
|
||||
<antcall target="-maybe-call-dep">
|
||||
<param name="call.built.properties" value="${built-clean.properties}"/>
|
||||
<param location="${project.EssentialsXMPP}" name="call.subproject"/>
|
||||
<param location="${project.EssentialsXMPP}/build.xml" name="call.script"/>
|
||||
<param name="call.target" value="clean"/>
|
||||
<param name="transfer.built-clean.properties" value="${built-clean.properties}"/>
|
||||
</antcall>
|
||||
</target>
|
||||
<target depends="init" name="-do-clean">
|
||||
<delete dir="${build.dir}"/>
|
||||
|
@@ -1,8 +1,8 @@
|
||||
build.xml.data.CRC32=c4188209
|
||||
build.xml.data.CRC32=2bd2dd75
|
||||
build.xml.script.CRC32=7a797370
|
||||
build.xml.stylesheet.CRC32=28e38971@1.43.1.45
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=c4188209
|
||||
nbproject/build-impl.xml.script.CRC32=73a4865f
|
||||
nbproject/build-impl.xml.data.CRC32=2bd2dd75
|
||||
nbproject/build-impl.xml.script.CRC32=769e541b
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45
|
||||
|
@@ -31,11 +31,13 @@ jar.compress=false
|
||||
javac.classpath=\
|
||||
${reference.Essentials.jar}:\
|
||||
${reference.EssentialsChat.jar}:\
|
||||
${reference.EssentialsGroupBridge.jar}:\
|
||||
${reference.EssentialsGroupManager.jar}:\
|
||||
${reference.EssentialsProtect.jar}:\
|
||||
${reference.EssentialsPermissionsCommands.jar}:\
|
||||
${reference.EssentialsSpawn.jar}:\
|
||||
${reference.EssentialsGeoIP.jar}
|
||||
${reference.EssentialsGeoIP.jar}:\
|
||||
${reference.EssentialsXMPP.jar}:\
|
||||
${reference.EssentialsGroupBridge.jar}:\
|
||||
${reference.EssentialsGroupManager.jar}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
@@ -69,15 +71,19 @@ project.EssentialsChat=../EssentialsChat
|
||||
project.EssentialsGeoIP=../EssentialsGeoIP
|
||||
project.EssentialsGroupBridge=../EssentialsGroupBridge
|
||||
project.EssentialsGroupManager=../EssentialsGroupManager
|
||||
project.EssentialsPermissionsCommands=../EssentialsPermissionsCommands
|
||||
project.EssentialsProtect=../EssentialsProtect
|
||||
project.EssentialsSpawn=../EssentialsSpawn
|
||||
project.EssentialsXMPP=../EssentialsXMPP
|
||||
reference.Essentials.jar=${project.Essentials}/dist/Essentials.jar
|
||||
reference.EssentialsChat.jar=${project.EssentialsChat}/dist/EssentialsChat.jar
|
||||
reference.EssentialsGeoIP.jar=${project.EssentialsGeoIP}/dist/EssentialsGeoIP.jar
|
||||
reference.EssentialsGroupBridge.jar=${project.EssentialsGroupBridge}/dist/EssentialsGroupBridge.jar
|
||||
reference.EssentialsGroupManager.jar=${project.EssentialsGroupManager}/dist/EssentialsGroupManager.jar
|
||||
reference.EssentialsPermissionsCommands.jar=${project.EssentialsPermissionsCommands}/dist/EssentialsPermissionsCommands.jar
|
||||
reference.EssentialsProtect.jar=${project.EssentialsProtect}/dist/EssentialsProtect.jar
|
||||
reference.EssentialsSpawn.jar=${project.EssentialsSpawn}/dist/EssentialsSpawn.jar
|
||||
reference.EssentialsXMPP.jar=${project.EssentialsXMPP}/dist/EssentialsXMPP.jar
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
|
@@ -55,6 +55,14 @@
|
||||
<clean-target>clean</clean-target>
|
||||
<id>jar</id>
|
||||
</reference>
|
||||
<reference>
|
||||
<foreign-project>EssentialsPermissionsCommands</foreign-project>
|
||||
<artifact-type>jar</artifact-type>
|
||||
<script>build.xml</script>
|
||||
<target>jar</target>
|
||||
<clean-target>clean</clean-target>
|
||||
<id>jar</id>
|
||||
</reference>
|
||||
<reference>
|
||||
<foreign-project>EssentialsProtect</foreign-project>
|
||||
<artifact-type>jar</artifact-type>
|
||||
@@ -71,6 +79,14 @@
|
||||
<clean-target>clean</clean-target>
|
||||
<id>jar</id>
|
||||
</reference>
|
||||
<reference>
|
||||
<foreign-project>EssentialsXMPP</foreign-project>
|
||||
<artifact-type>jar</artifact-type>
|
||||
<script>build.xml</script>
|
||||
<target>jar</target>
|
||||
<clean-target>clean</clean-target>
|
||||
<id>jar</id>
|
||||
</reference>
|
||||
</references>
|
||||
</configuration>
|
||||
</project>
|
||||
|
@@ -31,11 +31,11 @@ file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=..\\lib\\craftbukkit-0.0.1-SNAPSHO
|
||||
file.reference.iCo4.jar=../lib/iCo4.jar
|
||||
file.reference.iCo5.jar=../lib/iCo5.jar
|
||||
file.reference.junit-4.5.jar=..\\lib\\junit_4\\junit-4.5.jar
|
||||
file.reference.Permissions.jar=..\\lib\\Permissions.jar
|
||||
file.reference.Permissions3.jar=../lib/Permissions3.jar
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=\
|
||||
${file.reference.Permissions.jar}:\
|
||||
${file.reference.Permissions3.jar}:\
|
||||
${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}:\
|
||||
${file.reference.BOSEconomy.jar}:\
|
||||
${file.reference.iCo4.jar}:\
|
||||
|
157
Essentials/src/com/earth2me/essentials/BanWorkaround.java
Normal file
157
Essentials/src/com/earth2me/essentials/BanWorkaround.java
Normal file
@@ -0,0 +1,157 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.ServerConfigurationManager;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
|
||||
public class BanWorkaround implements IConf
|
||||
{
|
||||
private transient final IEssentials ess;
|
||||
private transient final ServerConfigurationManager scm;
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private transient final Set<String> bans = new HashSet<String>();
|
||||
private transient final Set<String> bannedIps = new HashSet<String>();
|
||||
|
||||
public BanWorkaround(final IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
this.scm = ((CraftServer)ess.getServer()).getHandle();
|
||||
}
|
||||
|
||||
public void banByName(final String name)
|
||||
{
|
||||
scm.a(name);
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
public void unbanByName(String name)
|
||||
{
|
||||
scm.b(name);
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
public void banByIp(final String ip)
|
||||
{
|
||||
scm.c(ip);
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
public void unbanByIp(final String ip)
|
||||
{
|
||||
scm.d(ip);
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
public boolean isNameBanned(final String name)
|
||||
{
|
||||
return bans.contains(name.toLowerCase());
|
||||
}
|
||||
|
||||
public boolean isIpBanned(final String ip)
|
||||
{
|
||||
return bannedIps.contains(ip.toLowerCase());
|
||||
}
|
||||
|
||||
public void reloadConfig()
|
||||
{
|
||||
//I don't like this but it needs to be done until CB fixors
|
||||
final File file = new File(ess.getDataFolder().getParentFile().getParentFile(), "banned-players.txt");
|
||||
try
|
||||
{
|
||||
if (!file.exists())
|
||||
{
|
||||
throw new FileNotFoundException(Util.i18n("bannedPlayersFileNotFound"));
|
||||
}
|
||||
|
||||
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
||||
try
|
||||
{
|
||||
bans.clear();
|
||||
while (bufferedReader.ready())
|
||||
{
|
||||
|
||||
final String line = bufferedReader.readLine().trim().toLowerCase();
|
||||
if (line.length() > 0 && line.charAt(0) == '#')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bans.add(line);
|
||||
|
||||
}
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), io);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
bufferedReader.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
|
||||
}
|
||||
|
||||
final File ipFile = new File(ess.getDataFolder().getParentFile().getParentFile(), "banned-ips.txt");
|
||||
try
|
||||
{
|
||||
if (!ipFile.exists())
|
||||
{
|
||||
throw new FileNotFoundException(Util.i18n("bannedIpsFileNotFound"));
|
||||
}
|
||||
|
||||
final BufferedReader bufferedReader = new BufferedReader(new FileReader(ipFile));
|
||||
try
|
||||
{
|
||||
bannedIps.clear();
|
||||
while (bufferedReader.ready())
|
||||
{
|
||||
|
||||
final String line = bufferedReader.readLine().trim().toLowerCase();
|
||||
if (line.length() > 0 && line.charAt(0) == '#')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bannedIps.add(line);
|
||||
|
||||
}
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), io);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
bufferedReader.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Charge
|
||||
{
|
||||
private final String command;
|
||||
private final Double costs;
|
||||
private final ItemStack items;
|
||||
private final IEssentials ess;
|
||||
|
||||
public Charge(String command, IEssentials ess)
|
||||
{
|
||||
this(command, null, null, ess);
|
||||
}
|
||||
|
||||
public Charge(double money, IEssentials ess)
|
||||
{
|
||||
this(null, money, null, ess);
|
||||
}
|
||||
|
||||
public Charge(ItemStack items, IEssentials ess)
|
||||
{
|
||||
this(null, null, items, ess);
|
||||
}
|
||||
|
||||
private Charge(String command, Double money, ItemStack item, IEssentials ess)
|
||||
{
|
||||
this.command = command;
|
||||
this.costs = money;
|
||||
this.items = item;
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
public void isAffordableFor(IUser user) throws Exception
|
||||
{
|
||||
double mon = user.getMoney();
|
||||
if (costs != null)
|
||||
{
|
||||
if (mon < costs && !user.isAuthorized("essentials.eco.loan"))
|
||||
{
|
||||
throw new Exception(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
}
|
||||
if (items != null)
|
||||
{
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, items))
|
||||
{
|
||||
throw new Exception(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
|
||||
}
|
||||
}
|
||||
if (command != null && !command.isEmpty())
|
||||
{
|
||||
if (user.isAuthorized("essentials.nocommandcost.all")
|
||||
|| user.isAuthorized("essentials.nocommandcost." + command))
|
||||
{
|
||||
return;
|
||||
}
|
||||
double cost = ess.getSettings().getCommandCost(command.startsWith("/") ? command.substring(1) : command);
|
||||
if (mon < cost && !user.isAuthorized("essentials.eco.loan"))
|
||||
{
|
||||
throw new Exception(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void charge(IUser user) throws Exception
|
||||
{
|
||||
double mon = user.getMoney();
|
||||
if (costs != null)
|
||||
{
|
||||
if (mon < costs && !user.isAuthorized("essentials.eco.loan"))
|
||||
{
|
||||
throw new Exception(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
user.takeMoney(costs);
|
||||
}
|
||||
if (items != null)
|
||||
{
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, items))
|
||||
{
|
||||
throw new Exception(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
|
||||
}
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, items);
|
||||
user.updateInventory();
|
||||
}
|
||||
if (command != null && !command.isEmpty())
|
||||
{
|
||||
if (user.isAuthorized("essentials.nocommandcost.all")
|
||||
|| user.isAuthorized("essentials.nocommandcost." + command))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double cost = ess.getSettings().getCommandCost(command.startsWith("/") ? command.substring(1) : command);
|
||||
if (mon < cost && !user.isAuthorized("essentials.eco.loan"))
|
||||
{
|
||||
throw new Exception(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
user.takeMoney(cost);
|
||||
}
|
||||
}
|
||||
}
|
15
Essentials/src/com/earth2me/essentials/ChargeException.java
Normal file
15
Essentials/src/com/earth2me/essentials/ChargeException.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
|
||||
public class ChargeException extends Exception
|
||||
{
|
||||
public ChargeException(final String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ChargeException(final String message, final Throwable throwable)
|
||||
{
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class ConfigPermissionsHandler implements IPermissionsHandler
|
||||
{
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public ConfigPermissionsHandler(final IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
public String getGroup(final Player base)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
|
||||
public boolean canBuild(final Player base, final String group)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean inGroup(final Player base, final String group)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPermission(final Player base, final String node)
|
||||
{
|
||||
final String[] cmds = node.split("\\.", 2);
|
||||
return !ess.getSettings().isCommandRestricted(cmds[cmds.length - 1])
|
||||
&& ess.getSettings().isPlayerCommand(cmds[cmds.length - 1]);
|
||||
}
|
||||
|
||||
public String getPrefix(final Player base)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getSuffix(final Player base)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.api.Economy;
|
||||
import com.earth2me.essentials.commands.EssentialsCommand;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
@@ -27,10 +28,13 @@ import org.bukkit.command.CommandSender;
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
||||
import com.earth2me.essentials.register.payment.Methods;
|
||||
import com.earth2me.essentials.signs.SignBlockListener;
|
||||
import com.earth2me.essentials.signs.SignEntityListener;
|
||||
import com.earth2me.essentials.signs.SignPlayerListener;
|
||||
import java.math.BigInteger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
@@ -42,119 +46,130 @@ import org.bukkit.plugin.java.*;
|
||||
|
||||
public class Essentials extends JavaPlugin implements IEssentials
|
||||
{
|
||||
public static final String AUTHORS = "Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans and Xeology";
|
||||
public static final int minBukkitBuildVersion = 953;
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
private Settings settings;
|
||||
private EssentialsPlayerListener playerListener;
|
||||
private EssentialsBlockListener blockListener;
|
||||
private EssentialsEntityListener entityListener;
|
||||
private JailPlayerListener jailPlayerListener;
|
||||
private static Essentials instance = null;
|
||||
private Spawn spawn;
|
||||
private Jail jail;
|
||||
private Warps warps;
|
||||
private Worth worth;
|
||||
private List<IConf> confList;
|
||||
public ArrayList bans = new ArrayList();
|
||||
public ArrayList bannedIps = new ArrayList();
|
||||
private Backup backup;
|
||||
private final Map<String, User> users = new HashMap<String, User>();
|
||||
private EssentialsTimer timer;
|
||||
private EssentialsUpdateTimer updateTimer;
|
||||
private boolean registerFallback = true;
|
||||
private final Methods paymentMethod = new Methods();
|
||||
private final static boolean enableErrorLogging = false;
|
||||
private final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
|
||||
public static final int BUKKIT_VERSION = 974;
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private transient ISettings settings;
|
||||
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);
|
||||
private transient Spawn spawn;
|
||||
private transient Jail jail;
|
||||
private transient Warps warps;
|
||||
private transient Worth worth;
|
||||
private transient List<IConf> confList;
|
||||
private transient Backup backup;
|
||||
private transient BanWorkaround bans;
|
||||
private transient ItemDb itemDb;
|
||||
private transient final Map<String, User> users = new HashMap<String, User>();
|
||||
private transient EssentialsUpdateTimer updateTimer;
|
||||
private transient final Methods paymentMethod = new Methods();
|
||||
private transient final static boolean enableErrorLogging = false;
|
||||
private transient final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
|
||||
private transient IPermissionsHandler permissionsHandler;
|
||||
|
||||
public static IEssentials getStatic()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Settings getSettings()
|
||||
public ISettings getSettings()
|
||||
{
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void setupForTesting(Server server) throws IOException, InvalidDescriptionException
|
||||
public void setupForTesting(final Server server) throws IOException, InvalidDescriptionException
|
||||
{
|
||||
File dataFolder = File.createTempFile("essentialstest", "");
|
||||
dataFolder.delete();
|
||||
dataFolder.mkdir();
|
||||
logger.log(Level.INFO, Util.i18n("usingTempFolderForTesting"));
|
||||
logger.log(Level.INFO, dataFolder.toString());
|
||||
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
|
||||
settings = new Settings(dataFolder);
|
||||
setStatic();
|
||||
final File dataFolder = File.createTempFile("essentialstest", "");
|
||||
if (!dataFolder.delete())
|
||||
{
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
public void setStatic()
|
||||
if (!dataFolder.mkdir())
|
||||
{
|
||||
instance = this;
|
||||
throw new IOException();
|
||||
}
|
||||
LOGGER.log(Level.INFO, Util.i18n("usingTempFolderForTesting"));
|
||||
LOGGER.log(Level.INFO, dataFolder.toString());
|
||||
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
|
||||
settings = new Settings(this);
|
||||
permissionsHandler = new ConfigPermissionsHandler(this);
|
||||
Economy.setEss(this);
|
||||
}
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
if (!Thread.currentThread().getStackTrace()[5].getMethodName().equals("loadPlugin")) {
|
||||
logger.log(Level.SEVERE, "Another plugin is trying to enable Essentials manually. Don't do this! It's probably "
|
||||
+ Thread.currentThread().getStackTrace()[5].getClassName());
|
||||
final String[] javaversion = System.getProperty("java.version").split("\\.", 3);
|
||||
if (javaversion == null || javaversion.length < 2 || Integer.parseInt(javaversion[1]) < 6)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, "Java version not supported! Please install Java 1.6. You have " + System.getProperty("java.version"));
|
||||
}
|
||||
if (enableErrorLogging)
|
||||
{
|
||||
logger.addHandler(errorHandler);
|
||||
LOGGER.addHandler(errorHandler);
|
||||
}
|
||||
setStatic();
|
||||
EssentialsUpgrade upgrade = new EssentialsUpgrade(this.getDescription().getVersion(), this);
|
||||
upgrade.beforeSettings();
|
||||
confList = new ArrayList<IConf>();
|
||||
settings = new Settings(this.getDataFolder());
|
||||
settings = new Settings(this);
|
||||
confList.add(settings);
|
||||
upgrade.afterSettings();
|
||||
Util.updateLocale(settings.getLocale(), this.getDataFolder());
|
||||
Util.updateLocale(settings.getLocale(), this);
|
||||
spawn = new Spawn(getServer(), this.getDataFolder());
|
||||
confList.add(spawn);
|
||||
warps = new Warps(getServer(), this.getDataFolder());
|
||||
confList.add(warps);
|
||||
worth = new Worth(this.getDataFolder());
|
||||
confList.add(worth);
|
||||
bans = new BanWorkaround(this);
|
||||
confList.add(bans);
|
||||
itemDb = new ItemDb(this);
|
||||
confList.add(itemDb);
|
||||
reload();
|
||||
backup = new Backup(this);
|
||||
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
for (Plugin plugin : pm.getPlugins())
|
||||
{
|
||||
if (plugin.getDescription().getName().startsWith("Essentials"))
|
||||
if (plugin.getDescription().getName().startsWith("Essentials")
|
||||
&& !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()))
|
||||
{
|
||||
if (!plugin.getDescription().getVersion().equals(this.getDescription().getVersion()))
|
||||
{
|
||||
logger.log(Level.WARNING, Util.format("versionMismatch", plugin.getDescription().getName()));
|
||||
LOGGER.log(Level.WARNING, Util.format("versionMismatch", plugin.getDescription().getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Matcher versionMatch = Pattern.compile("git-Bukkit-([0-9]+).([0-9]+).([0-9]+)-[0-9]+-[0-9a-z]+-b([0-9]+)jnks.*").matcher(getServer().getVersion());
|
||||
final Matcher versionMatch = Pattern.compile("git-Bukkit-([0-9]+).([0-9]+).([0-9]+)-[0-9]+-[0-9a-z]+-b([0-9]+)jnks.*").matcher(getServer().getVersion());
|
||||
if (versionMatch.matches())
|
||||
{
|
||||
int versionNumber = Integer.parseInt(versionMatch.group(4));
|
||||
if (versionNumber < minBukkitBuildVersion)
|
||||
final int versionNumber = Integer.parseInt(versionMatch.group(4));
|
||||
if (versionNumber < BUKKIT_VERSION)
|
||||
{
|
||||
logger.log(Level.WARNING, Util.i18n("notRecommendedBukkit"));
|
||||
LOGGER.log(Level.WARNING, Util.i18n("notRecommendedBukkit"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.log(Level.INFO, Util.i18n("bukkitFormatChanged"));
|
||||
LOGGER.log(Level.INFO, Util.i18n("bukkitFormatChanged"));
|
||||
}
|
||||
|
||||
final Plugin permissionsPlugin = pm.getPlugin("Permissions");
|
||||
|
||||
ServerListener serverListener = new EssentialsPluginListener(paymentMethod);
|
||||
if (permissionsPlugin != null)
|
||||
{
|
||||
if (permissionsPlugin.getDescription().getVersion().charAt(0) == '3')
|
||||
{
|
||||
this.permissionsHandler = new Permissions3Handler(permissionsPlugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.permissionsHandler = new Permissions2Handler(permissionsPlugin);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.permissionsHandler = new ConfigPermissionsHandler(this);
|
||||
}
|
||||
|
||||
final ServerListener serverListener = new EssentialsPluginListener(paymentMethod);
|
||||
pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this);
|
||||
pm.registerEvent(Type.PLUGIN_DISABLE, serverListener, Priority.Low, this);
|
||||
|
||||
playerListener = new EssentialsPlayerListener(this);
|
||||
final EssentialsPlayerListener playerListener = new EssentialsPlayerListener(this);
|
||||
pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Type.PLAYER_QUIT, playerListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Lowest, this);
|
||||
pm.registerEvent(Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Lowest, this);
|
||||
if (getSettings().getNetherPortalsEnabled())
|
||||
{
|
||||
pm.registerEvent(Type.PLAYER_MOVE, playerListener, Priority.High, this);
|
||||
@@ -166,57 +181,71 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
pm.registerEvent(Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.High, this);
|
||||
pm.registerEvent(Type.PLAYER_ANIMATION, playerListener, Priority.High, this);
|
||||
|
||||
blockListener = new EssentialsBlockListener(this);
|
||||
pm.registerEvent(Type.SIGN_CHANGE, blockListener, Priority.Low, this);
|
||||
pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Lowest, this);
|
||||
final EssentialsBlockListener blockListener = new EssentialsBlockListener(this);
|
||||
pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Lowest, this);
|
||||
|
||||
entityListener = new EssentialsEntityListener(this);
|
||||
final SignBlockListener signBlockListener = new SignBlockListener(this);
|
||||
pm.registerEvent(Type.SIGN_CHANGE, signBlockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Type.BLOCK_PLACE, signBlockListener, Priority.Low, this);
|
||||
pm.registerEvent(Type.BLOCK_BREAK, signBlockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Type.BLOCK_IGNITE, signBlockListener, Priority.Low, this);
|
||||
pm.registerEvent(Type.BLOCK_BURN, signBlockListener, Priority.Low, this);
|
||||
|
||||
final SignPlayerListener signPlayerListener = new SignPlayerListener(this);
|
||||
pm.registerEvent(Type.PLAYER_INTERACT, signPlayerListener, Priority.Low, this);
|
||||
|
||||
final SignEntityListener signEntityListener = new SignEntityListener(this);
|
||||
pm.registerEvent(Type.ENTITY_EXPLODE, signEntityListener, Priority.Low, this);
|
||||
|
||||
final EssentialsEntityListener entityListener = new EssentialsEntityListener(this);
|
||||
pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Lowest, this);
|
||||
pm.registerEvent(Type.ENTITY_COMBUST, entityListener, Priority.Lowest, this);
|
||||
pm.registerEvent(Type.ENTITY_DEATH, entityListener, Priority.Lowest, this);
|
||||
|
||||
jail = new Jail(this);
|
||||
jailPlayerListener = new JailPlayerListener(this);
|
||||
final JailPlayerListener jailPlayerListener = new JailPlayerListener(this);
|
||||
confList.add(jail);
|
||||
pm.registerEvent(Type.BLOCK_BREAK, jail, Priority.High, this);
|
||||
pm.registerEvent(Type.BLOCK_DAMAGE, jail, Priority.High, this);
|
||||
pm.registerEvent(Type.BLOCK_PLACE, jail, Priority.High, this);
|
||||
pm.registerEvent(Type.PLAYER_INTERACT, jailPlayerListener, Priority.High, this);
|
||||
attachEcoListeners();
|
||||
pm.registerEvent(Type.BLOCK_BREAK, jail, Priority.Low, this);
|
||||
pm.registerEvent(Type.BLOCK_DAMAGE, jail, Priority.Low, this);
|
||||
pm.registerEvent(Type.BLOCK_PLACE, jail, Priority.Low, this);
|
||||
pm.registerEvent(Type.PLAYER_INTERACT, jailPlayerListener, Priority.Low, this);
|
||||
pm.registerEvent(Type.PLAYER_RESPAWN, jailPlayerListener, Priority.High, this);
|
||||
pm.registerEvent(Type.PLAYER_TELEPORT, jailPlayerListener, Priority.High, this);
|
||||
|
||||
if (settings.isNetherEnabled() && getServer().getWorlds().size() < 2)
|
||||
{
|
||||
logger.log(Level.WARNING, "Old nether is disabled until multiworld support in bukkit is fixed.");
|
||||
getServer().createWorld(settings.getNetherName(), World.Environment.NETHER);
|
||||
}
|
||||
|
||||
timer = new EssentialsTimer(this);
|
||||
pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this);
|
||||
|
||||
final EssentialsTimer timer = new EssentialsTimer(this);
|
||||
getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50);
|
||||
Economy.setEss(this);
|
||||
if (enableErrorLogging)
|
||||
{
|
||||
updateTimer = new EssentialsUpdateTimer(this);
|
||||
getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 50, 50 * 60 * (this.getDescription().getVersion().startsWith("Dev") ? 60 : 360));
|
||||
}
|
||||
logger.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), AUTHORS));
|
||||
LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors())));
|
||||
}
|
||||
|
||||
public void onDisable()
|
||||
{
|
||||
instance = null;
|
||||
logger.removeHandler(errorHandler);
|
||||
Trade.closeLog();
|
||||
LOGGER.removeHandler(errorHandler);
|
||||
}
|
||||
|
||||
public void reload()
|
||||
{
|
||||
loadBanList();
|
||||
Trade.closeLog();
|
||||
|
||||
for (IConf iConf : confList)
|
||||
{
|
||||
iConf.reloadConfig();
|
||||
}
|
||||
|
||||
Util.updateLocale(settings.getLocale(), this.getDataFolder());
|
||||
Util.updateLocale(settings.getLocale(), this);
|
||||
|
||||
for (User user : users.values())
|
||||
{
|
||||
@@ -225,15 +254,6 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
|
||||
// for motd
|
||||
getConfiguration().load();
|
||||
|
||||
try
|
||||
{
|
||||
ItemDb.load(getDataFolder(), "items.csv");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.log(Level.WARNING, Util.i18n("itemsCsvNotLoaded"), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getMotd(CommandSender sender, String def)
|
||||
@@ -250,7 +270,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
String[] retval = new String[lines.size()];
|
||||
|
||||
if (lines == null || lines.isEmpty() || lines.get(0) == null)
|
||||
if (lines.isEmpty() || lines.get(0) == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -264,7 +284,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
catch (Throwable ex2)
|
||||
{
|
||||
logger.log(Level.WARNING, Util.format("corruptNodeInConfig", node));
|
||||
LOGGER.log(Level.WARNING, Util.format("corruptNodeInConfig", node));
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
@@ -332,39 +352,14 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return retval;
|
||||
}
|
||||
|
||||
@SuppressWarnings("LoggerStringConcat")
|
||||
public static void previewCommand(CommandSender sender, Command command, String commandLabel, String[] args)
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
logger.info(ChatColor.BLUE + "[PLAYER_COMMAND] " + ((Player)sender).getName() + ": /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
|
||||
{
|
||||
return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command");
|
||||
return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.");
|
||||
}
|
||||
|
||||
public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath)
|
||||
public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix)
|
||||
{
|
||||
if (("msg".equals(commandLabel.toLowerCase()) || "r".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase())) && sender instanceof Player)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append(commandLabel).append(" ");
|
||||
for (String a : args)
|
||||
{
|
||||
str.append(a).append(" ");
|
||||
}
|
||||
for (Player player : getServer().getOnlinePlayers())
|
||||
{
|
||||
if (getUser(player).isSocialSpyEnabled())
|
||||
{
|
||||
player.sendMessage(getUser(sender).getDisplayName() + " : " + str);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Allow plugins to override the command via onCommand
|
||||
if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e"))
|
||||
{
|
||||
@@ -386,24 +381,22 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(desc.getCommands() instanceof Map))
|
||||
PluginCommand pc = getServer().getPluginCommand(desc.getName() + ":" + commandLabel);
|
||||
if (pc != null)
|
||||
{
|
||||
continue;
|
||||
return pc.execute(sender, commandLabel, args);
|
||||
}
|
||||
|
||||
Map<String, Object> cmds = (Map<String, Object>)desc.getCommands();
|
||||
if (!cmds.containsKey(command.getName()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return p.onCommand(sender, command, commandLabel, args);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
previewCommand(sender, command, commandLabel, args);
|
||||
User user = sender instanceof Player ? getUser(sender) : null;
|
||||
User user = null;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
user = getUser(sender);
|
||||
LOGGER.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)));
|
||||
}
|
||||
|
||||
// New mail notification
|
||||
if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail"))
|
||||
@@ -430,14 +423,14 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
catch (Exception ex)
|
||||
{
|
||||
sender.sendMessage(Util.format("commandNotLoaded", commandLabel));
|
||||
logger.log(Level.SEVERE, Util.format("commandNotLoaded", commandLabel), ex);
|
||||
LOGGER.log(Level.SEVERE, Util.format("commandNotLoaded", commandLabel), ex);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check authorization
|
||||
if (user != null && !user.isAuthorized(cmd))
|
||||
if (user != null && !user.isAuthorized(cmd, permissionPrefix))
|
||||
{
|
||||
logger.log(Level.WARNING, Util.format("deniedAccessCommand", user.getName()));
|
||||
LOGGER.log(Level.WARNING, Util.format("deniedAccessCommand", user.getName()));
|
||||
user.sendMessage(Util.i18n("noAccessCommand"));
|
||||
return true;
|
||||
}
|
||||
@@ -463,133 +456,34 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
sender.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
LogRecord lr = new LogRecord(Level.WARNING, Util.format("errorCallingCommand", commandLabel));
|
||||
lr.setThrown(ex);
|
||||
if (getSettings().isDebug())
|
||||
{
|
||||
logger.log(lr);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (enableErrorLogging)
|
||||
{
|
||||
errorHandler.publish(lr);
|
||||
errorHandler.flush();
|
||||
}
|
||||
}
|
||||
showError(sender, ex, commandLabel);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
logger.log(Level.SEVERE, Util.format("commandFailed", commandLabel), ex);
|
||||
LOGGER.log(Level.SEVERE, Util.format("commandFailed", commandLabel), ex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void loadBanList()
|
||||
public void showError(final CommandSender sender, final Throwable exception, final String commandLabel)
|
||||
{
|
||||
//I don't like this but it needs to be done until CB fixors
|
||||
File file = new File("banned-players.txt");
|
||||
File ipFile = new File("banned-ips.txt");
|
||||
try
|
||||
sender.sendMessage(Util.format("errorWithMessage", exception.getMessage()));
|
||||
final LogRecord logRecord = new LogRecord(Level.WARNING, Util.format("errorCallingCommand", commandLabel));
|
||||
logRecord.setThrown(exception);
|
||||
if (getSettings().isDebug())
|
||||
{
|
||||
if (!file.exists())
|
||||
{
|
||||
throw new FileNotFoundException(Util.i18n("bannedPlayersFileNotFound"));
|
||||
LOGGER.log(logRecord);
|
||||
}
|
||||
|
||||
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
||||
try
|
||||
else
|
||||
{
|
||||
bans.clear();
|
||||
while (bufferedReader.ready())
|
||||
if (enableErrorLogging)
|
||||
{
|
||||
|
||||
final String line = bufferedReader.readLine().trim().toLowerCase();
|
||||
if (line.length() > 0 && line.charAt(0) == '#')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bans.add(line);
|
||||
|
||||
errorHandler.publish(logRecord);
|
||||
errorHandler.flush();
|
||||
}
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), io);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
bufferedReader.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!ipFile.exists())
|
||||
{
|
||||
throw new FileNotFoundException(Util.i18n("bannedIpsFileNotFound"));
|
||||
}
|
||||
|
||||
final BufferedReader bufferedReader = new BufferedReader(new FileReader(ipFile));
|
||||
try
|
||||
{
|
||||
bannedIps.clear();
|
||||
while (bufferedReader.ready())
|
||||
{
|
||||
|
||||
final String line = bufferedReader.readLine().trim().toLowerCase();
|
||||
if (line.length() > 0 && line.charAt(0) == '#')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bannedIps.add(line);
|
||||
|
||||
}
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), io);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
bufferedReader.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void attachEcoListeners()
|
||||
{
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
EssentialsEcoBlockListener ecoBlockListener = new EssentialsEcoBlockListener(this);
|
||||
EssentialsEcoPlayerListener ecoPlayerListener = new EssentialsEcoPlayerListener(this);
|
||||
pm.registerEvent(Type.PLAYER_INTERACT, ecoPlayerListener, Priority.High, this);
|
||||
pm.registerEvent(Type.BLOCK_BREAK, ecoBlockListener, Priority.High, this);
|
||||
pm.registerEvent(Type.SIGN_CHANGE, ecoBlockListener, Priority.Monitor, this);
|
||||
}
|
||||
|
||||
public CraftScheduler getScheduler()
|
||||
@@ -653,47 +547,37 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return u;
|
||||
}
|
||||
|
||||
public Map<String, User> getAllUsers()
|
||||
{
|
||||
return users;
|
||||
}
|
||||
|
||||
public User getOfflineUser(String name)
|
||||
{
|
||||
File userFolder = new File(getDataFolder(), "userdata");
|
||||
File userFile = new File(userFolder, Util.sanitizeFileName(name) + ".yml");
|
||||
if (userFile.exists())
|
||||
{ //Users do not get offline changes saved without being reproccessed as Users! ~ Xeology :)
|
||||
return getUser((Player)new OfflinePlayer(name));
|
||||
return getUser((Player)new OfflinePlayer(name, this));
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public World getWorld(String name)
|
||||
public World getWorld(final String name)
|
||||
{
|
||||
if (name.matches("[0-9]+"))
|
||||
{
|
||||
int id = Integer.parseInt(name);
|
||||
final int id = Integer.parseInt(name);
|
||||
if (id < getServer().getWorlds().size())
|
||||
{
|
||||
return getServer().getWorlds().get(id);
|
||||
}
|
||||
}
|
||||
World w = getServer().getWorld(name);
|
||||
if (w != null)
|
||||
{
|
||||
return w;
|
||||
}
|
||||
return null;
|
||||
return getServer().getWorld(name);
|
||||
}
|
||||
|
||||
public void setRegisterFallback(boolean registerFallback)
|
||||
{
|
||||
this.registerFallback = registerFallback;
|
||||
}
|
||||
|
||||
public boolean isRegisterFallbackEnabled()
|
||||
{
|
||||
return registerFallback;
|
||||
}
|
||||
|
||||
public void addReloadListener(IConf listener)
|
||||
public void addReloadListener(final IConf listener)
|
||||
{
|
||||
confList.add(listener);
|
||||
}
|
||||
@@ -703,7 +587,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return paymentMethod;
|
||||
}
|
||||
|
||||
public int broadcastMessage(String name, String message)
|
||||
public int broadcastMessage(final String name, final String message)
|
||||
{
|
||||
Player[] players = getServer().getOnlinePlayers();
|
||||
|
||||
@@ -734,18 +618,33 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return this.getScheduler().scheduleSyncDelayedTask(this, run);
|
||||
}
|
||||
|
||||
public int scheduleSyncRepeatingTask(final Runnable run, long delay, long period)
|
||||
public int scheduleSyncDelayedTask(final Runnable run, final long delay)
|
||||
{
|
||||
return this.getScheduler().scheduleSyncDelayedTask(this, run, delay);
|
||||
}
|
||||
|
||||
public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period)
|
||||
{
|
||||
return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
|
||||
}
|
||||
|
||||
public List<String> getBans()
|
||||
public TNTExplodeListener getTNTListener()
|
||||
{
|
||||
return tntListener;
|
||||
}
|
||||
|
||||
public IPermissionsHandler getPermissionsHandler()
|
||||
{
|
||||
return permissionsHandler;
|
||||
}
|
||||
|
||||
public BanWorkaround getBans()
|
||||
{
|
||||
return bans;
|
||||
}
|
||||
|
||||
public List<String> getBannedIps()
|
||||
public ItemDb getItemDb()
|
||||
{
|
||||
return bannedIps;
|
||||
return itemDb;
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,9 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
@@ -17,175 +11,25 @@ public class EssentialsBlockListener extends BlockListener
|
||||
{
|
||||
private final IEssentials ess;
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
public final static List<Material> protectedBlocks = new ArrayList<Material>(4);
|
||||
|
||||
static
|
||||
{
|
||||
protectedBlocks.add(Material.CHEST);
|
||||
protectedBlocks.add(Material.BURNING_FURNACE);
|
||||
protectedBlocks.add(Material.FURNACE);
|
||||
protectedBlocks.add(Material.DISPENSER);
|
||||
}
|
||||
|
||||
public EssentialsBlockListener(IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
if (ess.getSettings().areSignsDisabled()) return;
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
if (protectedBlocks.contains(event.getBlock().getType()) && !user.isAuthorized("essentials.signs.protection.override"))
|
||||
{
|
||||
if (isBlockProtected(event.getBlock(), user))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
user.sendMessage(Util.format("noDestroyPermission", event.getBlock().getType().toString().toLowerCase()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkProtectionSign(event.getBlock(), user) != NOSIGN &&
|
||||
checkProtectionSign(event.getBlock(), user) != OWNER)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
user.sendMessage(Util.format("noDestroyPermission", event.getBlock().getType().toString().toLowerCase()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignChange(SignChangeEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
if (ess.getSettings().areSignsDisabled()) return;
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
String username = user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
|
||||
|
||||
try
|
||||
{
|
||||
if (event.getLine(0).equalsIgnoreCase("[Protection]"))
|
||||
{
|
||||
Block block = event.getBlock();
|
||||
if (user.isAuthorized("essentials.signs.protection.create") && hasAdjacentChest(block) && !isBlockProtected(block, user))
|
||||
event.setLine(0, "§1[Protection]");
|
||||
else
|
||||
event.setLine(0, "§4[Protection]");
|
||||
event.setLine(3, username);
|
||||
return;
|
||||
}
|
||||
if (event.getLine(0).equalsIgnoreCase("[Disposal]"))
|
||||
{
|
||||
if (user.isAuthorized("essentials.signs.disposal.create"))
|
||||
event.setLine(0, "§1[Disposal]");
|
||||
else
|
||||
event.setLine(0, "§4[Disposal]");
|
||||
return;
|
||||
}
|
||||
if (event.getLine(0).equalsIgnoreCase("[Heal]"))
|
||||
{
|
||||
event.setLine(0, "§4[Heal]");
|
||||
if (user.isAuthorized("essentials.signs.heal.create"))
|
||||
{
|
||||
if (!event.getLine(1).isEmpty())
|
||||
{
|
||||
String[] l1 = event.getLine(1).split("[ :-]+", 2);
|
||||
boolean m1 = l1[0].matches("^[^0-9][\\.0-9]+");
|
||||
double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
|
||||
if (q1 < 1 || (!m1 && (int)q1 < 1)) throw new Exception(Util.i18n("moreThanZero"));
|
||||
if (!m1) ItemDb.get(l1[1]);
|
||||
event.setLine(1, (m1 ? Util.formatCurrency(q1) : (int)q1 + " " + l1[1]));
|
||||
}
|
||||
event.setLine(0, "§1[Heal]");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.getLine(0).equalsIgnoreCase("[Free]"))
|
||||
{
|
||||
event.setLine(0, "§4[Free]");
|
||||
ItemDb.get(event.getLine(1));
|
||||
if (user.isAuthorized("essentials.signs.free.create"))
|
||||
event.setLine(0, "§1[Free]");
|
||||
return;
|
||||
}
|
||||
if (event.getLine(0).equalsIgnoreCase("[Mail]"))
|
||||
{
|
||||
if (user.isAuthorized("essentials.signs.mail.create"))
|
||||
event.setLine(0, "§1[Mail]");
|
||||
else
|
||||
event.setLine(0, "§4[Mail]");
|
||||
return;
|
||||
}
|
||||
if (event.getLine(0).equalsIgnoreCase("[Balance]"))
|
||||
{
|
||||
if (user.isAuthorized("essentials.signs.balance.create"))
|
||||
event.setLine(0, "§1[Balance]");
|
||||
else
|
||||
event.setLine(0, "§4[Balance]");
|
||||
return;
|
||||
}
|
||||
if (event.getLine(0).equalsIgnoreCase("[Warp]"))
|
||||
{
|
||||
event.setLine(0, "§4[Warp]");
|
||||
if (user.isAuthorized("essentials.signs.warp.create")) {
|
||||
if (!event.getLine(3).isEmpty())
|
||||
{
|
||||
String[] l1 = event.getLine(3).split("[ :-]+", 2);
|
||||
boolean m1 = l1[0].matches("^[^0-9][\\.0-9]+");
|
||||
if (!m1 && l1.length != 2)
|
||||
{
|
||||
throw new Exception(Util.format("invalidSignLine", 4));
|
||||
}
|
||||
double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
|
||||
if ((int)q1 < 1) throw new Exception(Util.i18n("moreThanZero"));
|
||||
if (!m1) ItemDb.get(l1[1]);
|
||||
event.setLine(3, (m1 ? Util.formatCurrency(q1) : (int)q1 + " " + l1[1]));
|
||||
}
|
||||
if (event.getLine(1).isEmpty()) {
|
||||
event.setLine(1, "§dWarp name!");
|
||||
return;
|
||||
} else {
|
||||
ess.getWarps().getWarp(event.getLine(1));
|
||||
if (event.getLine(2).equalsIgnoreCase("Everyone")) {
|
||||
event.setLine(2, "§2Everyone");
|
||||
}
|
||||
event.setLine(0, "§1[Warp]");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (event.isCancelled()) return;
|
||||
Block signBlock = event.getBlockAgainst();
|
||||
if (signBlock.getType() == Material.WALL_SIGN || signBlock.getType() == Material.SIGN_POST)
|
||||
if (event.isCancelled())
|
||||
{
|
||||
Sign sign = new CraftSign(signBlock);
|
||||
if (sign.getLine(0).matches("§1\\[[a-zA-Z]+\\]"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
// Do not rely on getItemInHand();
|
||||
// http://leaky.bukkit.org/issues/663
|
||||
final ItemStack is = new ItemStack(event.getBlockPlaced().getType(), 1, (short)0, event.getBlockPlaced().getData());
|
||||
switch(is.getType()) {
|
||||
switch (is.getType())
|
||||
{
|
||||
case WOODEN_DOOR:
|
||||
is.setType(Material.WOOD_DOOR);
|
||||
is.setDurability((short)0);
|
||||
@@ -245,146 +89,21 @@ public class EssentialsBlockListener extends BlockListener
|
||||
case PISTON_BASE:
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case FIRE:
|
||||
return;
|
||||
}
|
||||
boolean unlimitedForUser = user.hasUnlimited(is);
|
||||
if (unlimitedForUser) {
|
||||
if (unlimitedForUser)
|
||||
{
|
||||
ess.scheduleSyncDelayedTask(
|
||||
new Runnable() {
|
||||
|
||||
public void run() {
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
user.getInventory().addItem(is);
|
||||
user.updateInventory();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasAdjacentChest(Block block)
|
||||
{
|
||||
Block[] faces = getAdjacentBlocks(block);
|
||||
for (Block b : faces)
|
||||
{
|
||||
if (protectedBlocks.contains(b.getType()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static final int NOT_ALLOWED = 0;
|
||||
private static final int ALLOWED = 1;
|
||||
private static final int NOSIGN = 2;
|
||||
private static final int OWNER = 3;
|
||||
|
||||
private int checkProtectionSign(Block block, User user)
|
||||
{
|
||||
String username = user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
|
||||
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
|
||||
{
|
||||
Sign sign = new CraftSign(block);
|
||||
if (sign.getLine(0).equalsIgnoreCase("§1[Protection]") && !user.isAuthorized("essentials.signs.protection.override"))
|
||||
{
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
String line = sign.getLine(i);
|
||||
if (line.startsWith("(") && line.endsWith(")")) {
|
||||
line = line.substring(1, line.length() - 1);
|
||||
if (user.inGroup(line)) {
|
||||
return ALLOWED;
|
||||
}
|
||||
} else if (line.equalsIgnoreCase(username)) {
|
||||
return ALLOWED;
|
||||
}
|
||||
}
|
||||
if (sign.getLine(3).equalsIgnoreCase(username))
|
||||
{
|
||||
return OWNER;
|
||||
}
|
||||
return NOT_ALLOWED;
|
||||
}
|
||||
}
|
||||
return NOSIGN;
|
||||
}
|
||||
|
||||
private static Block[] getAdjacentBlocks(Block block)
|
||||
{
|
||||
return new Block[]
|
||||
{
|
||||
block.getFace(BlockFace.NORTH),
|
||||
block.getFace(BlockFace.SOUTH),
|
||||
block.getFace(BlockFace.EAST),
|
||||
block.getFace(BlockFace.WEST),
|
||||
block.getFace(BlockFace.DOWN),
|
||||
block.getFace(BlockFace.UP)
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isBlockProtected(Block block, User user)
|
||||
{
|
||||
Block[] faces = getAdjacentBlocks(block);
|
||||
boolean protect = false;
|
||||
for (Block b : faces)
|
||||
{
|
||||
int check = checkProtectionSign(b, user);
|
||||
if (check == NOT_ALLOWED)
|
||||
{
|
||||
protect = true;
|
||||
}
|
||||
if (check == ALLOWED || check == OWNER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (protectedBlocks.contains(b.getType()))
|
||||
{
|
||||
Block[] faceChest = getAdjacentBlocks(b);
|
||||
|
||||
for (Block a : faceChest)
|
||||
{
|
||||
check = checkProtectionSign(a, user);
|
||||
if (check == NOT_ALLOWED)
|
||||
{
|
||||
protect = true;
|
||||
}
|
||||
if (check == ALLOWED || check == OWNER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return protect;
|
||||
}
|
||||
|
||||
public static boolean isBlockProtected(Block block)
|
||||
{
|
||||
Block[] faces = getAdjacentBlocks(block);
|
||||
for (Block b : faces)
|
||||
{
|
||||
if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN)
|
||||
{
|
||||
Sign sign = new CraftSign(b);
|
||||
if (sign.getLine(0).equalsIgnoreCase("§1[Protection]"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (protectedBlocks.contains(b.getType()))
|
||||
{
|
||||
Block[] faceChest = getAdjacentBlocks(b);
|
||||
|
||||
for (Block a : faceChest)
|
||||
{
|
||||
if (a.getType() == Material.SIGN_POST || a.getType() == Material.WALL_SIGN)
|
||||
{
|
||||
Sign sign = new CraftSign(a);
|
||||
if (sign.getLine(0).equalsIgnoreCase("§1[Protection]"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,250 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class EssentialsEcoBlockListener extends BlockListener
|
||||
{
|
||||
private final IEssentials ess;
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
public EssentialsEcoBlockListener(Essentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
String username = user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length());
|
||||
if (event.getBlock().getType() != Material.WALL_SIGN && event.getBlock().getType() != Material.SIGN_POST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Sign sign = new CraftSign(event.getBlock());
|
||||
|
||||
if (sign.getLine(0).equals("§1[Trade]"))
|
||||
{
|
||||
if (!sign.getLine(3).substring(2).equals(username))
|
||||
{
|
||||
if (!user.isOp())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
String[] l1 = sign.getLines()[1].split("[ :-]+");
|
||||
String[] l2 = sign.getLines()[2].split("[ :-]+");
|
||||
boolean m1 = l1[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
|
||||
boolean m2 = l2[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
|
||||
double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
|
||||
double q2 = Double.parseDouble(m2 ? l2[0].substring(1) : l2[0]);
|
||||
double r1 = Double.parseDouble(l1[m1 ? 1 : 2]);
|
||||
double r2 = Double.parseDouble(l2[m2 ? 1 : 2]);
|
||||
if ((!m1 & q1 < 1) || (!m2 & q2 < 1))
|
||||
{
|
||||
throw new Exception(Util.i18n("moreThanZero"));
|
||||
}
|
||||
|
||||
ItemStack i1 = m1 || r1 <= 0 ? null : ItemDb.get(l1[1], (int)r1);
|
||||
ItemStack i2 = m2 || r2 <= 0 ? null : ItemDb.get(l2[1], (int)r2);
|
||||
|
||||
if (m1)
|
||||
{
|
||||
user.giveMoney(r1);
|
||||
}
|
||||
else if (i1 != null)
|
||||
{
|
||||
Map<Integer, ItemStack> leftOver = user.getInventory().addItem(i1);
|
||||
for (ItemStack itemStack : leftOver.values())
|
||||
{
|
||||
InventoryWorkaround.dropItem(user.getLocation(), itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
if (m2)
|
||||
{
|
||||
user.giveMoney(r2);
|
||||
}
|
||||
else if (i2 != null)
|
||||
{
|
||||
Map<Integer, ItemStack> leftOver = user.getInventory().addItem(i2);
|
||||
for (ItemStack itemStack : leftOver.values())
|
||||
{
|
||||
InventoryWorkaround.dropItem(user.getLocation(), itemStack);
|
||||
}
|
||||
}
|
||||
user.updateInventory();
|
||||
|
||||
sign.setType(Material.AIR);
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignChange(SignChangeEvent event)
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
String username = user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length());
|
||||
|
||||
if ((event.getLine(0).equalsIgnoreCase("[Buy]") || event.getLine(0).equalsIgnoreCase("#1[Buy]")) && user.isAuthorized("essentials.signs.buy.create"))
|
||||
{
|
||||
try
|
||||
{
|
||||
event.setLine(0, "§1[Buy]");
|
||||
event.setLine(1, "" + Math.abs(Integer.parseInt(event.getLine(1))));
|
||||
ItemStack is = ItemDb.get(event.getLine(2));
|
||||
if (is.getTypeId() == 0 || Math.abs(Integer.parseInt(event.getLine(1))) == 0)
|
||||
{
|
||||
throw new Exception("Don't sell air.");
|
||||
}
|
||||
double price = Double.parseDouble(event.getLine(3).replaceAll("[^0-9\\.]", ""));
|
||||
event.setLine(3, Util.formatCurrency(price));
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
event.setLine(0, "§4[Buy]");
|
||||
event.setLine(1, "#");
|
||||
event.setLine(2, "Item");
|
||||
event.setLine(3, "$Price");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.getLine(0).equalsIgnoreCase("[Sell]") || event.getLine(0).equalsIgnoreCase("#1[Sell]")) && user.isAuthorized("essentials.signs.sell.create"))
|
||||
{
|
||||
try
|
||||
{
|
||||
event.setLine(0, "§1[Sell]");
|
||||
event.setLine(1, "" + Math.abs(Integer.parseInt(event.getLine(1))));
|
||||
ItemStack is = ItemDb.get(event.getLine(2));
|
||||
if (is.getTypeId() == 0 || Math.abs(Integer.parseInt(event.getLine(1))) == 0)
|
||||
{
|
||||
throw new Exception("Can't buy air.");
|
||||
}
|
||||
double price = Double.parseDouble(event.getLine(3).replaceAll("[^0-9\\.]", ""));
|
||||
event.setLine(3, Util.formatCurrency(price));
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
event.setLine(0, "§4[Sell]");
|
||||
event.setLine(1, "#");
|
||||
event.setLine(2, "Item");
|
||||
event.setLine(3, "$Price");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.getLine(0).equalsIgnoreCase("[Trade]") || event.getLine(0).equalsIgnoreCase("#1[Trade]")) && user.isAuthorized("essentials.signs.trade.create"))
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] l1 = event.getLine(1).split("[ :-]+");
|
||||
String[] l2 = event.getLine(2).split("[ :-]+");
|
||||
boolean m1 = l1[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
|
||||
boolean m2 = l2[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
|
||||
double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
|
||||
double q2 = Double.parseDouble(m2 ? l2[0].substring(1) : l2[0]);
|
||||
if (m1 ? l1.length != 1 : l1.length != 2)
|
||||
{
|
||||
throw new Exception(Util.format("invalidSignLine", 2));
|
||||
}
|
||||
if (m2 ? l2.length != 2 : l2.length != 3)
|
||||
{
|
||||
throw new Exception(Util.format("invalidSignLine", 3));
|
||||
}
|
||||
double r2 = Double.parseDouble(l2[m2 ? 1 : 2]);
|
||||
r2 = m2 ? r2 : r2 - r2 % q2;
|
||||
if ((!m1 & q1 < 1) || (!m2 & q2 < 1) || r2 < 1)
|
||||
{
|
||||
throw new Exception(Util.i18n("moreThanZero"));
|
||||
}
|
||||
if (!m1)
|
||||
{
|
||||
ItemDb.get(l1[1]);
|
||||
}
|
||||
|
||||
if (m2)
|
||||
{
|
||||
if (user.getMoney() < r2)
|
||||
{
|
||||
throw new Exception(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
user.takeMoney(r2);
|
||||
//user.sendMessage("r2: " + r2 + " q2: " + q2);
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack i2 = ItemDb.get(l2[1], (int)r2);
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, i2))
|
||||
{
|
||||
throw new Exception(Util.format("missingItems", (int)r2, l2[1]));
|
||||
}
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, i2);
|
||||
user.updateInventory();
|
||||
}
|
||||
|
||||
event.setLine(0, "§1[Trade]");
|
||||
event.setLine(1, (m1 ? Util.formatCurrency(q1) : (int)q1 + " " + l1[1]) + ":0");
|
||||
event.setLine(2, (m2 ? Util.formatCurrency(q2) : (int)q2 + " " + l2[1]) + ":" + (m2 ? Util.roundDouble(r2) : "" + (int)r2));
|
||||
event.setLine(3, "§8" + username);
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
event.setLine(0, "§4[Trade]");
|
||||
event.setLine(1, "# ItemOr" + ess.getSettings().getCurrencySymbol());
|
||||
event.setLine(2, "# ItemOr" + ess.getSettings().getCurrencySymbol() + ":#");
|
||||
event.setLine(3, "§8" + username);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,211 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class EssentialsEcoPlayerListener extends PlayerListener
|
||||
{
|
||||
private final IEssentials ess;
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
EssentialsEcoPlayerListener(IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
String username = user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length());
|
||||
if (event.getClickedBlock().getType() != Material.WALL_SIGN && event.getClickedBlock().getType() != Material.SIGN_POST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Sign sign = new CraftSign(event.getClickedBlock());
|
||||
|
||||
if (sign.getLine(0).equals("§1[Buy]") && user.isAuthorized("essentials.signs.buy.use"))
|
||||
{
|
||||
try
|
||||
{
|
||||
int amount = Integer.parseInt(sign.getLine(1));
|
||||
ItemStack item = ItemDb.get(sign.getLine(2), amount);
|
||||
double cost = Double.parseDouble(sign.getLine(3).substring(1));
|
||||
if (user.getMoney() < cost)
|
||||
{
|
||||
throw new Exception(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
user.takeMoney(cost);
|
||||
Map<Integer, ItemStack> leftOver = user.getInventory().addItem(item);
|
||||
for (ItemStack itemStack : leftOver.values())
|
||||
{
|
||||
InventoryWorkaround.dropItem(user.getLocation(), itemStack);
|
||||
}
|
||||
user.updateInventory();
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (sign.getLine(0).equals("§1[Sell]") && user.isAuthorized("essentials.signs.sell.use"))
|
||||
{
|
||||
try
|
||||
{
|
||||
int amount = Integer.parseInt(sign.getLine(1));
|
||||
ItemStack item = ItemDb.get(sign.getLine(2), amount);
|
||||
double cost = Double.parseDouble(sign.getLine(3).substring(1));
|
||||
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, item))
|
||||
{
|
||||
throw new Exception(Util.format("missingItems", amount, sign.getLine(2)));
|
||||
}
|
||||
user.giveMoney(cost);
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, item);
|
||||
user.updateInventory();
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (sign.getLine(0).equals("§1[Trade]") && user.isAuthorized("essentials.signs.trade.use"))
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] l1 = sign.getLine(1).split("[ :-]+");
|
||||
String[] l2 = sign.getLine(2).split("[ :-]+");
|
||||
boolean m1 = l1[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
|
||||
boolean m2 = l2[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
|
||||
double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
|
||||
double q2 = Double.parseDouble(m2 ? l2[0].substring(1) : l2[0]);
|
||||
double r1 = Double.parseDouble(l1[m1 ? 1 : 2]);
|
||||
double r2 = Double.parseDouble(l2[m2 ? 1 : 2]);
|
||||
r1 = m1 ? r1 : r1 - r1 % q1;
|
||||
r2 = m2 ? r2 : r2 - r2 % q2;
|
||||
if ((!m1 & q1 < 1) || (!m2 & q2 < 1))
|
||||
{
|
||||
throw new Exception(Util.i18n("moreThanZero"));
|
||||
}
|
||||
|
||||
ItemStack i1 = m1 || r1 <= 0 ? null : ItemDb.get(l1[1], (int)r1);
|
||||
ItemStack qi1 = m1 ? null : ItemDb.get(l1[1], (int)q1);
|
||||
ItemStack qi2 = m2 ? null : ItemDb.get(l2[1], (int)q2);
|
||||
|
||||
if (username.equals(sign.getLine(3).substring(2)))
|
||||
{
|
||||
if (m1)
|
||||
{
|
||||
user.giveMoney(r1);
|
||||
}
|
||||
else if (i1 != null)
|
||||
{
|
||||
Map<Integer, ItemStack> leftOver = user.getInventory().addItem(i1);
|
||||
for (ItemStack itemStack : leftOver.values())
|
||||
{
|
||||
InventoryWorkaround.dropItem(user.getLocation(), itemStack);
|
||||
}
|
||||
user.updateInventory();
|
||||
}
|
||||
r1 = 0;
|
||||
sign.setLine(1, (m1 ? Util.formatCurrency(q1) : ((int)q1) + " " + l1[1]) + ":0");
|
||||
sign.update();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m1)
|
||||
{
|
||||
if (user.getMoney() < q1)
|
||||
{
|
||||
throw new Exception(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, qi1))
|
||||
{
|
||||
throw new Exception(Util.format("missingItems", (int)q1, l1[1]));
|
||||
}
|
||||
}
|
||||
|
||||
if (r2 < q2)
|
||||
{
|
||||
throw new Exception(Util.i18n("tradeSignEmpty"));
|
||||
}
|
||||
|
||||
if (m1)
|
||||
{
|
||||
user.takeMoney(q1);
|
||||
}
|
||||
else
|
||||
{
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, qi1);
|
||||
}
|
||||
|
||||
if (m2)
|
||||
{
|
||||
user.giveMoney(q2);
|
||||
}
|
||||
else
|
||||
{
|
||||
Map<Integer, ItemStack> leftOver = user.getInventory().addItem(qi2);
|
||||
for (ItemStack itemStack : leftOver.values())
|
||||
{
|
||||
InventoryWorkaround.dropItem(user.getLocation(), itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
user.updateInventory();
|
||||
|
||||
r1 += q1;
|
||||
r2 -= q2;
|
||||
|
||||
|
||||
sign.setLine(0, "§1[Trade]");
|
||||
sign.setLine(1, (m1 ? Util.formatCurrency(q1) : ((int)q1) + " " + l1[1]) + ":" + (m1 ? Util.roundDouble(r1) : "" + (int)r1));
|
||||
sign.setLine(2, (m2 ? Util.formatCurrency(q2) : ((int)q2) + " " + l2[1]) + ":" + (m2 ? Util.roundDouble(r2) : "" + (int)r2));
|
||||
sign.update();
|
||||
user.sendMessage(Util.i18n("tradeCompleted"));
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,21 +4,18 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.InventoryPlayer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationType;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerEggThrowEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
@@ -34,57 +31,59 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EssentialsPlayerListener extends PlayerListener
|
||||
{
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
private final Server server;
|
||||
private final IEssentials ess;
|
||||
private final EssentialsBlockListener essBlockListener;
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient Server server;
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public EssentialsPlayerListener(IEssentials parent)
|
||||
public EssentialsPlayerListener(final IEssentials parent)
|
||||
{
|
||||
this.ess = parent;
|
||||
this.server = parent.getServer();
|
||||
essBlockListener = new EssentialsBlockListener(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event)
|
||||
public void onPlayerRespawn(final PlayerRespawnEvent event)
|
||||
{
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
user.setDisplayName(user.getNick());
|
||||
updateCompass(user);
|
||||
if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty()) {
|
||||
try
|
||||
if (ess.getSettings().changeDisplayName())
|
||||
{
|
||||
event.setRespawnLocation(ess.getJail().getJail(user.getJail()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
user.setDisplayName(user.getNick());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event)
|
||||
public void onPlayerChat(final PlayerChatEvent event)
|
||||
{
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (user.isMuted())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
logger.info(Util.format("mutedUserSpeaks", user.getName()));
|
||||
LOGGER.info(Util.format("mutedUserSpeaks", user.getName()));
|
||||
}
|
||||
Iterator<Player> it = event.getRecipients().iterator();
|
||||
final Iterator<Player> it = event.getRecipients().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
User u = ess.getUser(it.next());
|
||||
final User u = ess.getUser(it.next());
|
||||
if (u.isIgnoredPlayer(user.getName()))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
if (user.isAfk())
|
||||
{
|
||||
user.setAfk(false);
|
||||
ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName()));
|
||||
}
|
||||
if (ess.getSettings().changeDisplayName())
|
||||
{
|
||||
user.setDisplayName(user.getNick());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
public void onPlayerMove(final PlayerMoveEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
@@ -92,13 +91,19 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
if (user.isAfk())
|
||||
{
|
||||
user.setAfk(false);
|
||||
ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName()));
|
||||
}
|
||||
|
||||
if (!ess.getSettings().getNetherPortalsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Block block = event.getPlayer().getWorld().getBlockAt(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
|
||||
List<World> worlds = server.getWorlds();
|
||||
final List<World> worlds = server.getWorlds();
|
||||
|
||||
if (block.getType() == Material.PORTAL && worlds.size() > 1 && user.isAuthorized("essentials.portal"))
|
||||
{
|
||||
@@ -107,17 +112,19 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
return;
|
||||
}
|
||||
|
||||
Location loc = event.getTo();
|
||||
World nether = server.getWorld(ess.getSettings().getNetherName());
|
||||
if (nether == null) {
|
||||
if (nether == null)
|
||||
{
|
||||
for (World world : worlds)
|
||||
{
|
||||
if (world.getEnvironment() == World.Environment.NETHER) {
|
||||
if (world.getEnvironment() == World.Environment.NETHER)
|
||||
{
|
||||
nether = world;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nether == null) {
|
||||
if (nether == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -128,7 +135,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
{
|
||||
factor = ess.getSettings().getNetherRatio();
|
||||
}
|
||||
else if (user.getWorld().getEnvironment() != world.getEnvironment())
|
||||
else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER)
|
||||
{
|
||||
factor = 1.0 / ess.getSettings().getNetherRatio();
|
||||
}
|
||||
@@ -137,6 +144,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
factor = 1.0;
|
||||
}
|
||||
|
||||
Location loc = event.getTo();
|
||||
int x = loc.getBlockX();
|
||||
int y = loc.getBlockY();
|
||||
int z = loc.getBlockZ();
|
||||
@@ -161,14 +169,14 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
if (world.getEnvironment() == World.Environment.NETHER || ess.getSettings().getGenerateExitPortals())
|
||||
{
|
||||
portal = NetherPortal.createPortal(dest);
|
||||
logger.info(Util.format("userCreatedPortal", event.getPlayer().getName()));
|
||||
LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName()));
|
||||
user.sendMessage(Util.i18n("generatingPortal"));
|
||||
loc = portal.getSpawn();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info(Util.format("userUsedPortal", event.getPlayer().getName()));
|
||||
LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName()));
|
||||
user.sendMessage(Util.i18n("usingPortal"));
|
||||
loc = portal.getSpawn();
|
||||
}
|
||||
@@ -177,7 +185,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
event.setTo(loc);
|
||||
try
|
||||
{
|
||||
user.getTeleport().now(loc, new Charge("portal", ess));
|
||||
user.getTeleport().now(loc, new Trade("portal", ess));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -194,10 +202,13 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
public void onPlayerQuit(final PlayerQuitEvent event)
|
||||
{
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled())
|
||||
{
|
||||
user.toggleGodModeEnabled();
|
||||
}
|
||||
if (user.getSavedInventory() != null)
|
||||
{
|
||||
user.getInventory().setContents(user.getSavedInventory());
|
||||
@@ -208,7 +219,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
return;
|
||||
}
|
||||
user.dispose();
|
||||
Thread thread = new Thread(new Runnable()
|
||||
final Thread thread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
@@ -221,7 +232,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
rt.gc();
|
||||
mem = rt.freeMemory() - mem;
|
||||
mem /= 1024 * 1024;
|
||||
logger.log(Level.INFO, Util.format("freedMemory", mem));
|
||||
LOGGER.log(Level.INFO, Util.format("freedMemory", mem));
|
||||
}
|
||||
catch (InterruptedException ex)
|
||||
{
|
||||
@@ -234,20 +245,28 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event)
|
||||
{
|
||||
ess.getBackup().onPlayerJoin();
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
//we do not know the ip address on playerlogin so we need to do this here.
|
||||
if (user.isIpBanned())
|
||||
{
|
||||
String banReason = user.getBanReason();
|
||||
final String banReason = user.getBanReason();
|
||||
user.kickPlayer(banReason != null && !banReason.isEmpty() ? banReason : Util.i18n("defaultBanReason"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ess.getSettings().changeDisplayName())
|
||||
{
|
||||
user.setDisplayName(user.getNick());
|
||||
}
|
||||
user.setAfk(false);
|
||||
if (user.isAuthorized("essentials.sleepingignored"))
|
||||
{
|
||||
user.setSleepingIgnored(true);
|
||||
}
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
|
||||
{
|
||||
@@ -263,7 +282,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
|
||||
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
|
||||
{
|
||||
List<String> mail = user.getMails();
|
||||
final List<String> mail = user.getMails();
|
||||
if (mail.isEmpty())
|
||||
{
|
||||
user.sendMessage(Util.i18n("noNewMail"));
|
||||
@@ -276,18 +295,18 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerLogin(PlayerLoginEvent event)
|
||||
public void onPlayerLogin(final PlayerLoginEvent event)
|
||||
{
|
||||
if (event.getResult() != Result.ALLOWED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
user.setNPC(false);
|
||||
|
||||
if (user.isBanned())
|
||||
{
|
||||
String banReason = user.getBanReason();
|
||||
final String banReason = user.getBanReason();
|
||||
event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() ? banReason : Util.i18n("defaultBanReason"));
|
||||
return;
|
||||
}
|
||||
@@ -302,7 +321,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
updateCompass(user);
|
||||
}
|
||||
|
||||
private void updateCompass(User user)
|
||||
private void updateCompass(final User user)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -320,24 +339,16 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty())
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (ess.getSettings().changeDisplayName())
|
||||
{
|
||||
return;
|
||||
user.setDisplayName(user.getNick());
|
||||
}
|
||||
try
|
||||
{
|
||||
event.setTo(ess.getJail().getJail(user.getJail()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.log(Level.WARNING, Util.i18n("returnPlayerToJailError"), ex);
|
||||
}
|
||||
user.sendMessage(Util.i18n("jailMessage"));
|
||||
updateCompass(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
@@ -347,29 +358,12 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
if (user.isJailed())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!ess.getSettings().areSignsDisabled() && EssentialsBlockListener.protectedBlocks.contains(event.getClickedBlock().getType()))
|
||||
{
|
||||
if (!user.isAuthorized("essentials.signs.protection.override"))
|
||||
{
|
||||
if (essBlockListener.isBlockProtected(event.getClickedBlock(), user))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
user.sendMessage(Util.format("noAccessPermission", event.getClickedBlock().getType().toString().toLowerCase()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ess.getSettings().getBedSetsHome() && event.getClickedBlock().getType() == Material.BED_BLOCK)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
user.setHome();
|
||||
user.sendMessage(Util.i18n("homeSetToBed"));
|
||||
}
|
||||
@@ -377,158 +371,13 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getClickedBlock().getType() != Material.WALL_SIGN && event.getClickedBlock().getType() != Material.SIGN_POST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Sign sign = new CraftSign(event.getClickedBlock());
|
||||
|
||||
try
|
||||
{
|
||||
if (sign.getLine(0).equals("§1[Free]") && user.isAuthorized("essentials.signs.free.use"))
|
||||
{
|
||||
ItemStack item = ItemDb.get(sign.getLine(1));
|
||||
CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(user.getHandle()));
|
||||
inv.clear();
|
||||
item.setAmount(9 * 4 * 64);
|
||||
inv.addItem(item);
|
||||
user.showInventory(inv);
|
||||
return;
|
||||
}
|
||||
if (sign.getLine(0).equals("§1[Disposal]") && user.isAuthorized("essentials.signs.disposal.use"))
|
||||
{
|
||||
CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(user.getHandle()));
|
||||
inv.clear();
|
||||
user.showInventory(inv);
|
||||
return;
|
||||
}
|
||||
if (sign.getLine(0).equals("§1[Heal]") && user.isAuthorized("essentials.signs.heal.use"))
|
||||
{
|
||||
if (!sign.getLine(1).isEmpty())
|
||||
{
|
||||
String[] l1 = sign.getLine(1).split("[ :-]+");
|
||||
boolean m1 = l1[0].matches("^[^0-9][\\.0-9]+");
|
||||
double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
|
||||
if (!m1 && (int)q1 < 1)
|
||||
{
|
||||
throw new Exception(Util.i18n("moreThanZero"));
|
||||
}
|
||||
if (m1)
|
||||
{
|
||||
if (user.getMoney() < q1)
|
||||
{
|
||||
throw new Exception(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
user.takeMoney(q1);
|
||||
user.sendMessage(Util.format("moneyTaken", Util.formatCurrency(q1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack i = ItemDb.get(l1[1], (int)q1);
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, i))
|
||||
{
|
||||
throw new Exception(Util.format("missingItems", (int)q1, l1[1]));
|
||||
}
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, i);
|
||||
user.updateInventory();
|
||||
}
|
||||
}
|
||||
user.setHealth(20);
|
||||
user.sendMessage(Util.i18n("youAreHealed"));
|
||||
return;
|
||||
}
|
||||
if (sign.getLine(0).equals("§1[Mail]") && user.isAuthorized("essentials.signs.mail.use") && user.isAuthorized("essentials.mail"))
|
||||
{
|
||||
List<String> mail = user.getMails();
|
||||
if (mail.isEmpty())
|
||||
{
|
||||
user.sendMessage(Util.i18n("noNewMail"));
|
||||
return;
|
||||
}
|
||||
for (String s : mail)
|
||||
{
|
||||
user.sendMessage(s);
|
||||
}
|
||||
user.sendMessage(Util.i18n("markMailAsRead"));
|
||||
return;
|
||||
}
|
||||
if (sign.getLine(0).equals("§1[Balance]") && user.isAuthorized("essentials.signs.balance.use"))
|
||||
{
|
||||
user.sendMessage(Util.format("balance", user.getMoney()));
|
||||
return;
|
||||
}
|
||||
if (sign.getLine(0).equals("§1[Warp]"))
|
||||
{
|
||||
|
||||
if (!sign.getLine(2).isEmpty())
|
||||
{
|
||||
if (sign.getLine(2).equals("§2Everyone"))
|
||||
{
|
||||
Charge charge = chargeUserForWarp(sign, user);
|
||||
user.getTeleport().warp(sign.getLine(1), charge);
|
||||
return;
|
||||
}
|
||||
if (user.inGroup(sign.getLine(2)))
|
||||
{
|
||||
Charge charge = chargeUserForWarp(sign, user);
|
||||
user.getTeleport().warp(sign.getLine(1), charge);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (user.isAuthorized("essentials.signs.warp.use")
|
||||
&& (!ess.getSettings().getPerWarpPermission() || user.isAuthorized("essentials.warp." + sign.getLine(1))))
|
||||
{
|
||||
Charge charge = chargeUserForWarp(sign, user);
|
||||
user.getTeleport().warp(sign.getLine(1), charge);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Charge chargeUserForWarp(Sign sign, User user) throws Exception
|
||||
{
|
||||
if (!sign.getLine(3).isEmpty())
|
||||
{
|
||||
String[] l1 = sign.getLine(3).split("[ :-]+");
|
||||
boolean m1 = l1[0].matches("^[^0-9][\\.0-9]+");
|
||||
double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
|
||||
if (!m1 && (int)q1 < 1)
|
||||
{
|
||||
throw new Exception(Util.i18n("moreThanZero"));
|
||||
}
|
||||
if (m1)
|
||||
{
|
||||
return new Charge(q1, ess);
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack i = ItemDb.get(l1[1], (int)q1);
|
||||
return new Charge(i, ess);
|
||||
}
|
||||
}
|
||||
return new Charge("warpsign", ess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerEggThrow(PlayerEggThrowEvent event)
|
||||
public void onPlayerEggThrow(final PlayerEggThrowEvent event)
|
||||
{
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
ItemStack is = new ItemStack(Material.EGG, 1);
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack is = new ItemStack(Material.EGG, 1);
|
||||
if (user.hasUnlimited(is))
|
||||
{
|
||||
user.getInventory().addItem(is);
|
||||
@@ -537,7 +386,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event)
|
||||
public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (user.hasUnlimited(new ItemStack(event.getBucket())))
|
||||
@@ -554,24 +403,24 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event)
|
||||
public void onPlayerAnimation(final PlayerAnimationEvent event)
|
||||
{
|
||||
usePowertools(event);
|
||||
}
|
||||
|
||||
private void usePowertools(PlayerAnimationEvent event)
|
||||
private void usePowertools(final PlayerAnimationEvent event)
|
||||
{
|
||||
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
ItemStack is = user.getItemInHand();
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack is = user.getItemInHand();
|
||||
if (is == null || is.getType() == Material.AIR)
|
||||
{
|
||||
return;
|
||||
}
|
||||
String command = user.getPowertool(is);
|
||||
final String command = user.getPowertool(is);
|
||||
if (command == null || command.isEmpty())
|
||||
{
|
||||
return;
|
||||
@@ -593,4 +442,30 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
user.getServer().dispatchCommand(user, command);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final String cmd = event.getMessage().toLowerCase().split(" ")[0].replace("/", "").toLowerCase();
|
||||
if (("msg".equals(cmd) || "r".equals(cmd) || "mail".equals(cmd)))
|
||||
{
|
||||
for (Player player : ess.getServer().getOnlinePlayers())
|
||||
{
|
||||
if (ess.getUser(player).isSocialSpyEnabled())
|
||||
{
|
||||
player.sendMessage(user.getDisplayName() + " : " + event.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (user.isAfk())
|
||||
{
|
||||
user.setAfk(false);
|
||||
ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package com.earth2me.essentials;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
@@ -25,7 +24,7 @@ public class EssentialsTimer implements Runnable, IConf
|
||||
continue;
|
||||
}
|
||||
String name = string.substring(0, string.length()-4);
|
||||
User u = ess.getUser(new OfflinePlayer(name));
|
||||
User u = ess.getUser(new OfflinePlayer(name, ess));
|
||||
allUsers.add(u);
|
||||
}
|
||||
}
|
||||
@@ -43,8 +42,7 @@ public class EssentialsTimer implements Runnable, IConf
|
||||
for (User user: allUsers) {
|
||||
if (user.getBanTimeout() > 0 && user.getBanTimeout() < currentTime) {
|
||||
user.setBanTimeout(0);
|
||||
((CraftServer)ess.getServer()).getHandle().b(user.getName());
|
||||
ess.loadBanList();
|
||||
ess.getBans().unbanByName(user.getName());
|
||||
}
|
||||
if (user.getMuteTimeout() > 0 && user.getMuteTimeout() < currentTime && user.isMuted()) {
|
||||
user.setMuteTimeout(0);
|
||||
|
@@ -192,7 +192,7 @@ public class EssentialsUpgrade
|
||||
usersConfig.load();
|
||||
for (String username : usersConfig.getKeys(null))
|
||||
{
|
||||
User user = new User(new OfflinePlayer(username), ess);
|
||||
User user = new User(new OfflinePlayer(username, ess), ess);
|
||||
String nickname = usersConfig.getString(username + ".nickname");
|
||||
if (nickname != null && !nickname.isEmpty() && !nickname.equals(username))
|
||||
{
|
||||
|
@@ -392,4 +392,9 @@ public class FakeWorld implements World
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
public long getUID()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,22 +1,21 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.register.payment.Methods;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import org.bukkit.Server;
|
||||
import java.util.Map;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public interface IEssentials
|
||||
|
||||
public interface IEssentials extends Plugin
|
||||
{
|
||||
void addReloadListener(IConf listener);
|
||||
|
||||
void reload();
|
||||
|
||||
boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath);
|
||||
boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix);
|
||||
|
||||
User getUser(Object base);
|
||||
|
||||
@@ -26,7 +25,7 @@ public interface IEssentials
|
||||
|
||||
int broadcastMessage(String name, String message);
|
||||
|
||||
Settings getSettings();
|
||||
ISettings getSettings();
|
||||
|
||||
CraftScheduler getScheduler();
|
||||
|
||||
@@ -44,25 +43,25 @@ public interface IEssentials
|
||||
|
||||
Spawn getSpawn();
|
||||
|
||||
void loadBanList();
|
||||
|
||||
public boolean isRegisterFallbackEnabled();
|
||||
|
||||
public Methods getPaymentMethod();
|
||||
|
||||
Server getServer();
|
||||
|
||||
File getDataFolder();
|
||||
|
||||
PluginDescriptionFile getDescription();
|
||||
Methods getPaymentMethod();
|
||||
|
||||
int scheduleAsyncDelayedTask(Runnable run);
|
||||
|
||||
int scheduleSyncDelayedTask(Runnable run);
|
||||
|
||||
int scheduleSyncDelayedTask(Runnable run, long delay);
|
||||
|
||||
int scheduleSyncRepeatingTask(final Runnable run, long delay, long period);
|
||||
|
||||
List<String> getBans();
|
||||
BanWorkaround getBans();
|
||||
|
||||
List<String> getBannedIps();
|
||||
TNTExplodeListener getTNTListener();
|
||||
|
||||
IPermissionsHandler getPermissionsHandler();
|
||||
|
||||
void showError(final CommandSender sender, final Throwable exception, final String commandLabel);
|
||||
|
||||
Map<String, User> getAllUsers();
|
||||
|
||||
ItemDb getItemDb();
|
||||
}
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public interface IPermissionsHandler
|
||||
{
|
||||
|
||||
String getGroup(Player base);
|
||||
|
||||
boolean canBuild(Player base, String group);
|
||||
|
||||
boolean inGroup(Player base, String group);
|
||||
|
||||
boolean hasPermission(Player base, String node);
|
||||
|
||||
String getPrefix(Player base);
|
||||
|
||||
String getSuffix(Player base);
|
||||
|
||||
}
|
131
Essentials/src/com/earth2me/essentials/ISettings.java
Normal file
131
Essentials/src/com/earth2me/essentials/ISettings.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
||||
public interface ISettings extends IConf
|
||||
{
|
||||
|
||||
boolean areSignsDisabled();
|
||||
|
||||
String format(String format, IUser user);
|
||||
|
||||
String getAnnounceNewPlayerFormat(IUser user);
|
||||
|
||||
boolean getAnnounceNewPlayers();
|
||||
|
||||
String getBackupCommand();
|
||||
|
||||
long getBackupInterval();
|
||||
|
||||
boolean getBedSetsHome();
|
||||
|
||||
String getChatFormat(String group);
|
||||
|
||||
int getChatRadius();
|
||||
|
||||
double getCommandCost(IEssentialsCommand cmd);
|
||||
|
||||
double getCommandCost(String label);
|
||||
|
||||
String getCurrencySymbol();
|
||||
|
||||
int getDefaultStackSize();
|
||||
|
||||
boolean getGenerateExitPortals();
|
||||
|
||||
double getHealCooldown();
|
||||
|
||||
Object getKit(String name);
|
||||
|
||||
Map<String, Object> getKits();
|
||||
|
||||
String getLocale();
|
||||
|
||||
String getNetherName();
|
||||
|
||||
boolean getNetherPortalsEnabled();
|
||||
|
||||
double getNetherRatio();
|
||||
|
||||
String getNewbieSpawn();
|
||||
|
||||
String getNicknamePrefix();
|
||||
|
||||
ChatColor getOperatorColor() throws Exception;
|
||||
|
||||
boolean getPerWarpPermission();
|
||||
|
||||
boolean getProtectBoolean(final String configName, boolean def);
|
||||
|
||||
int getProtectCreeperMaxHeight();
|
||||
|
||||
List<Integer> getProtectList(final String configName);
|
||||
|
||||
boolean getProtectPreventSpawn(final String creatureName);
|
||||
|
||||
String getProtectString(final String configName);
|
||||
|
||||
boolean getReclaimSetting();
|
||||
|
||||
boolean getRespawnAtHome();
|
||||
|
||||
boolean getSortListByGroups();
|
||||
|
||||
int getSpawnMobLimit();
|
||||
|
||||
int getStartingBalance();
|
||||
|
||||
double getTeleportCooldown();
|
||||
|
||||
double getTeleportDelay();
|
||||
|
||||
boolean hidePermissionlessHelp();
|
||||
|
||||
boolean isCommandDisabled(final IEssentialsCommand cmd);
|
||||
|
||||
boolean isCommandDisabled(String label);
|
||||
|
||||
boolean isCommandOverridden(String name);
|
||||
|
||||
boolean isCommandRestricted(IEssentialsCommand cmd);
|
||||
|
||||
boolean isCommandRestricted(String label);
|
||||
|
||||
boolean isDebug();
|
||||
|
||||
boolean isEcoDisabled();
|
||||
|
||||
boolean isNetherEnabled();
|
||||
|
||||
boolean isTradeInStacks(int id);
|
||||
|
||||
List<Integer> itemSpawnBlacklist();
|
||||
|
||||
boolean permissionBasedItemSpawn();
|
||||
|
||||
void reloadConfig();
|
||||
|
||||
boolean showNonEssCommandsInHelp();
|
||||
|
||||
boolean spawnIfNoHome();
|
||||
|
||||
boolean use1to1RatioInNether();
|
||||
|
||||
boolean warnOnBuildDisallow();
|
||||
|
||||
boolean warnOnSmite();
|
||||
|
||||
double getMaxMoney();
|
||||
|
||||
boolean isEcoLogEnabled();
|
||||
|
||||
boolean removeGodOnDisconnect();
|
||||
|
||||
boolean changeDisplayName();
|
||||
|
||||
boolean isPlayerCommand(String string);
|
||||
}
|
@@ -23,6 +23,8 @@ public interface IUser
|
||||
|
||||
boolean isAuthorized(IEssentialsCommand cmd);
|
||||
|
||||
boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix);
|
||||
|
||||
void setLastTeleportTimestamp(long time);
|
||||
|
||||
Location getLastLocation();
|
||||
@@ -33,6 +35,8 @@ public interface IUser
|
||||
|
||||
void takeMoney(double value);
|
||||
|
||||
void giveMoney(double value);
|
||||
|
||||
PlayerInventory getInventory();
|
||||
|
||||
void updateInventory();
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -18,17 +20,17 @@ public final class InventoryWorkaround
|
||||
{
|
||||
}
|
||||
|
||||
public static int first(Inventory ci, ItemStack item, boolean forceDurability, boolean forceAmount)
|
||||
public static int first(final Inventory inventory, final ItemStack item, final boolean forceDurability, final boolean forceAmount)
|
||||
{
|
||||
return next(ci, item, 0, forceDurability, forceAmount);
|
||||
return next(inventory, item, 0, forceDurability, forceAmount);
|
||||
}
|
||||
|
||||
public static int next(Inventory ci, ItemStack item, int start, boolean forceDurability, boolean forceAmount)
|
||||
public static int next(final Inventory cinventory, final ItemStack item, final int start, final boolean forceDurability, final boolean forceAmount)
|
||||
{
|
||||
ItemStack[] inventory = ci.getContents();
|
||||
final ItemStack[] inventory = cinventory.getContents();
|
||||
for (int i = start; i < inventory.length; i++)
|
||||
{
|
||||
ItemStack cItem = inventory[i];
|
||||
final ItemStack cItem = inventory[i];
|
||||
if (cItem == null)
|
||||
{
|
||||
continue;
|
||||
@@ -41,15 +43,133 @@ public final class InventoryWorkaround
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, ItemStack> removeItem(Inventory ci, boolean forceDurability, ItemStack... items)
|
||||
public static int firstPartial(final Inventory cinventory, final ItemStack item, final boolean forceDurability)
|
||||
{
|
||||
HashMap<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
if (item == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
final ItemStack[] inventory = cinventory.getContents();
|
||||
for (int i = 0; i < inventory.length; i++)
|
||||
{
|
||||
final ItemStack cItem = inventory[i];
|
||||
if (cItem == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.getTypeId() == cItem.getTypeId() && cItem.getAmount() < cItem.getType().getMaxStackSize() && (!forceDurability || cItem.getDurability() == item.getDurability()))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static Map<Integer, ItemStack> addItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items)
|
||||
{
|
||||
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
|
||||
/* TODO: some optimization
|
||||
* - Create a 'firstPartial' with a 'fromIndex'
|
||||
* - Record the lastPartial per Material
|
||||
* - Cache firstEmpty result
|
||||
*/
|
||||
|
||||
// combine items
|
||||
|
||||
ItemStack[] combined = new ItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
if (items[i] == null || items[i].getAmount() < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < combined.length; j++)
|
||||
{
|
||||
if (combined[j] == null)
|
||||
{
|
||||
combined[j] = new ItemStack(items[i].getType(), items[i].getAmount(), items[i].getDurability());
|
||||
break;
|
||||
}
|
||||
if (combined[j].getTypeId() == items[i].getTypeId() && (!forceDurability || combined[j].getDurability() == items[i].getDurability()))
|
||||
{
|
||||
combined[j].setAmount(combined[j].getAmount() + items[i].getAmount());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
final ItemStack item = items[i];
|
||||
while (true)
|
||||
{
|
||||
// Do we already have a stack of it?
|
||||
final int firstPartial = firstPartial(cinventory, item, forceDurability);
|
||||
|
||||
// Drat! no partial stack
|
||||
if (firstPartial == -1)
|
||||
{
|
||||
// Find a free spot!
|
||||
final int firstFree = cinventory.firstEmpty();
|
||||
|
||||
if (firstFree == -1)
|
||||
{
|
||||
// No space at all!
|
||||
leftover.put(i, item);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// More than a single stack!
|
||||
if (item.getAmount() > item.getType().getMaxStackSize())
|
||||
{
|
||||
cinventory.setItem(firstFree, new CraftItemStack(item.getTypeId(), item.getType().getMaxStackSize(), item.getDurability()));
|
||||
item.setAmount(item.getAmount() - item.getType().getMaxStackSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just store it
|
||||
cinventory.setItem(firstFree, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// So, apparently it might only partially fit, well lets do just that
|
||||
final ItemStack partialItem = cinventory.getItem(firstPartial);
|
||||
|
||||
final int amount = item.getAmount();
|
||||
final int partialAmount = partialItem.getAmount();
|
||||
final int maxAmount = partialItem.getType().getMaxStackSize();
|
||||
|
||||
// Check if it fully fits
|
||||
if (amount + partialAmount <= maxAmount)
|
||||
{
|
||||
partialItem.setAmount(amount + partialAmount);
|
||||
break;
|
||||
}
|
||||
|
||||
// It fits partially
|
||||
partialItem.setAmount(maxAmount);
|
||||
item.setAmount(amount + partialAmount - maxAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
return leftover;
|
||||
}
|
||||
|
||||
public static Map<Integer, ItemStack> removeItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items)
|
||||
{
|
||||
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
|
||||
// TODO: optimization
|
||||
|
||||
for (int i = 0; i < items.length; i++)
|
||||
{
|
||||
ItemStack item = items[i];
|
||||
final ItemStack item = items[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
@@ -66,7 +186,7 @@ public final class InventoryWorkaround
|
||||
}
|
||||
|
||||
// get first Item, ignore the amount
|
||||
int first = first(ci, item, forceDurability, false);
|
||||
final int first = first(cinventory, item, forceDurability, false);
|
||||
|
||||
// Drat! we don't have this type in the inventory
|
||||
if (first == -1)
|
||||
@@ -77,20 +197,20 @@ public final class InventoryWorkaround
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemStack = ci.getItem(first);
|
||||
int amount = itemStack.getAmount();
|
||||
final ItemStack itemStack = cinventory.getItem(first);
|
||||
final int amount = itemStack.getAmount();
|
||||
|
||||
if (amount <= toDelete)
|
||||
{
|
||||
toDelete -= amount;
|
||||
// clear the slot, all used up
|
||||
ci.clear(first);
|
||||
cinventory.clear(first);
|
||||
}
|
||||
else
|
||||
{
|
||||
// split the stack and store
|
||||
itemStack.setAmount(amount - toDelete);
|
||||
ci.setItem(first, itemStack);
|
||||
cinventory.setItem(first, itemStack);
|
||||
toDelete = 0;
|
||||
}
|
||||
}
|
||||
@@ -99,9 +219,9 @@ public final class InventoryWorkaround
|
||||
return leftover;
|
||||
}
|
||||
|
||||
public static boolean containsItem(Inventory ci, boolean forceDurability, ItemStack... items)
|
||||
public static boolean containsItem(final Inventory cinventory, final boolean forceDurability, final ItemStack... items)
|
||||
{
|
||||
HashMap<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
final Map<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||
|
||||
// TODO: optimization
|
||||
|
||||
@@ -131,7 +251,7 @@ public final class InventoryWorkaround
|
||||
|
||||
for (int i = 0; i < combined.length; i++)
|
||||
{
|
||||
ItemStack item = combined[i];
|
||||
final ItemStack item = combined[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
@@ -147,7 +267,7 @@ public final class InventoryWorkaround
|
||||
break;
|
||||
}
|
||||
|
||||
int slot = next(ci, item, position, forceDurability, false);
|
||||
final int slot = next(cinventory, item, position, forceDurability, false);
|
||||
|
||||
// Drat! we don't have this type in the inventory
|
||||
if (slot == -1)
|
||||
@@ -157,8 +277,8 @@ public final class InventoryWorkaround
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemStack = ci.getItem(slot);
|
||||
int amount = itemStack.getAmount();
|
||||
final ItemStack itemStack = cinventory.getItem(slot);
|
||||
final int amount = itemStack.getAmount();
|
||||
|
||||
if (amount <= mustHave)
|
||||
{
|
||||
@@ -175,16 +295,18 @@ public final class InventoryWorkaround
|
||||
return leftover.isEmpty();
|
||||
}
|
||||
|
||||
public static Item[] dropItem(Location loc, ItemStack itm)
|
||||
public static Item[] dropItem(final Location loc, final ItemStack itm)
|
||||
{
|
||||
int maxStackSize = itm.getType().getMaxStackSize();
|
||||
int stacks = itm.getAmount() / maxStackSize;
|
||||
int leftover = itm.getAmount() % maxStackSize;
|
||||
final int maxStackSize = itm.getType().getMaxStackSize();
|
||||
final int stacks = itm.getAmount() / maxStackSize;
|
||||
final int leftover = itm.getAmount() % maxStackSize;
|
||||
Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)];
|
||||
for (int i = 0; i < stacks; i++) {
|
||||
for (int i = 0; i < stacks; i++)
|
||||
{
|
||||
itemStacks[i] = loc.getWorld().dropItem(loc, new ItemStack(itm.getType(), maxStackSize, itm.getDurability()));
|
||||
}
|
||||
if (leftover > 0) {
|
||||
if (leftover > 0)
|
||||
{
|
||||
itemStacks[stacks] = loc.getWorld().dropItem(loc, new ItemStack(itm.getType(), leftover, itm.getDurability()));
|
||||
}
|
||||
return itemStacks;
|
||||
|
@@ -7,30 +7,31 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public final class ItemDb
|
||||
public class ItemDb implements IConf
|
||||
{
|
||||
private ItemDb()
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public ItemDb(IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
private final static Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient Map<String, Integer> items = new HashMap<String, Integer>();
|
||||
private final transient Map<String, Short> durabilities = new HashMap<String, Short>();
|
||||
|
||||
private final static Logger logger = Logger.getLogger("Minecraft");
|
||||
private static Map<String, Integer> items = new HashMap<String, Integer>();
|
||||
private static Map<String, Short> durabilities = new HashMap<String, Short>();
|
||||
|
||||
public static void load(File folder, String fname) throws IOException
|
||||
public void reloadConfig()
|
||||
{
|
||||
folder.mkdirs();
|
||||
File file = new File(folder, fname);
|
||||
final File file = new File(ess.getDataFolder(), "items.csv");
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
file.createNewFile();
|
||||
InputStream res = ItemDb.class.getResourceAsStream("/items.csv");
|
||||
final InputStream res = ItemDb.class.getResourceAsStream("/items.csv");
|
||||
FileWriter tx = null;
|
||||
try
|
||||
{
|
||||
@@ -41,6 +42,11 @@ public final class ItemDb
|
||||
}
|
||||
tx.flush();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, Util.i18n("itemsCsvNotLoaded"), ex);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
@@ -63,52 +69,67 @@ public final class ItemDb
|
||||
}
|
||||
}
|
||||
|
||||
BufferedReader rx = new BufferedReader(new FileReader(file));
|
||||
BufferedReader rx = null;
|
||||
try
|
||||
{
|
||||
rx = new BufferedReader(new FileReader(file));
|
||||
durabilities.clear();
|
||||
items.clear();
|
||||
|
||||
for (int i = 0; rx.ready(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
String line = rx.readLine().trim().toLowerCase();
|
||||
final String line = rx.readLine().trim().toLowerCase();
|
||||
if (line.startsWith("#"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] parts = line.split("[^a-z0-9]");
|
||||
final String[] parts = line.split("[^a-z0-9]");
|
||||
if (parts.length < 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int numeric = Integer.parseInt(parts[1]);
|
||||
final int numeric = Integer.parseInt(parts[1]);
|
||||
|
||||
durabilities.put(parts[0].toLowerCase(), parts.length > 2 && !parts[2].equals("0") ? Short.parseShort(parts[2]) : 0);
|
||||
items.put(parts[0].toLowerCase(), numeric);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.warning(Util.format("parseError", fname, i));
|
||||
LOGGER.warning(Util.format("parseError", "items.csv", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, Util.i18n("itemsCsvNotLoaded"), ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (rx != null) {
|
||||
try
|
||||
{
|
||||
rx.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack get(String id, int quantity) throws Exception
|
||||
public ItemStack get(final String id, final int quantity) throws Exception
|
||||
{
|
||||
ItemStack retval = get(id.toLowerCase());
|
||||
final ItemStack retval = get(id.toLowerCase());
|
||||
retval.setAmount(quantity);
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static ItemStack get(String id) throws Exception
|
||||
public ItemStack get(final String id) throws Exception
|
||||
{
|
||||
int itemid = 0;
|
||||
String itemname = null;
|
||||
@@ -148,13 +169,13 @@ public final class ItemDb
|
||||
}
|
||||
}
|
||||
|
||||
Material mat = Material.getMaterial(itemid);
|
||||
final Material mat = Material.getMaterial(itemid);
|
||||
if (mat == null)
|
||||
{
|
||||
throw new Exception(Util.format("unknownItemId", itemid));
|
||||
}
|
||||
ItemStack retval = new ItemStack(mat);
|
||||
retval.setAmount(Essentials.getStatic().getSettings().getDefaultStackSize());
|
||||
final ItemStack retval = new ItemStack(mat);
|
||||
retval.setAmount(ess.getSettings().getDefaultStackSize());
|
||||
retval.setDurability(metaData);
|
||||
return retval;
|
||||
}
|
||||
|
@@ -1,11 +1,16 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
|
||||
public class JailPlayerListener extends PlayerListener
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final IEssentials ess;
|
||||
|
||||
public JailPlayerListener(IEssentials parent)
|
||||
@@ -16,10 +21,47 @@ public class JailPlayerListener extends PlayerListener
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (user.isJailed())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
event.setRespawnLocation(ess.getJail().getJail(user.getJail()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
event.setTo(ess.getJail().getJail(user.getJail()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, Util.i18n("returnPlayerToJailError"), ex);
|
||||
}
|
||||
user.sendMessage(Util.i18n("jailMessage"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -29,13 +29,16 @@ import org.bukkit.util.Vector;
|
||||
public class OfflinePlayer implements Player
|
||||
{
|
||||
private final String name;
|
||||
final transient IEssentials ess;
|
||||
private Location location = new Location(null, 0, 0, 0, 0, 0);
|
||||
private World world = null;
|
||||
private World world;
|
||||
private UUID uniqueId = UUID.randomUUID();
|
||||
|
||||
public OfflinePlayer(String name)
|
||||
public OfflinePlayer(String name, IEssentials ess)
|
||||
{
|
||||
this.name = name;
|
||||
this.ess = ess;
|
||||
this.world = ess.getServer().getWorlds().get(0);
|
||||
}
|
||||
|
||||
public boolean isOnline()
|
||||
@@ -258,7 +261,7 @@ public class OfflinePlayer implements Player
|
||||
|
||||
public Server getServer()
|
||||
{
|
||||
return Essentials.getStatic() == null ? null : Essentials.getStatic().getServer();
|
||||
return ess == null ? null : ess.getServer();
|
||||
}
|
||||
|
||||
public Vector getMomentum()
|
||||
@@ -296,7 +299,8 @@ public class OfflinePlayer implements Player
|
||||
throw new UnsupportedOperationException(Util.i18n("notSupportedYet"));
|
||||
}
|
||||
|
||||
public void sendRawMessage(String string) {
|
||||
public void sendRawMessage(String string)
|
||||
{
|
||||
throw new UnsupportedOperationException(Util.i18n("notSupportedYet"));
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,48 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public class Permissions2Handler implements IPermissionsHandler
|
||||
{
|
||||
private final transient PermissionHandler permissionHandler;
|
||||
|
||||
Permissions2Handler(final Plugin permissionsPlugin)
|
||||
{
|
||||
permissionHandler = ((Permissions)permissionsPlugin).getHandler();
|
||||
}
|
||||
|
||||
public String getGroup(final Player base)
|
||||
{
|
||||
return permissionHandler.getGroup(base.getWorld().getName(), base.getName());
|
||||
}
|
||||
|
||||
public boolean canBuild(final Player base, final String group)
|
||||
{
|
||||
return permissionHandler.canGroupBuild(base.getWorld().getName(), getGroup(base));
|
||||
}
|
||||
|
||||
public boolean inGroup(final Player base, final String group)
|
||||
{
|
||||
return permissionHandler.inGroup(base.getWorld().getName(), base.getName(), group);
|
||||
}
|
||||
|
||||
public boolean hasPermission(final Player base, final String node)
|
||||
{
|
||||
return permissionHandler.permission(base, node);
|
||||
}
|
||||
|
||||
public String getPrefix(final Player base)
|
||||
{
|
||||
return permissionHandler.getGroupPrefix(base.getWorld().getName(), getGroup(base));
|
||||
}
|
||||
|
||||
public String getSuffix(final Player base)
|
||||
{
|
||||
return permissionHandler.getGroupSuffix(base.getWorld().getName(), getGroup(base));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public class Permissions3Handler implements IPermissionsHandler
|
||||
{
|
||||
private final transient PermissionHandler permissionHandler;
|
||||
|
||||
Permissions3Handler(final Plugin permissionsPlugin)
|
||||
{
|
||||
permissionHandler = ((Permissions)permissionsPlugin).getHandler();
|
||||
}
|
||||
|
||||
public String getGroup(final Player base)
|
||||
{
|
||||
return permissionHandler.getPrimaryGroup(base.getWorld().getName(), base.getName());
|
||||
}
|
||||
|
||||
public boolean canBuild(final Player base, final String group)
|
||||
{
|
||||
return permissionHandler.canUserBuild(base.getWorld().getName(), base.getName());
|
||||
}
|
||||
|
||||
public boolean inGroup(final Player base, final String group)
|
||||
{
|
||||
return permissionHandler.inGroup(base.getWorld().getName(), base.getName(), group);
|
||||
}
|
||||
|
||||
public boolean hasPermission(final Player base, final String node)
|
||||
{
|
||||
return permissionHandler.has(base, node);
|
||||
}
|
||||
|
||||
public String getPrefix(final Player base)
|
||||
{
|
||||
return permissionHandler.getUserPrefix(base.getWorld().getName(), base.getName());
|
||||
}
|
||||
|
||||
public String getSuffix(final Player base)
|
||||
{
|
||||
return permissionHandler.getUserSuffix(base.getWorld().getName(), base.getName());
|
||||
}
|
||||
|
||||
}
|
@@ -19,12 +19,12 @@ public class PlayerExtension extends PlayerWrapper
|
||||
|
||||
public boolean isBanned()
|
||||
{
|
||||
return ess.getBans().contains(getName());
|
||||
return ess.getBans().isNameBanned(this.getName());
|
||||
}
|
||||
|
||||
public boolean isIpBanned()
|
||||
{
|
||||
return ess.getBannedIps().contains(getAddress().getAddress().toString().replace("/", ""));
|
||||
return ess.getBans().isIpBanned(getAddress().getAddress().getHostAddress());
|
||||
}
|
||||
|
||||
public float getCorrectedYaw()
|
||||
@@ -53,38 +53,17 @@ public class PlayerExtension extends PlayerWrapper
|
||||
|
||||
public String getGroup()
|
||||
{
|
||||
try
|
||||
{
|
||||
return com.nijikokun.bukkit.Permissions.Permissions.Security.getGroup(getWorld().getName(), getName());
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
return ess.getPermissionsHandler().getGroup(base);
|
||||
}
|
||||
|
||||
public boolean inGroup(String group)
|
||||
{
|
||||
try
|
||||
{
|
||||
return com.nijikokun.bukkit.Permissions.Permissions.Security.inGroup(getWorld().getName(), getName(), group);
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ess.getPermissionsHandler().inGroup(base, group);
|
||||
}
|
||||
|
||||
public boolean canBuild()
|
||||
{
|
||||
try
|
||||
{
|
||||
return isOp() || com.nijikokun.bukkit.Permissions.Permissions.Security.canGroupBuild(getWorld().getName(), getGroup());
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return ess.getPermissionsHandler().canBuild(base, getGroup());
|
||||
}
|
||||
|
||||
public EntityPlayer getHandle()
|
||||
|
@@ -6,65 +6,74 @@ import org.bukkit.ChatColor;
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Settings implements IConf
|
||||
public class Settings implements ISettings
|
||||
{
|
||||
private final EssentialsConf config;
|
||||
private final transient EssentialsConf config;
|
||||
private final static Logger logger = Logger.getLogger("Minecraft");
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public Settings(File dataFolder)
|
||||
public Settings(IEssentials ess)
|
||||
{
|
||||
config = new EssentialsConf(new File(dataFolder, "config.yml"));
|
||||
this.ess = ess;
|
||||
config = new EssentialsConf(new File(ess.getDataFolder(), "config.yml"));
|
||||
config.setTemplateName("/config.yml");
|
||||
config.load();
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRespawnAtHome()
|
||||
{
|
||||
return config.getBoolean("respawn-at-home", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBedSetsHome()
|
||||
{
|
||||
return config.getBoolean("bed-sethome", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChatRadius()
|
||||
{
|
||||
return config.getInt("chat.radius", config.getInt("chat-radius", 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTeleportDelay()
|
||||
{
|
||||
return config.getDouble("teleport-delay", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultStackSize()
|
||||
{
|
||||
return config.getInt("default-stack-size", 64);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartingBalance()
|
||||
{
|
||||
return config.getInt("starting-balance", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getNetherPortalsEnabled()
|
||||
{
|
||||
return isNetherEnabled() && config.getBoolean("nether.portals-enabled", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommandDisabled(final IEssentialsCommand cmd)
|
||||
{
|
||||
return isCommandDisabled(cmd.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommandDisabled(String label)
|
||||
{
|
||||
for (String c : config.getStringList("disabled-commands", new ArrayList<String>(0)))
|
||||
@@ -75,11 +84,13 @@ public class Settings implements IConf
|
||||
return config.getBoolean("disable-" + label.toLowerCase(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommandRestricted(IEssentialsCommand cmd)
|
||||
{
|
||||
return isCommandRestricted(cmd.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommandRestricted(String label)
|
||||
{
|
||||
for (String c : config.getStringList("restricted-commands", new ArrayList<String>(0)))
|
||||
@@ -90,6 +101,18 @@ public class Settings implements IConf
|
||||
return config.getBoolean("restrict-" + label.toLowerCase(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerCommand(String label)
|
||||
{
|
||||
for (String c : config.getStringList("player-commands", new ArrayList<String>(0)))
|
||||
{
|
||||
if (!c.equalsIgnoreCase(label)) continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommandOverridden(String name)
|
||||
{
|
||||
List<String> defaultList = new ArrayList<String>(1);
|
||||
@@ -103,11 +126,13 @@ public class Settings implements IConf
|
||||
return config.getBoolean("override-" + name.toLowerCase(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCommandCost(IEssentialsCommand cmd)
|
||||
{
|
||||
return getCommandCost(cmd.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCommandCost(String label)
|
||||
{
|
||||
double cost = config.getDouble("command-costs." + label, 0.0);
|
||||
@@ -116,26 +141,25 @@ public class Settings implements IConf
|
||||
return cost;
|
||||
}
|
||||
|
||||
public String getCommandPrefix()
|
||||
{
|
||||
return config.getString("command-prefix", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNicknamePrefix()
|
||||
{
|
||||
return config.getString("nickname-prefix", "~");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTeleportCooldown()
|
||||
{
|
||||
return config.getDouble("teleport-cooldown", 60);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHealCooldown()
|
||||
{
|
||||
return config.getDouble("heal-cooldown", 60);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKit(String name)
|
||||
{
|
||||
Map<String, Object> kits = (Map<String, Object>)config.getProperty("kits");
|
||||
@@ -148,11 +172,13 @@ public class Settings implements IConf
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getKits()
|
||||
{
|
||||
return (Map<String, Object>)config.getProperty("kits");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatColor getOperatorColor() throws Exception
|
||||
{
|
||||
String colorName = config.getString("ops-name-color", null);
|
||||
@@ -173,257 +199,123 @@ public class Settings implements IConf
|
||||
return ChatColor.getByCode(Integer.parseInt(colorName, 16));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getReclaimSetting()
|
||||
{
|
||||
return config.getBoolean("reclaim-onlogout", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNetherName()
|
||||
{
|
||||
return config.getString("nether.folder", "nether");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNetherEnabled()
|
||||
{
|
||||
return config.getBoolean("nether.enabled", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpawnMobLimit()
|
||||
{
|
||||
return config.getInt("spawnmob-limit", 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showNonEssCommandsInHelp()
|
||||
{
|
||||
return config.getBoolean("non-ess-in-help", true);
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getEpSettings()
|
||||
@Override
|
||||
public boolean hidePermissionlessHelp()
|
||||
{
|
||||
Map<String, Boolean> epSettings = new HashMap<String, Boolean>();
|
||||
|
||||
epSettings.put("protect.protect.signs", config.getBoolean("protect.protect.signs", true));
|
||||
epSettings.put("protect.protect.rails", config.getBoolean("protect.protect.rails", true));
|
||||
epSettings.put("protect.protect.block-below", config.getBoolean("protect.protect.block-below", true));
|
||||
epSettings.put("protect.protect.prevent-block-on-rails", config.getBoolean("protect.protect.prevent-block-on-rails", false));
|
||||
return epSettings;
|
||||
return config.getBoolean("hide-permissionless-help", true);
|
||||
}
|
||||
|
||||
public Map<String, String> getEpDBSettings()
|
||||
{
|
||||
Map<String, String> epSettings = new HashMap<String, String>();
|
||||
epSettings.put("protect.datatype", config.getString("protect.datatype", "sqlite"));
|
||||
epSettings.put("protect.username", config.getString("protect.username", "root"));
|
||||
epSettings.put("protect.password", config.getString("protect.password", "root"));
|
||||
epSettings.put("protect.mysqlDb", config.getString("protect.mysqlDb", "jdbc:mysql://localhost:3306/minecraft"));
|
||||
return epSettings;
|
||||
}
|
||||
|
||||
public List<Integer> getEpAlertOnPlacement()
|
||||
{
|
||||
final List<Integer> epAlertPlace = new ArrayList<Integer>();
|
||||
for (String itemName : config.getString("protect.alert.on-placement", "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
ItemStack is;
|
||||
try {
|
||||
is = ItemDb.get(itemName);
|
||||
epAlertPlace.add(is.getTypeId());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "alert.on-placement"));
|
||||
}
|
||||
}
|
||||
return epAlertPlace;
|
||||
}
|
||||
|
||||
public List<Integer> getEpAlertOnUse()
|
||||
{
|
||||
final List<Integer> epAlertUse = new ArrayList<Integer>();
|
||||
for (String itemName : config.getString("protect.alert.on-use", "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
ItemStack is;
|
||||
try {
|
||||
is = ItemDb.get(itemName);
|
||||
epAlertUse.add(is.getTypeId());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "alert.on-use"));
|
||||
}
|
||||
}
|
||||
return epAlertUse;
|
||||
}
|
||||
|
||||
public List<Integer> getEpAlertOnBreak()
|
||||
{
|
||||
final List<Integer> epAlertPlace = new ArrayList<Integer>();
|
||||
for (String itemName : config.getString("protect.alert.on-break", "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
ItemStack is;
|
||||
try {
|
||||
is = ItemDb.get(itemName);
|
||||
epAlertPlace.add(is.getTypeId());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "alert.on-break"));
|
||||
}
|
||||
}
|
||||
return epAlertPlace;
|
||||
}
|
||||
|
||||
public List<Integer> epBlackListPlacement()
|
||||
{
|
||||
final List<Integer> epBlacklistPlacement = new ArrayList<Integer>();
|
||||
for (String itemName : config.getString("protect.blacklist.placement", "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
ItemStack is;
|
||||
try {
|
||||
is = ItemDb.get(itemName);
|
||||
epBlacklistPlacement.add(is.getTypeId());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "blacklist.placement"));
|
||||
}
|
||||
}
|
||||
return epBlacklistPlacement;
|
||||
}
|
||||
|
||||
public List<Integer> epBlackListUsage()
|
||||
{
|
||||
final List<Integer> epBlackListUsage = new ArrayList<Integer>();
|
||||
for (String itemName : config.getString("protect.blacklist.usage", "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
ItemStack is;
|
||||
try {
|
||||
is = ItemDb.get(itemName);
|
||||
epBlackListUsage.add(is.getTypeId());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "blacklist.usage"));
|
||||
}
|
||||
}
|
||||
return epBlackListUsage;
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getEpGuardSettings()
|
||||
{
|
||||
final Map<String, Boolean> epSettings = new HashMap<String, Boolean>();
|
||||
epSettings.put("protect.prevent.lava-flow", config.getBoolean("protect.prevent.lava-flow", false));
|
||||
epSettings.put("protect.prevent.water-flow", config.getBoolean("protect.prevent.water-flow", false));
|
||||
epSettings.put("protect.prevent.water-bucket-flow", config.getBoolean("protect.prevent.water-bucket-flow", false));
|
||||
epSettings.put("protect.prevent.fire-spread", config.getBoolean("protect.prevent.fire-spread", true));
|
||||
epSettings.put("protect.prevent.flint-fire", config.getBoolean("protect.prevent.flint-fire", false));
|
||||
epSettings.put("protect.prevent.portal-creation", config.getBoolean("protect.prevent.portal-creation", false));
|
||||
epSettings.put("protect.prevent.lava-fire-spread", config.getBoolean("protect.prevent.lava-fire-spread", true));
|
||||
epSettings.put("protect.prevent.tnt-explosion", config.getBoolean("protect.prevent.tnt-explosion", false));
|
||||
epSettings.put("protect.prevent.creeper-explosion", config.getBoolean("protect.prevent.creeper-explosion", false));
|
||||
epSettings.put("protect.prevent.creeper-playerdamage", config.getBoolean("protect.prevent.creeper-playerdamage", false));
|
||||
epSettings.put("protect.prevent.creeper-blockdamage", config.getBoolean("protect.prevent.creeper-blockdamage", false));
|
||||
epSettings.put("protect.prevent.entitytarget", config.getBoolean("protect.prevent.entitytarget", false));
|
||||
for (CreatureType ct : CreatureType.values()) {
|
||||
final String name = ct.toString().toLowerCase();
|
||||
epSettings.put("protect.prevent.spawn."+name, config.getBoolean("protect.prevent.spawn."+name, false));
|
||||
}
|
||||
epSettings.put("protect.prevent.lightning-fire-spread", config.getBoolean("protect.prevent.lightning-fire-spread", true));
|
||||
return epSettings;
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getEpPlayerSettings()
|
||||
{
|
||||
final Map<String, Boolean> epPlayerSettings = new HashMap<String, Boolean>();
|
||||
epPlayerSettings.put("protect.disable.fall", config.getBoolean("protect.disable.fall", false));
|
||||
epPlayerSettings.put("protect.disable.pvp", config.getBoolean("protect.disable.pvp", false));
|
||||
epPlayerSettings.put("protect.disable.drown", config.getBoolean("protect.disable.drown", false));
|
||||
epPlayerSettings.put("protect.disable.suffocate", config.getBoolean("protect.disable.suffocate", false));
|
||||
epPlayerSettings.put("protect.disable.lavadmg", config.getBoolean("protect.disable.lavadmg", false));
|
||||
epPlayerSettings.put("protect.disable.projectiles", config.getBoolean("protect.disable.projectiles", false));
|
||||
epPlayerSettings.put("protect.disable.contactdmg", config.getBoolean("protect.disable.contactdmg", false));
|
||||
epPlayerSettings.put("protect.disable.firedmg", config.getBoolean("protect.disable.firedmg", false));
|
||||
epPlayerSettings.put("protect.disable.build", config.getBoolean("protect.disable.build", false));
|
||||
epPlayerSettings.put("protect.disable.lightning", config.getBoolean("protect.disable.lightning", false));
|
||||
epPlayerSettings.put("protect.disable.weather.lightning", config.getBoolean("protect.disable.weather.lightning", false));
|
||||
epPlayerSettings.put("protect.disable.weather.storm", config.getBoolean("protect.disable.weather.storm", false));
|
||||
epPlayerSettings.put("protect.disable.weather.thunder", config.getBoolean("protect.disable.weather.thunder", false));
|
||||
return epPlayerSettings;
|
||||
|
||||
}
|
||||
|
||||
public int getEpCreeperMaxHeight()
|
||||
@Override
|
||||
public int getProtectCreeperMaxHeight()
|
||||
{
|
||||
return config.getInt("protect.creeper.max-height", -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areSignsDisabled()
|
||||
{
|
||||
return config.getBoolean("signs-disabled", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBackupInterval()
|
||||
{
|
||||
return config.getInt("backup.interval", 1440); // 1440 = 24 * 60
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBackupCommand()
|
||||
{
|
||||
return config.getString("backup.command", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChatFormat(String group)
|
||||
{
|
||||
return config.getString("chat.group-formats." + (group == null ? "Default" : group),
|
||||
config.getString("chat.format", "&7[{GROUP}]&f {DISPLAYNAME}&7:&f {MESSAGE}"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getGenerateExitPortals()
|
||||
{
|
||||
return config.getBoolean("nether.generate-exit-portals", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAnnounceNewPlayers()
|
||||
{
|
||||
return !config.getString("newbies.announce-format", "-").isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnnounceNewPlayerFormat(IUser user)
|
||||
{
|
||||
return format(config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!"), user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(String format, IUser user)
|
||||
{
|
||||
return format.replace('&', '§').replace("§§", "&").replace("{PLAYER}", user.getDisplayName()).replace("{DISPLAYNAME}", user.getDisplayName()).replace("{GROUP}", user.getGroup()).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getAddress().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNewbieSpawn()
|
||||
{
|
||||
return config.getString("newbies.spawnpoint", "default");
|
||||
}
|
||||
@Override
|
||||
public boolean getPerWarpPermission()
|
||||
{
|
||||
return config.getBoolean("per-warp-permission", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSortListByGroups()
|
||||
{
|
||||
return config.getBoolean("sort-list-by-groups", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
config.load();
|
||||
}
|
||||
|
||||
public ArrayList<Integer> itemSpawnBlacklist()
|
||||
@Override
|
||||
public List<Integer> itemSpawnBlacklist()
|
||||
{
|
||||
ArrayList<Integer> epItemSpwn = new ArrayList<Integer>();
|
||||
final List<Integer> epItemSpwn = new ArrayList<Integer>();
|
||||
for (String itemName : config.getString("item-spawn-blacklist", "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
@@ -431,7 +323,7 @@ public class Settings implements IConf
|
||||
}
|
||||
ItemStack is;
|
||||
try {
|
||||
is = ItemDb.get(itemName);
|
||||
is = ess.getItemDb().get(itemName);
|
||||
epItemSpwn.add(is.getTypeId());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "item-spawn-blacklist"));
|
||||
@@ -440,40 +332,25 @@ public class Settings implements IConf
|
||||
return epItemSpwn;
|
||||
}
|
||||
|
||||
public ArrayList<Integer> epBlockBreakingBlacklist()
|
||||
{
|
||||
ArrayList<Integer> epBreakList = new ArrayList<Integer>();
|
||||
for (String itemName : config.getString("protect.blacklist.break", "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
ItemStack is;
|
||||
try {
|
||||
is = ItemDb.get(itemName);
|
||||
epBreakList.add(is.getTypeId());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "blacklist.break"));
|
||||
}
|
||||
}
|
||||
return epBreakList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnIfNoHome()
|
||||
{
|
||||
return config.getBoolean("spawn-if-no-home", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean warnOnBuildDisallow()
|
||||
{
|
||||
return config.getBoolean("protect.disable.warn-on-build-disallow", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean use1to1RatioInNether()
|
||||
{
|
||||
return config.getBoolean("nether.use-1to1-ratio", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNetherRatio()
|
||||
{
|
||||
if (config.getBoolean("nether.use-1to1-ratio", false)) {
|
||||
@@ -482,38 +359,109 @@ public class Settings implements IConf
|
||||
return config.getDouble("nether.ratio", 16.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug()
|
||||
{
|
||||
return config.getBoolean("debug", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean warnOnSmite()
|
||||
{
|
||||
return config.getBoolean("warn-on-smite" ,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean permissionBasedItemSpawn()
|
||||
{
|
||||
return config.getBoolean("permission-based-item-spawn", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocale()
|
||||
{
|
||||
return config.getString("locale", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrencySymbol()
|
||||
{
|
||||
return config.getString("currency-symbol", "$").substring(0, 1).replaceAll("[0-9]", "$");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTradeInStacks(int id)
|
||||
{
|
||||
return config.getBoolean("trade-in-stacks-" + id, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEcoDisabled()
|
||||
{
|
||||
return config.getBoolean("disable-eco", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getProtectPreventSpawn(final String creatureName)
|
||||
{
|
||||
return config.getBoolean("protect.prevent.spawn."+creatureName, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getProtectList(final String configName)
|
||||
{
|
||||
final List<Integer> list = new ArrayList<Integer>();
|
||||
for (String itemName : config.getString(configName, "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
ItemStack itemStack;
|
||||
try {
|
||||
itemStack = ess.getItemDb().get(itemName);
|
||||
list.add(itemStack.getTypeId());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, configName));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtectString(final String configName)
|
||||
{
|
||||
return config.getString(configName, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getProtectBoolean(final String configName, boolean def)
|
||||
{
|
||||
return config.getBoolean(configName, def);
|
||||
}
|
||||
|
||||
private final static double MAXMONEY = 10000000000000.0;
|
||||
public double getMaxMoney()
|
||||
{
|
||||
double max = config.getDouble("max-money", MAXMONEY);
|
||||
if (Math.abs(max) > MAXMONEY) {
|
||||
max = max < 0 ? -MAXMONEY : MAXMONEY;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public boolean isEcoLogEnabled()
|
||||
{
|
||||
return config.getBoolean("economy-log-enabled", false);
|
||||
}
|
||||
|
||||
public boolean removeGodOnDisconnect()
|
||||
{
|
||||
return config.getBoolean("remove-god-on-disconnect", false);
|
||||
}
|
||||
|
||||
public boolean changeDisplayName()
|
||||
{
|
||||
return config.getBoolean("change-displayname", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,82 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.minecraft.server.ChunkPosition;
|
||||
import net.minecraft.server.Packet60Explosion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
|
||||
|
||||
public class TNTExplodeListener extends EntityListener implements Runnable
|
||||
{
|
||||
private final IEssentials ess;
|
||||
private boolean enabled = false;
|
||||
private int timer = -1;
|
||||
|
||||
public TNTExplodeListener(IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
public void enable()
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
enabled = true;
|
||||
timer = ess.scheduleSyncDelayedTask(this, 1000);
|
||||
return;
|
||||
}
|
||||
if (timer != -1) {
|
||||
ess.getScheduler().cancelTask(timer);
|
||||
timer = ess.scheduleSyncDelayedTask(this, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityExplode(final EntityExplodeEvent event)
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getEntity() instanceof LivingEntity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size());
|
||||
final Player[] players = ess.getServer().getOnlinePlayers();
|
||||
final List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length);
|
||||
final Location loc = event.getLocation();
|
||||
for (Player player : players)
|
||||
{
|
||||
if (player.getWorld().equals(loc.getWorld()))
|
||||
{
|
||||
blocksUnderPlayers.add(new ChunkPosition(player.getLocation().getBlockX(), player.getLocation().getBlockY() - 1, player.getLocation().getBlockZ()));
|
||||
}
|
||||
}
|
||||
for (Block block : event.blockList())
|
||||
{
|
||||
final ChunkPosition cp = new ChunkPosition(block.getX(), block.getY(), block.getZ());
|
||||
if (!blocksUnderPlayers.contains(cp))
|
||||
{
|
||||
set.add(cp);
|
||||
}
|
||||
}
|
||||
((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0F, set));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
}
|
@@ -1,36 +1,44 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
/**
|
||||
* @author toi
|
||||
* Thanks to Raphfrk for optimization of this class.
|
||||
*/
|
||||
public class TargetBlock {
|
||||
|
||||
private Location loc;
|
||||
private double viewHeight;
|
||||
private int maxDistance;
|
||||
private int[] blockToIgnore;
|
||||
private double checkDistance, curDistance;
|
||||
private double xRotation, yRotation;
|
||||
private Vector targetPos = new Vector();
|
||||
private Vector targetPosDouble = new Vector();
|
||||
private Vector prevPos = new Vector();
|
||||
private final Vector offset = new Vector();
|
||||
|
||||
/**
|
||||
* Original authors: toi & Raphfrk
|
||||
*/
|
||||
public class TargetBlock
|
||||
{
|
||||
private transient final Location location;
|
||||
private transient final double viewHeight;
|
||||
private transient final int maxDistance;
|
||||
private transient final int[] blockToIgnore;
|
||||
private transient final double checkDistance;
|
||||
private transient double curDistance;
|
||||
private transient double targetPositionX;
|
||||
private transient double targetPositionY;
|
||||
private transient double targetPositionZ;
|
||||
private transient int itargetPositionX;
|
||||
private transient int itargetPositionY;
|
||||
private transient int itargetPositionZ;
|
||||
private transient int prevPositionX;
|
||||
private transient int prevPositionY;
|
||||
private transient int prevPositionZ;
|
||||
private transient final double offsetX;
|
||||
private transient final double offsetY;
|
||||
private transient final double offsetZ;
|
||||
|
||||
/**
|
||||
* Constructor requiring a player, uses default values
|
||||
*
|
||||
* @param player Player to work with
|
||||
*/
|
||||
public TargetBlock(Player player)
|
||||
public TargetBlock(final Player player)
|
||||
{
|
||||
this.setValues(player.getLocation(), 300, 1.65, 0.2, null);
|
||||
this(player.getLocation(), 300, 1.65, 0.2, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,9 +46,9 @@ public class TargetBlock {
|
||||
*
|
||||
* @param loc Location to work with
|
||||
*/
|
||||
public TargetBlock(Location loc)
|
||||
public TargetBlock(final Location loc)
|
||||
{
|
||||
this.setValues(loc, 300, 0, 0.2, null);
|
||||
this(loc, 300, 0, 0.2, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,9 +58,9 @@ public class TargetBlock {
|
||||
* @param maxDistance How far it checks for blocks
|
||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||
*/
|
||||
public TargetBlock(Player player, int maxDistance, double checkDistance)
|
||||
public TargetBlock(final Player player, final int maxDistance, final double checkDistance)
|
||||
{
|
||||
this.setValues(player.getLocation(), maxDistance, 1.65, checkDistance, null);
|
||||
this(player.getLocation(), maxDistance, 1.65, checkDistance, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,8 +70,9 @@ public class TargetBlock {
|
||||
* @param maxDistance How far it checks for blocks
|
||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||
*/
|
||||
public TargetBlock(Location loc, int maxDistance, double checkDistance) {
|
||||
this.setValues(loc, maxDistance, 0, checkDistance, null);
|
||||
public TargetBlock(final Location loc, final int maxDistance, final double checkDistance)
|
||||
{
|
||||
this(loc, maxDistance, 0, checkDistance, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,9 +83,9 @@ public class TargetBlock {
|
||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||
* @param blocksToIgnore Integer array of what block ids to ignore while checking for viable targets
|
||||
*/
|
||||
public TargetBlock (Player player, int maxDistance, double checkDistance, int[] blocksToIgnore)
|
||||
public TargetBlock(final Player player, final int maxDistance, final double checkDistance, final int[] blocksToIgnore)
|
||||
{
|
||||
this.setValues(player.getLocation(), maxDistance, 1.65, checkDistance, blocksToIgnore);
|
||||
this(player.getLocation(), maxDistance, 1.65, checkDistance, blocksToIgnore);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,9 +96,9 @@ public class TargetBlock {
|
||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||
* @param blocksToIgnore Array of what block ids to ignore while checking for viable targets
|
||||
*/
|
||||
public TargetBlock (Location loc, int maxDistance, double checkDistance, int[] blocksToIgnore)
|
||||
public TargetBlock(final Location loc, final int maxDistance, final double checkDistance, final int[] blocksToIgnore)
|
||||
{
|
||||
this.setValues(loc, maxDistance, 0, checkDistance, blocksToIgnore);
|
||||
this(loc, maxDistance, 0, checkDistance, blocksToIgnore);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,10 +109,9 @@ public class TargetBlock {
|
||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||
* @param blocksToIgnore String ArrayList of what block ids to ignore while checking for viable targets
|
||||
*/
|
||||
public TargetBlock (Player player, int maxDistance, double checkDistance, ArrayList<String> blocksToIgnore)
|
||||
public TargetBlock(final Player player, final int maxDistance, final double checkDistance, final List<String> blocksToIgnore)
|
||||
{
|
||||
int[] bti = this.convertStringArraytoIntArray(blocksToIgnore);
|
||||
this.setValues(player.getLocation(), maxDistance, 1.65, checkDistance, bti);
|
||||
this(player.getLocation(), maxDistance, 1.65, checkDistance, TargetBlock.convertStringArraytoIntArray(blocksToIgnore));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,10 +122,9 @@ public class TargetBlock {
|
||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||
* @param blocksToIgnore String ArrayList of what block ids to ignore while checking for viable targets
|
||||
*/
|
||||
public TargetBlock (Location loc, int maxDistance, double checkDistance, ArrayList<String> blocksToIgnore)
|
||||
public TargetBlock(final Location loc, final int maxDistance, final double checkDistance, final List<String> blocksToIgnore)
|
||||
{
|
||||
int[] bti = this.convertStringArraytoIntArray(blocksToIgnore);
|
||||
this.setValues(loc, maxDistance, 0, checkDistance, bti);
|
||||
this(loc, maxDistance, 0, checkDistance, TargetBlock.convertStringArraytoIntArray(blocksToIgnore));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,35 +136,47 @@ public class TargetBlock {
|
||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||
* @param blocksToIgnore Ids of blocks to ignore while checking for viable targets
|
||||
*/
|
||||
private void setValues(Location loc, int maxDistance, double viewHeight, double checkDistance, int[] blocksToIgnore)
|
||||
private TargetBlock(final Location loc, final int maxDistance, final double viewHeight, final double checkDistance, final int[] blocksToIgnore)
|
||||
{
|
||||
this.loc = loc;
|
||||
this.location = loc;
|
||||
this.maxDistance = maxDistance;
|
||||
this.viewHeight = viewHeight;
|
||||
this.checkDistance = checkDistance;
|
||||
this.blockToIgnore = blocksToIgnore;
|
||||
this.curDistance = 0;
|
||||
xRotation = (loc.getYaw() + 90) % 360;
|
||||
yRotation = loc.getPitch() * -1;
|
||||
if (blocksToIgnore == null || blocksToIgnore.length == 0)
|
||||
{
|
||||
this.blockToIgnore = new int[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.blockToIgnore = new int[blocksToIgnore.length];
|
||||
System.arraycopy(blocksToIgnore, 0, this.blockToIgnore, 0, this.blockToIgnore.length);
|
||||
}
|
||||
|
||||
double h = (checkDistance * Math.cos(Math.toRadians(yRotation)));
|
||||
offset.setY((checkDistance * Math.sin(Math.toRadians(yRotation))));
|
||||
offset.setX((h * Math.cos(Math.toRadians(xRotation))));
|
||||
offset.setZ((h * Math.sin(Math.toRadians(xRotation))));
|
||||
final double xRotation = (loc.getYaw() + 90) % 360;
|
||||
final double yRotation = loc.getPitch() * -1;
|
||||
|
||||
targetPosDouble = new Vector(loc.getX(), loc.getY() + viewHeight, loc.getZ());
|
||||
targetPos = new Vector( targetPosDouble.getBlockX(), targetPosDouble.getBlockY(), targetPosDouble.getBlockZ());
|
||||
prevPos = targetPos.clone();
|
||||
final double hypotenuse = (checkDistance * Math.cos(Math.toRadians(yRotation)));
|
||||
offsetX = hypotenuse * Math.cos(Math.toRadians(xRotation));
|
||||
offsetY = checkDistance * Math.sin(Math.toRadians(yRotation));
|
||||
offsetZ = hypotenuse * Math.sin(Math.toRadians(xRotation));
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this to reset checking position to allow you to check for a new target with the same TargetBlock instance.
|
||||
*/
|
||||
public void reset()
|
||||
public final void reset()
|
||||
{
|
||||
targetPosDouble = new Vector(loc.getX(), loc.getY() + viewHeight, loc.getZ());
|
||||
targetPos = new Vector( targetPosDouble.getBlockX(), targetPosDouble.getBlockY(), targetPosDouble.getBlockZ());
|
||||
prevPos = targetPos.clone();
|
||||
targetPositionX = location.getX();
|
||||
targetPositionY = location.getY() + viewHeight;
|
||||
targetPositionZ = location.getZ();
|
||||
itargetPositionX = (int)Math.floor(targetPositionX);
|
||||
itargetPositionY = (int)Math.floor(targetPositionY);
|
||||
itargetPositionZ = (int)Math.floor(targetPositionZ);
|
||||
prevPositionX = itargetPositionX;
|
||||
prevPositionY = itargetPositionY;
|
||||
prevPositionZ = itargetPositionZ;
|
||||
this.curDistance = 0;
|
||||
}
|
||||
|
||||
@@ -169,17 +188,16 @@ public class TargetBlock {
|
||||
*/
|
||||
public double getDistanceToBlock()
|
||||
{
|
||||
Vector blockUnderPlayer = new Vector(
|
||||
(int) Math.floor(loc.getX() + 0.5),
|
||||
(int) Math.floor(loc.getY() - 0.5),
|
||||
(int) Math.floor(loc.getZ() + 0.5));
|
||||
final double blockUnderPlayerX = Math.floor(location.getX() + 0.5);
|
||||
final double blockUnderPlayerY = Math.floor(location.getY() - 0.5);
|
||||
final double blockUnderPlayerZ = Math.floor(location.getZ() + 0.5);
|
||||
|
||||
Block blk = getTargetBlock();
|
||||
double x = blk.getX() - blockUnderPlayer.getBlockX();
|
||||
double y = blk.getY() - blockUnderPlayer.getBlockY();
|
||||
double z = blk.getZ() - blockUnderPlayer.getBlockZ();
|
||||
final Block block = getTargetBlock();
|
||||
final double distX = block.getX() - blockUnderPlayerX;
|
||||
final double distY = block.getY() - blockUnderPlayerY;
|
||||
final double distZ = block.getZ() - blockUnderPlayerZ;
|
||||
|
||||
return Math.sqrt((Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)));
|
||||
return Math.sqrt(distX*distX + distY*distY + distZ*distZ);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,17 +208,7 @@ public class TargetBlock {
|
||||
*/
|
||||
public int getDistanceToBlockRounded()
|
||||
{
|
||||
Vector blockUnderPlayer = new Vector(
|
||||
(int) Math.floor(loc.getX() + 0.5),
|
||||
(int) Math.floor(loc.getY() - 0.5),
|
||||
(int) Math.floor(loc.getZ() + 0.5));
|
||||
|
||||
Block blk = getTargetBlock();
|
||||
double x = blk.getX() - blockUnderPlayer.getBlockX();
|
||||
double y = blk.getY() - blockUnderPlayer.getBlockY();
|
||||
double z = blk.getZ() - blockUnderPlayer.getBlockZ();
|
||||
|
||||
return (int) Math.round((Math.sqrt((Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)))));
|
||||
return (int)Math.round(getDistanceToBlock());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,8 +218,7 @@ public class TargetBlock {
|
||||
*/
|
||||
public int getXDistanceToBlock()
|
||||
{
|
||||
this.reset();
|
||||
return (int) Math.floor(getTargetBlock().getX() - loc.getBlockX() + 0.5);
|
||||
return (int)Math.floor(getTargetBlock().getX() - location.getBlockX() + 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,8 +228,7 @@ public class TargetBlock {
|
||||
*/
|
||||
public int getYDistanceToBlock()
|
||||
{
|
||||
this.reset();
|
||||
return (int) Math.floor(getTargetBlock().getY() - loc.getBlockY() + viewHeight);
|
||||
return (int)Math.floor(getTargetBlock().getY() - location.getBlockY() + viewHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,8 +238,7 @@ public class TargetBlock {
|
||||
*/
|
||||
public int getZDistanceToBlock()
|
||||
{
|
||||
this.reset();
|
||||
return (int) Math.floor(getTargetBlock().getZ() - loc.getBlockZ() + 0.5);
|
||||
return (int)Math.floor(getTargetBlock().getZ() - location.getBlockZ() + 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,12 +246,17 @@ public class TargetBlock {
|
||||
*
|
||||
* @return Block
|
||||
*/
|
||||
@SuppressWarnings("empty-statement")
|
||||
public Block getTargetBlock()
|
||||
{
|
||||
this.reset();
|
||||
while ((getNextBlock() != null) && ((getCurrentBlock().getTypeId() == 0) || this.blockToIgnoreHasValue(getCurrentBlock().getTypeId())));
|
||||
return getCurrentBlock();
|
||||
Block block;
|
||||
do
|
||||
{
|
||||
block = getNextBlock();
|
||||
}
|
||||
while (block != null && ((block.getTypeId() == 0) || this.blockIsIgnored(block.getTypeId())));
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,21 +265,9 @@ public class TargetBlock {
|
||||
* @param typeID ID of type to set the block to
|
||||
* @return boolean
|
||||
*/
|
||||
@SuppressWarnings("empty-statement")
|
||||
public boolean setTargetBlock(int typeID)
|
||||
public boolean setTargetBlock(final int typeID)
|
||||
{
|
||||
if (Material.getMaterial(typeID) != null)
|
||||
{
|
||||
this.reset();
|
||||
while (getNextBlock() != null && getCurrentBlock().getTypeId() == 0);
|
||||
if (getCurrentBlock() != null)
|
||||
{
|
||||
Block blk = loc.getWorld().getBlockAt(targetPos.getBlockX(), targetPos.getBlockY(), targetPos.getBlockZ());
|
||||
blk.setTypeId(typeID);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return setTargetBlock(Material.getMaterial(typeID));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,14 +277,16 @@ public class TargetBlock {
|
||||
* @return boolean
|
||||
*/
|
||||
@SuppressWarnings("empty-statement")
|
||||
public boolean setTargetBlock(Material type)
|
||||
public boolean setTargetBlock(final Material type)
|
||||
{
|
||||
this.reset();
|
||||
while ((getNextBlock() != null) && ((getCurrentBlock().getTypeId() == 0) || this.blockToIgnoreHasValue(getCurrentBlock().getTypeId())));
|
||||
if (getCurrentBlock() != null)
|
||||
if (type == null)
|
||||
{
|
||||
Block blk = loc.getWorld().getBlockAt(targetPos.getBlockX(), targetPos.getBlockY(), targetPos.getBlockZ());
|
||||
blk.setType(type);
|
||||
return false;
|
||||
}
|
||||
final Block block = getTargetBlock();
|
||||
if (block != null)
|
||||
{
|
||||
block.setType(type);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -299,22 +299,9 @@ public class TargetBlock {
|
||||
* @param type Name of type to set the block to
|
||||
* @return boolean
|
||||
*/
|
||||
@SuppressWarnings("empty-statement")
|
||||
public boolean setTargetBlock(String type)
|
||||
public boolean setTargetBlock(final String type)
|
||||
{
|
||||
Material mat = Material.valueOf(type);
|
||||
if (mat != null)
|
||||
{
|
||||
this.reset();
|
||||
while ((getNextBlock() != null) && ((getCurrentBlock().getTypeId() == 0) || this.blockToIgnoreHasValue(getCurrentBlock().getTypeId())));
|
||||
if (getCurrentBlock() != null)
|
||||
{
|
||||
Block blk = loc.getWorld().getBlockAt(targetPos.getBlockX(), targetPos.getBlockY(), targetPos.getBlockZ());
|
||||
blk.setType(mat);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return setTargetBlock(Material.valueOf(type));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,18 +309,14 @@ public class TargetBlock {
|
||||
*
|
||||
* @return Block
|
||||
*/
|
||||
@SuppressWarnings("empty-statement")
|
||||
public Block getFaceBlock()
|
||||
{
|
||||
while ((getNextBlock() != null) && ((getCurrentBlock().getTypeId() == 0) || this.blockToIgnoreHasValue(getCurrentBlock().getTypeId())));
|
||||
if (getCurrentBlock() != null)
|
||||
{
|
||||
return getPreviousBlock();
|
||||
}
|
||||
else
|
||||
final Block block = getTargetBlock();
|
||||
if (block == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return getPreviousBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,18 +325,9 @@ public class TargetBlock {
|
||||
* @param typeID
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean setFaceBlock(int typeID)
|
||||
public boolean setFaceBlock(final int typeID)
|
||||
{
|
||||
if (Material.getMaterial(typeID) != null)
|
||||
{
|
||||
if (getCurrentBlock() != null)
|
||||
{
|
||||
Block blk = loc.getWorld().getBlockAt(prevPos.getBlockX(), prevPos.getBlockY(), prevPos.getBlockZ());
|
||||
blk.setTypeId(typeID);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return setFaceBlock(Material.getMaterial(typeID));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -362,11 +336,15 @@ public class TargetBlock {
|
||||
* @param type
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean setFaceBlock(Material type)
|
||||
public boolean setFaceBlock(final Material type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (getCurrentBlock() != null)
|
||||
{
|
||||
Block blk = loc.getWorld().getBlockAt(prevPos.getBlockX(), prevPos.getBlockY(), prevPos.getBlockZ());
|
||||
final Block blk = location.getWorld().getBlockAt(prevPositionX, prevPositionY, prevPositionZ);
|
||||
blk.setType(type);
|
||||
return true;
|
||||
}
|
||||
@@ -380,19 +358,9 @@ public class TargetBlock {
|
||||
* @param type
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean setFaceBlock(String type)
|
||||
public boolean setFaceBlock(final String type)
|
||||
{
|
||||
Material mat = Material.valueOf(type);
|
||||
if (mat != null)
|
||||
{
|
||||
if (getCurrentBlock() != null)
|
||||
{
|
||||
Block blk = loc.getWorld().getBlockAt(prevPos.getBlockX(), prevPos.getBlockY(), prevPos.getBlockZ());
|
||||
blk.setType(mat);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return setFaceBlock(Material.valueOf(type));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,23 +370,27 @@ public class TargetBlock {
|
||||
*/
|
||||
public Block getNextBlock()
|
||||
{
|
||||
prevPos = targetPos.clone();
|
||||
prevPositionX = itargetPositionX;
|
||||
prevPositionY = itargetPositionY;
|
||||
prevPositionZ = itargetPositionZ;
|
||||
do
|
||||
{
|
||||
curDistance += checkDistance;
|
||||
|
||||
targetPosDouble.setX(offset.getX() + targetPosDouble.getX());
|
||||
targetPosDouble.setY(offset.getY() + targetPosDouble.getY());
|
||||
targetPosDouble.setZ(offset.getZ() + targetPosDouble.getZ());
|
||||
targetPos = new Vector( targetPosDouble.getBlockX(), targetPosDouble.getBlockY(), targetPosDouble.getBlockZ());
|
||||
targetPositionX += offsetX;
|
||||
targetPositionY += offsetY;
|
||||
targetPositionZ += offsetZ;
|
||||
itargetPositionX = (int)Math.floor(targetPositionX);
|
||||
itargetPositionY = (int)Math.floor(targetPositionY);
|
||||
itargetPositionZ = (int)Math.floor(targetPositionZ);
|
||||
}
|
||||
while (curDistance <= maxDistance && targetPos.getBlockX() == prevPos.getBlockX() && targetPos.getBlockY() == prevPos.getBlockY() && targetPos.getBlockZ() == prevPos.getBlockZ());
|
||||
while (curDistance <= maxDistance && itargetPositionX == prevPositionX && itargetPositionY == prevPositionY && itargetPositionZ == prevPositionZ);
|
||||
if (curDistance > maxDistance)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.loc.getWorld().getBlockAt(this.targetPos.getBlockX(), this.targetPos.getBlockY(), this.targetPos.getBlockZ());
|
||||
return this.location.getWorld().getBlockAt(itargetPositionX, itargetPositionY, itargetPositionZ);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,14 +400,16 @@ public class TargetBlock {
|
||||
*/
|
||||
public Block getCurrentBlock()
|
||||
{
|
||||
if (curDistance > maxDistance)
|
||||
Block block;
|
||||
if (curDistance <= maxDistance)
|
||||
{
|
||||
return null;
|
||||
block = this.location.getWorld().getBlockAt(itargetPositionX, itargetPositionY, itargetPositionZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.loc.getWorld().getBlockAt(this.targetPos.getBlockX(), this.targetPos.getBlockY(), this.targetPos.getBlockZ());
|
||||
block = null;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -443,18 +417,9 @@ public class TargetBlock {
|
||||
*
|
||||
* @param typeID
|
||||
*/
|
||||
public boolean setCurrentBlock(int typeID)
|
||||
public boolean setCurrentBlock(final int typeID)
|
||||
{
|
||||
if (Material.getMaterial(typeID) != null)
|
||||
{
|
||||
Block blk = getCurrentBlock();
|
||||
if (blk != null)
|
||||
{
|
||||
blk.setTypeId(typeID);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return setCurrentBlock(Material.getMaterial(typeID));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -462,10 +427,10 @@ public class TargetBlock {
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public boolean setCurrentBlock(Material type)
|
||||
public boolean setCurrentBlock(final Material type)
|
||||
{
|
||||
Block blk = getCurrentBlock();
|
||||
if (blk != null)
|
||||
final Block blk = getCurrentBlock();
|
||||
if (blk != null && type != null)
|
||||
{
|
||||
blk.setType(type);
|
||||
return true;
|
||||
@@ -479,19 +444,9 @@ public class TargetBlock {
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public boolean setCurrentBlock(String type)
|
||||
public boolean setCurrentBlock(final String type)
|
||||
{
|
||||
Material mat = Material.valueOf(type);
|
||||
if (mat != null)
|
||||
{
|
||||
Block blk = getCurrentBlock();
|
||||
if (blk != null)
|
||||
{
|
||||
blk.setType(mat);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return setCurrentBlock(Material.valueOf(type));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -501,7 +456,7 @@ public class TargetBlock {
|
||||
*/
|
||||
public Block getPreviousBlock()
|
||||
{
|
||||
return this.loc.getWorld().getBlockAt(prevPos.getBlockX(), prevPos.getBlockY(), prevPos.getBlockZ());
|
||||
return this.location.getWorld().getBlockAt(prevPositionX, prevPositionY, prevPositionZ);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -509,18 +464,9 @@ public class TargetBlock {
|
||||
*
|
||||
* @param typeID
|
||||
*/
|
||||
public boolean setPreviousBlock(int typeID)
|
||||
public boolean setPreviousBlock(final int typeID)
|
||||
{
|
||||
if (Material.getMaterial(typeID) != null)
|
||||
{
|
||||
Block blk = getPreviousBlock();
|
||||
if (blk != null)
|
||||
{
|
||||
blk.setTypeId(typeID);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return setPreviousBlock(Material.getMaterial(typeID));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,10 +474,10 @@ public class TargetBlock {
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public boolean setPreviousBlock(Material type)
|
||||
public boolean setPreviousBlock(final Material type)
|
||||
{
|
||||
Block blk = getPreviousBlock();
|
||||
if (blk != null)
|
||||
final Block blk = getPreviousBlock();
|
||||
if (blk != null && type != null)
|
||||
{
|
||||
blk.setType(type);
|
||||
return true;
|
||||
@@ -545,27 +491,15 @@ public class TargetBlock {
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public boolean setPreviousBlock(String type)
|
||||
public boolean setPreviousBlock(final String type)
|
||||
{
|
||||
Material mat = Material.valueOf(type);
|
||||
if (mat != null)
|
||||
{
|
||||
Block blk = getPreviousBlock();
|
||||
if (blk != null)
|
||||
{
|
||||
blk.setType(mat);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return setPreviousBlock(Material.valueOf(type));
|
||||
}
|
||||
|
||||
private int[] convertStringArraytoIntArray(ArrayList<String> array)
|
||||
private static int[] convertStringArraytoIntArray(final List<String> array)
|
||||
{
|
||||
if (array != null)
|
||||
{
|
||||
int intarray[] = new int[array.size()];
|
||||
for (int i = 0; i < array.size(); i++)
|
||||
final int intarray[] = new int[array == null ? 0 : array.size()];
|
||||
for (int i = 0; i < intarray.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -573,27 +507,20 @@ public class TargetBlock {
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
intarray[i] = 0;
|
||||
}
|
||||
}
|
||||
return intarray;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean blockToIgnoreHasValue(int value)
|
||||
{
|
||||
if (this.blockToIgnore != null)
|
||||
{
|
||||
if (this.blockToIgnore.length > 0)
|
||||
private boolean blockIsIgnored(final int value)
|
||||
{
|
||||
for (int i : this.blockToIgnore)
|
||||
{
|
||||
if (i == value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -2,7 +2,6 @@ package com.earth2me.essentials;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -10,6 +9,7 @@ import org.bukkit.entity.Entity;
|
||||
|
||||
public class Teleport implements Runnable
|
||||
{
|
||||
private static final double MOVE_CONSTANT = 0.3;
|
||||
private static class Target
|
||||
{
|
||||
private final Location location;
|
||||
@@ -48,18 +48,18 @@ public class Teleport implements Runnable
|
||||
private long initY;
|
||||
private long initZ;
|
||||
private Target teleportTarget;
|
||||
private Charge chargeFor;
|
||||
private Trade chargeFor;
|
||||
private final IEssentials ess;
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
private void initTimer(long delay, Target target, Charge chargeFor)
|
||||
private void initTimer(long delay, Target target, Trade chargeFor)
|
||||
{
|
||||
this.started = System.currentTimeMillis();
|
||||
this.delay = delay;
|
||||
this.health = user.getHealth();
|
||||
this.initX = Math.round(user.getLocation().getX() * 10000);
|
||||
this.initY = Math.round(user.getLocation().getY() * 10000);
|
||||
this.initZ = Math.round(user.getLocation().getZ() * 10000);
|
||||
this.initX = Math.round(user.getLocation().getX()*MOVE_CONSTANT);
|
||||
this.initY = Math.round(user.getLocation().getY()*MOVE_CONSTANT);
|
||||
this.initZ = Math.round(user.getLocation().getZ()*MOVE_CONSTANT);
|
||||
this.teleportTarget = target;
|
||||
this.chargeFor = chargeFor;
|
||||
}
|
||||
@@ -72,9 +72,9 @@ public class Teleport implements Runnable
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
if (Math.round(user.getLocation().getX() * 10000) != initX
|
||||
|| Math.round(user.getLocation().getY() * 10000) != initY
|
||||
|| Math.round(user.getLocation().getZ() * 10000) != initZ
|
||||
if (Math.round(user.getLocation().getX()*MOVE_CONSTANT) != initX
|
||||
|| Math.round(user.getLocation().getY()*MOVE_CONSTANT) != initY
|
||||
|| Math.round(user.getLocation().getZ()*MOVE_CONSTANT) != initZ
|
||||
|| user.getHealth() < health)
|
||||
{ // user moved, cancel teleport
|
||||
cancel(true);
|
||||
@@ -101,11 +101,7 @@ public class Teleport implements Runnable
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
ess.showError(user.getBase(), ex, "teleport");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -122,12 +118,12 @@ public class Teleport implements Runnable
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
public void respawn(Spawn spawn, Charge chargeFor) throws Exception
|
||||
public void respawn(Spawn spawn, Trade chargeFor) throws Exception
|
||||
{
|
||||
teleport(new Target(spawn.getSpawn(user.getGroup())), chargeFor);
|
||||
}
|
||||
|
||||
public void warp(String warp, Charge chargeFor) throws Exception
|
||||
public void warp(String warp, Trade chargeFor) throws Exception
|
||||
{
|
||||
Location loc = ess.getWarps().getWarp(warp);
|
||||
teleport(new Target(loc), chargeFor);
|
||||
@@ -181,17 +177,17 @@ public class Teleport implements Runnable
|
||||
cancel(false);
|
||||
}
|
||||
|
||||
public void teleport(Location loc, Charge chargeFor) throws Exception
|
||||
public void teleport(Location loc, Trade chargeFor) throws Exception
|
||||
{
|
||||
teleport(new Target(loc), chargeFor);
|
||||
}
|
||||
|
||||
public void teleport(Entity entity, Charge chargeFor) throws Exception
|
||||
public void teleport(Entity entity, Trade chargeFor) throws Exception
|
||||
{
|
||||
teleport(new Target(entity), chargeFor);
|
||||
}
|
||||
|
||||
private void teleport(Target target, Charge chargeFor) throws Exception
|
||||
private void teleport(Target target, Trade chargeFor) throws Exception
|
||||
{
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
|
||||
@@ -234,20 +230,23 @@ public class Teleport implements Runnable
|
||||
now(new Target(loc));
|
||||
}
|
||||
|
||||
public void now(Location loc, Charge chargeFor) throws Exception
|
||||
public void now(Location loc, Trade chargeFor) throws Exception
|
||||
{
|
||||
cooldown(false);
|
||||
chargeFor.charge(user);
|
||||
now(new Target(loc));
|
||||
}
|
||||
|
||||
public void now(Entity entity) throws Exception
|
||||
public void now(Entity entity, boolean cooldown) throws Exception
|
||||
{
|
||||
if (cooldown)
|
||||
{
|
||||
cooldown(false);
|
||||
}
|
||||
now(new Target(entity));
|
||||
}
|
||||
|
||||
public void back(Charge chargeFor) throws Exception
|
||||
public void back(Trade chargeFor) throws Exception
|
||||
{
|
||||
teleport(new Target(user.getLastLocation()), chargeFor);
|
||||
}
|
||||
@@ -257,12 +256,12 @@ public class Teleport implements Runnable
|
||||
back(null);
|
||||
}
|
||||
|
||||
public void home(Charge chargeFor) throws Exception
|
||||
public void home(Trade chargeFor) throws Exception
|
||||
{
|
||||
home(user, chargeFor);
|
||||
}
|
||||
|
||||
public void home(IUser user, Charge chargeFor) throws Exception
|
||||
public void home(IUser user, Trade chargeFor) throws Exception
|
||||
{
|
||||
Location loc = user.getHome(this.user.getLocation());
|
||||
if (loc == null)
|
||||
|
230
Essentials/src/com/earth2me/essentials/Trade.java
Normal file
230
Essentials/src/com/earth2me/essentials/Trade.java
Normal file
@@ -0,0 +1,230 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Trade
|
||||
{
|
||||
private final transient String command;
|
||||
private final transient Double money;
|
||||
private final transient ItemStack itemStack;
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public Trade(final String command, final IEssentials ess)
|
||||
{
|
||||
this(command, null, null, ess);
|
||||
}
|
||||
|
||||
public Trade(final double money, final IEssentials ess)
|
||||
{
|
||||
this(null, money, null, ess);
|
||||
}
|
||||
|
||||
public Trade(final ItemStack items, final IEssentials ess)
|
||||
{
|
||||
this(null, null, items, ess);
|
||||
}
|
||||
|
||||
private Trade(final String command, final Double money, final ItemStack item, final IEssentials ess)
|
||||
{
|
||||
this.command = command;
|
||||
this.money = money;
|
||||
this.itemStack = item;
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
public void isAffordableFor(final IUser user) throws ChargeException
|
||||
{
|
||||
final double mon = user.getMoney();
|
||||
if (getMoney() != null
|
||||
&& mon < getMoney()
|
||||
&& getMoney() > 0
|
||||
&& !user.isAuthorized("essentials.eco.loan"))
|
||||
{
|
||||
throw new ChargeException(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
|
||||
if (getItemStack() != null
|
||||
&& !InventoryWorkaround.containsItem(user.getInventory(), true, itemStack))
|
||||
{
|
||||
throw new ChargeException(Util.format("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase().replace("_", " ")));
|
||||
}
|
||||
|
||||
if (command != null && !command.isEmpty()
|
||||
&& !user.isAuthorized("essentials.nocommandcost.all")
|
||||
&& !user.isAuthorized("essentials.nocommandcost." + command)
|
||||
&& mon < ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command)
|
||||
&& 0 < ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command)
|
||||
&& !user.isAuthorized("essentials.eco.loan"))
|
||||
{
|
||||
throw new ChargeException(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
}
|
||||
|
||||
public void pay(final IUser user)
|
||||
{
|
||||
if (getMoney() != null && getMoney() > 0)
|
||||
{
|
||||
user.giveMoney(getMoney());
|
||||
}
|
||||
if (getItemStack() != null)
|
||||
{
|
||||
final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItem(user.getInventory(), true, getItemStack());
|
||||
for (ItemStack itemStack : leftOver.values())
|
||||
{
|
||||
InventoryWorkaround.dropItem(user.getLocation(), itemStack);
|
||||
}
|
||||
user.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
public void charge(final IUser user) throws ChargeException
|
||||
{
|
||||
if (getMoney() != null)
|
||||
{
|
||||
final double mon = user.getMoney();
|
||||
if (mon < getMoney() && getMoney() > 0 && !user.isAuthorized("essentials.eco.loan"))
|
||||
{
|
||||
throw new ChargeException(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
user.takeMoney(getMoney());
|
||||
}
|
||||
if (getItemStack() != null)
|
||||
{
|
||||
if (!InventoryWorkaround.containsItem(user.getInventory(), true, itemStack))
|
||||
{
|
||||
throw new ChargeException(Util.format("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase().replace("_", " ")));
|
||||
}
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, getItemStack());
|
||||
user.updateInventory();
|
||||
}
|
||||
if (command != null && !command.isEmpty()
|
||||
&& !user.isAuthorized("essentials.nocommandcost.all")
|
||||
&& !user.isAuthorized("essentials.nocommandcost." + command))
|
||||
{
|
||||
final double mon = user.getMoney();
|
||||
final double cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
|
||||
if (mon < cost && cost > 0 && !user.isAuthorized("essentials.eco.loan"))
|
||||
{
|
||||
throw new ChargeException(Util.i18n("notEnoughMoney"));
|
||||
}
|
||||
user.takeMoney(cost);
|
||||
}
|
||||
}
|
||||
|
||||
public Double getMoney()
|
||||
{
|
||||
return money;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return itemStack;
|
||||
}
|
||||
private static FileWriter fw = null;
|
||||
|
||||
public static void log(String type, String subtype, String event, String sender, Trade charge, String receiver, Trade pay, IEssentials ess)
|
||||
{
|
||||
if (!ess.getSettings().isEcoLogEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (fw == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
fw = new FileWriter(new File(ess.getDataFolder(), "trade.log"), true);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(type).append(",").append(subtype).append(",").append("event").append(",\"");
|
||||
sb.append(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date()));
|
||||
sb.append("\",\"");
|
||||
if (sender != null)
|
||||
{
|
||||
sb.append(sender);
|
||||
}
|
||||
sb.append("\",");
|
||||
if (charge == null)
|
||||
{
|
||||
sb.append("\"\",\"\",\"\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (charge.getItemStack() != null)
|
||||
{
|
||||
sb.append(charge.getItemStack().getAmount()).append(",");
|
||||
sb.append(charge.getItemStack().getType().toString()).append(",");
|
||||
sb.append(charge.getItemStack().getDurability());
|
||||
}
|
||||
if (charge.getMoney() != null)
|
||||
{
|
||||
sb.append(charge.getMoney()).append(",");
|
||||
sb.append("money").append(",");
|
||||
sb.append(ess.getSettings().getCurrencySymbol());
|
||||
}
|
||||
}
|
||||
sb.append(",\"");
|
||||
if (receiver != null)
|
||||
{
|
||||
sb.append(receiver);
|
||||
}
|
||||
sb.append("\",");
|
||||
if (pay == null)
|
||||
{
|
||||
sb.append("\"\",\"\",\"\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pay.getItemStack() != null)
|
||||
{
|
||||
sb.append(pay.getItemStack().getAmount()).append(",");
|
||||
sb.append(pay.getItemStack().getType().toString()).append(",");
|
||||
sb.append(pay.getItemStack().getDurability());
|
||||
}
|
||||
if (pay.getMoney() != null)
|
||||
{
|
||||
sb.append(pay.getMoney()).append(",");
|
||||
sb.append("money").append(",");
|
||||
sb.append(ess.getSettings().getCurrencySymbol());
|
||||
}
|
||||
}
|
||||
sb.append("\n");
|
||||
try
|
||||
{
|
||||
fw.write(sb.toString());
|
||||
fw.flush();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeLog()
|
||||
{
|
||||
if (fw != null) {
|
||||
try
|
||||
{
|
||||
fw.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
||||
}
|
||||
fw = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -34,7 +34,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
|
||||
public boolean isAuthorized(IEssentialsCommand cmd)
|
||||
{
|
||||
return isAuthorized("essentials." + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
|
||||
return isAuthorized(cmd, "essentials.");
|
||||
}
|
||||
|
||||
public boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix)
|
||||
{
|
||||
return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
|
||||
}
|
||||
|
||||
public boolean isAuthorized(String node)
|
||||
@@ -49,15 +54,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return com.nijikokun.bukkit.Permissions.Permissions.Security.permission(base, node);
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
String[] cmds = node.split("\\.", 2);
|
||||
return !ess.getSettings().isCommandRestricted(cmds[cmds.length - 1]);
|
||||
}
|
||||
return ess.getPermissionsHandler().hasPermission(this, node);
|
||||
}
|
||||
|
||||
public void healCooldown() throws Exception
|
||||
@@ -79,13 +76,22 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
}
|
||||
|
||||
public void giveMoney(double value)
|
||||
{
|
||||
giveMoney(value, null);
|
||||
}
|
||||
|
||||
public void giveMoney(double value, CommandSender initiator)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
setMoney(getMoney() + value);
|
||||
sendMessage(Util.format("addedToAccount", Util.formatCurrency(value)));
|
||||
sendMessage(Util.format("addedToAccount", Util.formatCurrency(value, ess)));
|
||||
if (initiator != null)
|
||||
{
|
||||
initiator.sendMessage((Util.format("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())));
|
||||
}
|
||||
}
|
||||
|
||||
public void payUser(User reciever, double value) throws Exception
|
||||
@@ -102,19 +108,28 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
{
|
||||
setMoney(getMoney() - value);
|
||||
reciever.setMoney(reciever.getMoney() + value);
|
||||
sendMessage(Util.format("moneySentTo", Util.formatCurrency(value), reciever.getDisplayName()));
|
||||
reciever.sendMessage(Util.format("moneyRecievedFrom", Util.formatCurrency(value), getDisplayName()));
|
||||
sendMessage(Util.format("moneySentTo", Util.formatCurrency(value, ess), reciever.getDisplayName()));
|
||||
reciever.sendMessage(Util.format("moneyRecievedFrom", Util.formatCurrency(value, ess), getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
public void takeMoney(double value)
|
||||
{
|
||||
takeMoney(value, null);
|
||||
}
|
||||
|
||||
public void takeMoney(double value, CommandSender initiator)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
setMoney(getMoney() - value);
|
||||
sendMessage(Util.format("takenFromAccount", Util.formatCurrency(value)));
|
||||
sendMessage(Util.format("takenFromAccount", Util.formatCurrency(value, ess)));
|
||||
if (initiator != null)
|
||||
{
|
||||
initiator.sendMessage((Util.format("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canAfford(double cost)
|
||||
@@ -125,7 +140,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
this.base = new OfflinePlayer(getName());
|
||||
this.base = new OfflinePlayer(getName(), ess);
|
||||
}
|
||||
|
||||
public boolean getJustPortaled()
|
||||
@@ -160,7 +175,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ChatColor.stripColor(this.getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(((User) o).getDisplayName()));
|
||||
return ChatColor.stripColor(this.getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(((User)o).getDisplayName()));
|
||||
|
||||
}
|
||||
|
||||
@@ -208,26 +223,39 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
|
||||
public String getNick()
|
||||
{
|
||||
String nickname = getNickname();
|
||||
if (ess.getSettings().isCommandDisabled("nick") || nickname == null || nickname.isEmpty() || nickname.equals(getName()))
|
||||
final StringBuilder nickname = new StringBuilder();
|
||||
final String nick = getNickname();
|
||||
if (ess.getSettings().isCommandDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
|
||||
{
|
||||
nickname = getName();
|
||||
nickname.append(getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
nickname = ess.getSettings().getNicknamePrefix() + nickname;
|
||||
nickname.append(ess.getSettings().getNicknamePrefix()).append(nick);
|
||||
}
|
||||
if (isOp())
|
||||
{
|
||||
try
|
||||
{
|
||||
nickname = ess.getSettings().getOperatorColor().toString() + nickname + "§f";
|
||||
nickname.insert(0, ess.getSettings().getOperatorColor().toString());
|
||||
nickname.append("§f");
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
return nickname;
|
||||
|
||||
final String prefix = ess.getPermissionsHandler().getPrefix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName());
|
||||
final String suffix = ess.getPermissionsHandler().getSuffix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName());
|
||||
|
||||
nickname.insert(0, prefix);
|
||||
nickname.append(suffix);
|
||||
if (suffix.length() > 1 && suffix.substring(suffix.length() - 2, suffix.length() - 1).equals("§"))
|
||||
{
|
||||
nickname.append("§f");
|
||||
}
|
||||
|
||||
return nickname.toString();
|
||||
}
|
||||
|
||||
public Teleport getTeleport()
|
||||
@@ -248,12 +276,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
@Override
|
||||
public double getMoney()
|
||||
{
|
||||
if (ess.isRegisterFallbackEnabled() && ess.getPaymentMethod().hasMethod())
|
||||
if (ess.getPaymentMethod().hasMethod())
|
||||
{
|
||||
try
|
||||
{
|
||||
Method method = ess.getPaymentMethod().getMethod();
|
||||
if (!method.hasAccount(this.getName())) {
|
||||
if (!method.hasAccount(this.getName()))
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
Method.MethodAccount account = ess.getPaymentMethod().getMethod().getAccount(this.getName());
|
||||
@@ -269,12 +298,13 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
@Override
|
||||
public void setMoney(double value)
|
||||
{
|
||||
if (ess.isRegisterFallbackEnabled() && ess.getPaymentMethod().hasMethod())
|
||||
if (ess.getPaymentMethod().hasMethod())
|
||||
{
|
||||
try
|
||||
{
|
||||
Method method = ess.getPaymentMethod().getMethod();
|
||||
if (!method.hasAccount(this.getName())) {
|
||||
if (!method.hasAccount(this.getName()))
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
Method.MethodAccount account = ess.getPaymentMethod().getMethod().getAccount(this.getName());
|
||||
@@ -286,4 +316,19 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
}
|
||||
super.setMoney(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAfk(boolean set)
|
||||
{
|
||||
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set);
|
||||
super.setAfk(set);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toggleAfk()
|
||||
{
|
||||
boolean now = super.toggleAfk();
|
||||
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now);
|
||||
return now;
|
||||
}
|
||||
}
|
@@ -58,18 +58,20 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
isSocialSpyEnabled = _isSocialSpyEnabled();
|
||||
isNPC = _isNPC();
|
||||
}
|
||||
|
||||
private double money;
|
||||
|
||||
private double _getMoney() {
|
||||
private double _getMoney()
|
||||
{
|
||||
double money = ess.getSettings().getStartingBalance();
|
||||
if (config.hasProperty("money"))
|
||||
{
|
||||
return config.getDouble("money", ess.getSettings().getStartingBalance());
|
||||
money = config.getDouble("money", money);
|
||||
}
|
||||
else
|
||||
if (Math.abs(money) > ess.getSettings().getMaxMoney())
|
||||
{
|
||||
return ess.getSettings().getStartingBalance();
|
||||
money = money < 0 ? -ess.getSettings().getMaxMoney() : ess.getSettings().getMaxMoney();
|
||||
}
|
||||
return money;
|
||||
}
|
||||
|
||||
public double getMoney()
|
||||
@@ -80,6 +82,10 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
public void setMoney(double value)
|
||||
{
|
||||
money = value;
|
||||
if (Math.abs(money) > ess.getSettings().getMaxMoney())
|
||||
{
|
||||
money = money < 0 ? -ess.getSettings().getMaxMoney() : ess.getSettings().getMaxMoney();
|
||||
}
|
||||
config.setProperty("money", value);
|
||||
config.save();
|
||||
}
|
||||
@@ -383,6 +389,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
setTeleportEnabled(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean toggleSocialSpy()
|
||||
{
|
||||
boolean ret = !isSocialSpyEnabled();
|
||||
@@ -622,7 +629,6 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
setAfk(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private boolean newplayer;
|
||||
|
||||
private boolean getNew()
|
||||
@@ -641,7 +647,6 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
config.setProperty("newplayer", set);
|
||||
config.save();
|
||||
}
|
||||
|
||||
private String geolocation;
|
||||
|
||||
private String _getGeoLocation()
|
||||
@@ -668,7 +673,6 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
}
|
||||
config.save();
|
||||
}
|
||||
|
||||
private boolean isSocialSpyEnabled;
|
||||
|
||||
private boolean _isSocialSpyEnabled()
|
||||
@@ -687,7 +691,6 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
config.setProperty("socialspy", status);
|
||||
config.save();
|
||||
}
|
||||
|
||||
private boolean isNPC;
|
||||
|
||||
private boolean _isNPC()
|
||||
|
@@ -284,9 +284,9 @@ public class Util
|
||||
}
|
||||
private static DecimalFormat df = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
public static String formatCurrency(double value)
|
||||
public static String formatCurrency(final double value, final IEssentials ess)
|
||||
{
|
||||
String str = Essentials.getStatic().getSettings().getCurrencySymbol() + df.format(value);
|
||||
String str = ess.getSettings().getCurrencySymbol() + df.format(value);
|
||||
if (str.endsWith(".00"))
|
||||
{
|
||||
str = str.substring(0, str.length() - 3);
|
||||
@@ -307,19 +307,21 @@ public class Util
|
||||
|
||||
private static class ConfigClassLoader extends ClassLoader
|
||||
{
|
||||
private final File dataFolder;
|
||||
private final ClassLoader cl;
|
||||
private final transient File dataFolder;
|
||||
private final transient ClassLoader cl;
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public ConfigClassLoader(File dataFolder, ClassLoader cl)
|
||||
public ConfigClassLoader(final ClassLoader cl, final IEssentials ess)
|
||||
{
|
||||
this.dataFolder = dataFolder;
|
||||
this.ess = ess;
|
||||
this.dataFolder = ess.getDataFolder();
|
||||
this.cl = cl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getResource(String string)
|
||||
public URL getResource(final String string)
|
||||
{
|
||||
File file = new File(dataFolder, string);
|
||||
final File file = new File(dataFolder, string);
|
||||
if (file.exists())
|
||||
{
|
||||
try
|
||||
@@ -341,17 +343,18 @@ public class Util
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String string)
|
||||
public InputStream getResourceAsStream(final String string)
|
||||
{
|
||||
File file = new File(dataFolder, string);
|
||||
final File file = new File(dataFolder, string);
|
||||
if (file.exists())
|
||||
{
|
||||
BufferedReader br = null;
|
||||
try
|
||||
{
|
||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||
String version = br.readLine();
|
||||
br.close();
|
||||
if (version == null || !version.equals("#version: " + Essentials.getStatic().getDescription().getVersion()))
|
||||
br = new BufferedReader(new FileReader(file));
|
||||
final String version = br.readLine();
|
||||
|
||||
if (version == null || !version.equals("#version: " + ess.getDescription().getVersion()))
|
||||
{
|
||||
logger.log(Level.WARNING, String.format("Translation file %s is not updated for Essentials version. Will use default.", file));
|
||||
return cl.getResourceAsStream(string);
|
||||
@@ -362,36 +365,50 @@ public class Util
|
||||
{
|
||||
return cl.getResourceAsStream(string);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (br != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
br.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
return cl.getResourceAsStream(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return cl.getResourceAsStream(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<URL> getResources(String string) throws IOException
|
||||
public Enumeration<URL> getResources(final String string) throws IOException
|
||||
{
|
||||
return cl.getResources(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> loadClass(String string) throws ClassNotFoundException
|
||||
public Class<?> loadClass(final String string) throws ClassNotFoundException
|
||||
{
|
||||
return cl.loadClass(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setClassAssertionStatus(String string, boolean bln)
|
||||
public synchronized void setClassAssertionStatus(final String string, final boolean bln)
|
||||
{
|
||||
cl.setClassAssertionStatus(string, bln);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setDefaultAssertionStatus(boolean bln)
|
||||
public synchronized void setDefaultAssertionStatus(final boolean bln)
|
||||
{
|
||||
cl.setDefaultAssertionStatus(bln);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setPackageAssertionStatus(String string, boolean bln)
|
||||
public synchronized void setPackageAssertionStatus(final String string, final boolean bln)
|
||||
{
|
||||
cl.setPackageAssertionStatus(string, bln);
|
||||
}
|
||||
@@ -420,7 +437,7 @@ public class Util
|
||||
return mf.format(objects);
|
||||
}
|
||||
|
||||
public static void updateLocale(String loc, File dataFolder)
|
||||
public static void updateLocale(String loc, IEssentials ess)
|
||||
{
|
||||
if (loc == null || loc.isEmpty())
|
||||
{
|
||||
@@ -440,10 +457,27 @@ public class Util
|
||||
currentLocale = new Locale(parts[0], parts[1], parts[2]);
|
||||
}
|
||||
logger.log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
|
||||
bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(dataFolder, Util.class.getClassLoader()));
|
||||
bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(Util.class.getClassLoader(), ess));
|
||||
if (!bundle.keySet().containsAll(defaultBundle.keySet()))
|
||||
{
|
||||
logger.log(Level.WARNING, String.format("Translation file %s does not contain all translation keys.", currentLocale.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public static String joinList(Object... list)
|
||||
{
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (Object each : list)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
buf.append(", ");
|
||||
|
||||
}
|
||||
first = false;
|
||||
buf.append(each);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package com.earth2me.essentials.api;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.EssentialsConf;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.io.File;
|
||||
@@ -9,6 +9,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
/**
|
||||
* Instead of using this api directly, we recommend to use the register plugin:
|
||||
* http://bit.ly/RegisterMethod
|
||||
@@ -19,10 +20,19 @@ public final class Economy
|
||||
{
|
||||
}
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
private static IEssentials ess;
|
||||
|
||||
/**
|
||||
* @param aEss the ess to set
|
||||
*/
|
||||
public static void setEss(IEssentials aEss)
|
||||
{
|
||||
ess = aEss;
|
||||
}
|
||||
|
||||
private static void createNPCFile(String name)
|
||||
{
|
||||
File folder = new File(Essentials.getStatic().getDataFolder(), "userdata");
|
||||
File folder = new File(ess.getDataFolder(), "userdata");
|
||||
if (!folder.exists())
|
||||
{
|
||||
folder.mkdirs();
|
||||
@@ -30,13 +40,13 @@ public final class Economy
|
||||
EssentialsConf npcConfig = new EssentialsConf(new File(folder, Util.sanitizeFileName(name) + ".yml"));
|
||||
npcConfig.load();
|
||||
npcConfig.setProperty("npc", true);
|
||||
npcConfig.setProperty("money", Essentials.getStatic().getSettings().getStartingBalance());
|
||||
npcConfig.setProperty("money", ess.getSettings().getStartingBalance());
|
||||
npcConfig.save();
|
||||
}
|
||||
|
||||
private static void deleteNPC(String name)
|
||||
{
|
||||
File folder = new File(Essentials.getStatic().getDataFolder(), "userdata");
|
||||
File folder = new File(ess.getDataFolder(), "userdata");
|
||||
if (!folder.exists())
|
||||
{
|
||||
folder.mkdirs();
|
||||
@@ -44,8 +54,10 @@ public final class Economy
|
||||
File config = new File(folder, Util.sanitizeFileName(name) + ".yml");
|
||||
EssentialsConf npcConfig = new EssentialsConf(config);
|
||||
npcConfig.load();
|
||||
if (npcConfig.hasProperty("npc") && npcConfig.getBoolean("npc", false)) {
|
||||
if (!config.delete()) {
|
||||
if (npcConfig.hasProperty("npc") && npcConfig.getBoolean("npc", false))
|
||||
{
|
||||
if (!config.delete())
|
||||
{
|
||||
logger.log(Level.WARNING, Util.format("deleteFileError", config));
|
||||
}
|
||||
}
|
||||
@@ -54,14 +66,14 @@ public final class Economy
|
||||
private static User getUserByName(String name)
|
||||
{
|
||||
User user;
|
||||
Player player = Essentials.getStatic().getServer().getPlayer(name);
|
||||
Player player = ess.getServer().getPlayer(name);
|
||||
if (player != null)
|
||||
{
|
||||
user = Essentials.getStatic().getUser(player);
|
||||
user = ess.getUser(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
user = Essentials.getStatic().getOfflineUser(name);
|
||||
user = ess.getOfflineUser(name);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
@@ -75,7 +87,8 @@ public final class Economy
|
||||
public static double getMoney(String name) throws UserDoesNotExistException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
}
|
||||
return user.getMoney();
|
||||
@@ -91,7 +104,8 @@ public final class Economy
|
||||
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
}
|
||||
if (balance < 0.0 && !user.isAuthorized("essentials.eco.loan"))
|
||||
@@ -161,7 +175,7 @@ public final class Economy
|
||||
*/
|
||||
public static void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException
|
||||
{
|
||||
setMoney(name, Essentials.getStatic().getSettings().getStartingBalance());
|
||||
setMoney(name, ess.getSettings().getStartingBalance());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +230,7 @@ public final class Economy
|
||||
*/
|
||||
public static String format(double amount)
|
||||
{
|
||||
return Util.formatCurrency(amount);
|
||||
return Util.formatCurrency(amount, ess);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,7 +238,8 @@ public final class Economy
|
||||
* @param name Name of the user
|
||||
* @return true, if the user exists
|
||||
*/
|
||||
public static boolean playerExists(String name) {
|
||||
public static boolean playerExists(String name)
|
||||
{
|
||||
return getUserByName(name) != null;
|
||||
}
|
||||
|
||||
@@ -237,7 +252,8 @@ public final class Economy
|
||||
public static boolean isNPC(String name) throws UserDoesNotExistException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
}
|
||||
return user.isNPC();
|
||||
@@ -251,7 +267,8 @@ public final class Economy
|
||||
public static boolean createNPC(String name)
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
createNPCFile(name);
|
||||
return true;
|
||||
}
|
||||
@@ -266,7 +283,8 @@ public final class Economy
|
||||
public static void removeNPC(String name) throws UserDoesNotExistException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
}
|
||||
deleteNPC(name);
|
||||
|
@@ -17,11 +17,29 @@ public class Commandafk extends EssentialsCommand
|
||||
{
|
||||
charge(user);
|
||||
|
||||
if (args.length > 0 && user.isAuthorized("essentials.afk.others"))
|
||||
{
|
||||
User afkUser = ess.getUser(ess.getServer().matchPlayer(args[0]));
|
||||
if (afkUser != null)
|
||||
{
|
||||
toggleAfk(afkUser);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
toggleAfk(user);
|
||||
}
|
||||
}
|
||||
|
||||
private final void toggleAfk(User user)
|
||||
{
|
||||
if (!user.toggleAfk())
|
||||
{
|
||||
user.sendMessage(Util.i18n("markedAsNotAway"));
|
||||
ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName()));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(Util.i18n("markedAsAway"));
|
||||
ess.broadcastMessage(user.getName(), Util.format("userIsAway", user.getDisplayName()));
|
||||
}
|
||||
|
@@ -1,12 +1,10 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import net.minecraft.server.EntityTNTPrimed;
|
||||
import net.minecraft.server.World;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.TargetBlock;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
|
||||
public class Commandantioch extends EssentialsCommand
|
||||
@@ -17,17 +15,13 @@ public class Commandantioch extends EssentialsCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
charge(user);
|
||||
ess.broadcastMessage(user.getName(), "...lobbest thou thy Holy Hand Grenade of Antioch towards thy foe,");
|
||||
ess.broadcastMessage(user.getName(), "who being naughty in My sight, shall snuff it.");
|
||||
|
||||
Location loc = user.getLocation();
|
||||
World world = ((CraftWorld)user.getWorld()).getHandle();
|
||||
loc = new TargetBlock(user).getTargetBlock().getLocation();
|
||||
EntityTNTPrimed tnt = new EntityTNTPrimed(world, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
world.addEntity(tnt);
|
||||
world.makeSound(tnt, "random.fuse", 1.0F, 1.0F);
|
||||
final Location loc = new TargetBlock(user).getTargetBlock().getLocation();
|
||||
loc.getWorld().spawn(loc, TNTPrimed.class);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.Server;
|
||||
@@ -16,7 +16,7 @@ public class Commandback extends EssentialsCommand
|
||||
@Override
|
||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
Charge charge = new Charge(this.getName(), ess);
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
user.sendMessage(Util.i18n("backUsageMsg"));
|
||||
user.getTeleport().back(charge);
|
||||
|
@@ -20,7 +20,7 @@ public class Commandbalance extends EssentialsCommand
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
sender.sendMessage(Util.format("balance", Util.formatCurrency(getPlayer(server, args, 0).getMoney())));
|
||||
sender.sendMessage(Util.format("balance", Util.formatCurrency(getPlayer(server, args, 0, true).getMoney(), ess)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,7 +31,7 @@ public class Commandbalance extends EssentialsCommand
|
||||
|| !(user.isAuthorized("essentials.balance.others")
|
||||
|| user.isAuthorized("essentials.balance.other"))
|
||||
? user
|
||||
: getPlayer(server, args, 0)).getMoney();
|
||||
user.sendMessage(Util.format("balance", Util.formatCurrency(bal)));
|
||||
: getPlayer(server, args, 0, true)).getMoney();
|
||||
user.sendMessage(Util.format("balance", Util.formatCurrency(bal, ess)));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,67 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
public class Commandbalancetop extends EssentialsCommand
|
||||
{
|
||||
public Commandbalancetop()
|
||||
{
|
||||
super("balancetop");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
int max = 10;
|
||||
if (args.length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Integer.parseInt(args[0]) < 10)
|
||||
{
|
||||
max = Integer.parseInt(args[0]);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
//catch it because they tried to enter a string not number.
|
||||
}
|
||||
}
|
||||
final Map<User, Double> balances = new HashMap<User, Double>();
|
||||
for (User u : ess.getAllUsers().values())
|
||||
{
|
||||
balances.put(u, u.getMoney());
|
||||
}
|
||||
|
||||
final List<Map.Entry<User, Double>> sortedEntries = new ArrayList<Map.Entry<User, Double>>(balances.entrySet());
|
||||
Collections.sort(sortedEntries, new Comparator<Map.Entry<User, Double>>()
|
||||
{
|
||||
public int compare(final Entry<User, Double> entry1, final Entry<User, Double> entry2)
|
||||
{
|
||||
return -entry1.getValue().compareTo(entry2.getValue());
|
||||
}
|
||||
});
|
||||
int count = 0;
|
||||
sender.sendMessage(Util.format("balanceTop", max));
|
||||
for (Map.Entry<User, Double> entry : sortedEntries)
|
||||
{
|
||||
if (count == max)
|
||||
{
|
||||
break;
|
||||
}
|
||||
sender.sendMessage(entry.getKey().getDisplayName() + ", " + Util.formatCurrency(entry.getValue(), ess));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
|
||||
@@ -15,31 +14,32 @@ public class Commandban extends EssentialsCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
User p = null;
|
||||
if (server.matchPlayer(args[0]).isEmpty())
|
||||
final User player = getPlayer(server, args, 0, true);
|
||||
if (player.isAuthorized("essentials.ban.exempt"))
|
||||
{
|
||||
((CraftServer)server).getHandle().a(args[0]);
|
||||
sender.sendMessage(Util.format("playerBanned",args[0]));
|
||||
sender.sendMessage(Util.i18n("banExempt"));
|
||||
return;
|
||||
}
|
||||
|
||||
String banReason;
|
||||
if (args.length > 1)
|
||||
{
|
||||
banReason = getFinalArg(args, 1);
|
||||
player.setBanReason(commandLabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
p = ess.getUser(server.matchPlayer(args[0]).get(0));
|
||||
String banReason = Util.i18n("defaultBanReason");
|
||||
if(args.length > 1) {
|
||||
banReason = getFinalArg(args, 1);
|
||||
p.setBanReason(commandLabel);
|
||||
banReason = Util.i18n("defaultBanReason");
|
||||
}
|
||||
p.kickPlayer(banReason);
|
||||
((CraftServer)server).getHandle().a(p.getName());
|
||||
sender.sendMessage(Util.format("playerBanned", p.getName()));
|
||||
}
|
||||
ess.loadBanList();
|
||||
player.kickPlayer(banReason);
|
||||
ess.getBans().banByName(player.getName());
|
||||
server.broadcastMessage(Util.format("playerBanned", player.getName(), banReason));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
|
||||
public class Commandbanip extends EssentialsCommand
|
||||
@@ -21,9 +20,7 @@ public class Commandbanip extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
((CraftServer)server).getHandle().c(args[0]);
|
||||
ess.getBans().banByIp(args[0]);
|
||||
sender.sendMessage(Util.i18n("banIpAddress"));
|
||||
ess.loadBanList();
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ public class Commandbigtree extends EssentialsCommand
|
||||
@Override
|
||||
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
TreeType tree = TreeType.TREE;
|
||||
TreeType tree;
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("redwood"))
|
||||
{
|
||||
tree = TreeType.TALL_REDWOOD;
|
||||
@@ -36,7 +36,7 @@ public class Commandbigtree extends EssentialsCommand
|
||||
double z = user.getLocation().getZ();
|
||||
|
||||
// offset tree in direction player is facing
|
||||
int r = (int)user.getCorrectedYaw();
|
||||
final int r = (int)user.getCorrectedYaw();
|
||||
if (r < 68 || r > 292) // north
|
||||
{
|
||||
x -= 3.0D;
|
||||
@@ -54,8 +54,8 @@ public class Commandbigtree extends EssentialsCommand
|
||||
z += 3.0D;
|
||||
}
|
||||
|
||||
Location safeLocation = Util.getSafeDestination(new Location(user.getWorld(), x, y, z));
|
||||
boolean success = user.getWorld().generateTree(safeLocation, (TreeType)tree);
|
||||
final Location safeLocation = Util.getSafeDestination(new Location(user.getWorld(), x, y, z));
|
||||
final boolean success = user.getWorld().generateTree(safeLocation, (TreeType)tree);
|
||||
if (success)
|
||||
{
|
||||
charge(user);
|
||||
|
@@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
||||
public class Commandclearinventory extends EssentialsCommand
|
||||
|
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import org.bukkit.entity.Player;
|
||||
import com.earth2me.essentials.User;
|
||||
|
||||
@@ -56,17 +55,15 @@ public class Commandeco extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player p : server.matchPlayer(args[1]))
|
||||
{
|
||||
User u = ess.getUser(p);
|
||||
User u = getPlayer(server, args, 1, true);
|
||||
switch (cmd)
|
||||
{
|
||||
case GIVE:
|
||||
u.giveMoney(amount);
|
||||
u.giveMoney(amount, sender);
|
||||
break;
|
||||
|
||||
case TAKE:
|
||||
u.takeMoney(amount);
|
||||
u.takeMoney(amount, sender);
|
||||
break;
|
||||
|
||||
case RESET:
|
||||
@@ -75,8 +72,6 @@ public class Commandeco extends EssentialsCommand
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private enum EcoCommands
|
||||
{
|
||||
|
@@ -1,8 +1,14 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commandessentials extends EssentialsCommand
|
||||
@@ -11,12 +17,102 @@ public class Commandessentials extends EssentialsCommand
|
||||
{
|
||||
super("essentials");
|
||||
}
|
||||
private transient int taskid;
|
||||
private final transient Map<Player, Block> noteBlocks = new HashMap<Player, Block>();
|
||||
|
||||
@Override
|
||||
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
final Map<String, Byte> noteMap = new HashMap<String, Byte>();
|
||||
noteMap.put("1F#", (byte)0x0);
|
||||
noteMap.put("1G", (byte)0x1);
|
||||
noteMap.put("1G#", (byte)0x2);
|
||||
noteMap.put("1A", (byte)0x3);
|
||||
noteMap.put("1A#", (byte)0x4);
|
||||
noteMap.put("1B", (byte)0x5);
|
||||
noteMap.put("1C", (byte)0x6);
|
||||
noteMap.put("1C#", (byte)0x7);
|
||||
noteMap.put("1D", (byte)0x8);
|
||||
noteMap.put("1D#", (byte)0x9);
|
||||
noteMap.put("1E", (byte)0xA);
|
||||
noteMap.put("1F", (byte)0xB);
|
||||
noteMap.put("2F#", (byte)(0x0 + 0xC));
|
||||
noteMap.put("2G", (byte)(0x1 + 0xC));
|
||||
noteMap.put("2G#", (byte)(0x2 + 0xC));
|
||||
noteMap.put("2A", (byte)(0x3 + 0xC));
|
||||
noteMap.put("2A#", (byte)(0x4 + 0xC));
|
||||
noteMap.put("2B", (byte)(0x5 + 0xC));
|
||||
noteMap.put("2C", (byte)(0x6 + 0xC));
|
||||
noteMap.put("2C#", (byte)(0x7 + 0xC));
|
||||
noteMap.put("2D", (byte)(0x8 + 0xC));
|
||||
noteMap.put("2D#", (byte)(0x9 + 0xC));
|
||||
noteMap.put("2E", (byte)(0xA + 0xC));
|
||||
noteMap.put("2F", (byte)(0xB + 0xC));
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("nya"))
|
||||
{
|
||||
if (!noteBlocks.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
final String tuneStr = "1D#,1E,2F#,,2A#,1E,1D#,1E,2F#,2B,2D#,2E,2D#,2A#,2B,,2F#,,1D#,1E,2F#,2B,2C#,2A#,2B,2C#,2E,2D#,2E,2C#,,2F#,,2G#,,1D,1D#,,1C#,1D,1C#,1B,,1B,,1C#,,1D,,1D,1C#,1B,1C#,1D#,2F#,2G#,1D#,2F#,1C#,1D#,1B,1C#,1B,1D#,,2F#,,2G#,1D#,2F#,1C#,1D#,1B,1D,1D#,1D,1C#,1B,1C#,1D,,1B,1C#,1D#,2F#,1C#,1D,1C#,1B,1C#,,1B,,1C#,,2F#,,2G#,,1D,1D#,,1C#,1D,1C#,1B,,1B,,1C#,,1D,,1D,1C#,1B,1C#,1D#,2F#,2G#,1D#,2F#,1C#,1D#,1B,1C#,1B,1D#,,2F#,,2G#,1D#,2F#,1C#,1D#,1B,1D,1D#,1D,1C#,1B,1C#,1D,,1B,1C#,1D#,2F#,1C#,1D,1C#,1B,1C#,,1B,,1B,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1A#,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1A#,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1A#,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1A#,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1B,,";
|
||||
final String[] tune = tuneStr.split(",");
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
final Location loc = player.getLocation();
|
||||
loc.add(0, 3, 0);
|
||||
while (loc.getBlockY() < player.getLocation().getBlockY() + 10 && loc.getBlock().getTypeId() != 0)
|
||||
{
|
||||
loc.add(0, 1, 0);
|
||||
}
|
||||
if (loc.getBlock().getTypeId() == 0)
|
||||
{
|
||||
noteBlocks.put(player, loc.getBlock());
|
||||
loc.getBlock().setType(Material.NOTE_BLOCK);
|
||||
}
|
||||
}
|
||||
taskid = ess.scheduleSyncRepeatingTask(new Runnable()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
public void run()
|
||||
{
|
||||
final String note = tune[i];
|
||||
i++;
|
||||
if (i >= tune.length)
|
||||
{
|
||||
Commandessentials.this.stopTune();
|
||||
}
|
||||
if (note.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Map<Player, Block> noteBlocks = Commandessentials.this.noteBlocks;
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
Block block = noteBlocks.get(player);
|
||||
if (block == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
player.playNote(block.getLocation(), (byte)0, noteMap.get(note));
|
||||
}
|
||||
}
|
||||
}, 20, 2);
|
||||
return;
|
||||
}
|
||||
ess.reload();
|
||||
charge(sender);
|
||||
sender.sendMessage(Util.format("essentialsReload", ess.getDescription().getVersion()));
|
||||
}
|
||||
|
||||
private void stopTune()
|
||||
{
|
||||
ess.getScheduler().cancelTask(taskid);
|
||||
for (Block block : noteBlocks.values())
|
||||
{
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
noteBlocks.clear();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,24 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
|
||||
public class Commandfireball extends EssentialsCommand
|
||||
{
|
||||
|
||||
public Commandfireball()
|
||||
{
|
||||
super("fireball");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
charge(user);
|
||||
final Vector direction = user.getEyeLocation().getDirection().multiply(2);
|
||||
user.getWorld().spawn(user.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Fireball.class);
|
||||
}
|
||||
}
|
@@ -18,7 +18,8 @@ public class Commandgc extends EssentialsCommand
|
||||
{
|
||||
charge(sender);
|
||||
sender.sendMessage(Util.format("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024)));
|
||||
sender.sendMessage(Util.format("gcmin", (Runtime.getRuntime().freeMemory() / 1024 / 1024)));
|
||||
sender.sendMessage(Util.format("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024)));
|
||||
sender.sendMessage(Util.format("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024)));
|
||||
for (World w : server.getWorlds())
|
||||
{
|
||||
sender.sendMessage(
|
||||
|
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.earth2me.essentials.ItemDb;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@@ -25,7 +24,7 @@ public class Commandgive extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
ItemStack stack = ItemDb.get(args[1]);
|
||||
ItemStack stack = ess.getItemDb().get(args[1]);
|
||||
|
||||
String itemname = stack.getType().toString().toLowerCase().replace("_", "");
|
||||
if (sender instanceof Player
|
||||
|
@@ -30,17 +30,32 @@ public class Commandhelp extends EssentialsCommand
|
||||
@Override
|
||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
int page;
|
||||
int page = 1;
|
||||
String match = "";
|
||||
try
|
||||
{
|
||||
page = args.length > 0 ? Integer.parseInt(args[0]) : 1;
|
||||
if (args.length > 0)
|
||||
{
|
||||
match = args[0].toLowerCase();
|
||||
page = Integer.parseInt(args[args.length - 1]);
|
||||
if (args.length == 1)
|
||||
{
|
||||
match = "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
page = 1;
|
||||
if (args.length == 1)
|
||||
{
|
||||
match = args[0].toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
List<String> lines = getHelpLines(user);
|
||||
List<String> lines = getHelpLines(user, match);
|
||||
if (lines.size() > 0)
|
||||
{
|
||||
int start = (page - 1) * 9;
|
||||
int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);
|
||||
|
||||
@@ -50,6 +65,11 @@ public class Commandhelp extends EssentialsCommand
|
||||
user.sendMessage(lines.get(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
user.sendMessage(Util.i18n("noHelpFound"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
@@ -58,13 +78,13 @@ public class Commandhelp extends EssentialsCommand
|
||||
}
|
||||
|
||||
@SuppressWarnings("CallToThreadDumpStack")
|
||||
private List<String> getHelpLines(User user) throws Exception
|
||||
private List<String> getHelpLines(User user, String match) throws Exception
|
||||
{
|
||||
List<String> retval = new ArrayList<String>();
|
||||
File helpFile = new File(ess.getDataFolder(), "help_"+Util.sanitizeFileName(user.getName()) +".txt");
|
||||
File helpFile = new File(ess.getDataFolder(), "help_" + Util.sanitizeFileName(user.getName()) + ".txt");
|
||||
if (!helpFile.exists())
|
||||
{
|
||||
helpFile = new File(ess.getDataFolder(), "help_"+Util.sanitizeFileName(user.getGroup()) +".txt");
|
||||
helpFile = new File(ess.getDataFolder(), "help_" + Util.sanitizeFileName(user.getGroup()) + ".txt");
|
||||
}
|
||||
if (!helpFile.exists())
|
||||
{
|
||||
@@ -73,7 +93,8 @@ public class Commandhelp extends EssentialsCommand
|
||||
if (helpFile.exists())
|
||||
{
|
||||
final BufferedReader bufferedReader = new BufferedReader(new FileReader(helpFile));
|
||||
try {
|
||||
try
|
||||
{
|
||||
|
||||
while (bufferedReader.ready())
|
||||
{
|
||||
@@ -98,6 +119,12 @@ public class Commandhelp extends EssentialsCommand
|
||||
final HashMap<String, HashMap<String, String>> cmds = (HashMap<String, HashMap<String, String>>)desc.getCommands();
|
||||
for (Entry<String, HashMap<String, String>> k : cmds.entrySet())
|
||||
{
|
||||
if ((!match.equalsIgnoreCase("")) && (!k.getKey().toLowerCase().contains(match))
|
||||
&& (!k.getValue().get("description").toLowerCase().contains(match)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p.getDescription().getName().toLowerCase().contains("essentials"))
|
||||
{
|
||||
final String node = "essentials." + k.getKey();
|
||||
@@ -119,11 +146,21 @@ public class Commandhelp extends EssentialsCommand
|
||||
retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (value.containsKey("permissions") && value.get("permissions") != null && !(value.get("permissions").equals("")))
|
||||
{
|
||||
if (user.isAuthorized(value.get("permissions")))
|
||||
{
|
||||
retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ess.getSettings().hidePermissionlessHelp())
|
||||
{
|
||||
retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
@@ -16,7 +16,7 @@ public class Commandhome extends EssentialsCommand
|
||||
@Override
|
||||
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
Charge charge = new Charge(this.getName(), ess);
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
if(args.length > 0 && user.isAuthorized("essentials.home.others"))
|
||||
{
|
||||
|
@@ -1,10 +1,8 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.ItemDb;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -23,7 +21,7 @@ public class Commanditem extends EssentialsCommand
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
ItemStack stack = ItemDb.get(args[0]);
|
||||
ItemStack stack = ess.getItemDb().get(args[0]);
|
||||
|
||||
String itemname = stack.getType().toString().toLowerCase().replace("_", "");
|
||||
if (ess.getSettings().permissionBasedItemSpawn()
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.TargetBlock;
|
||||
@@ -36,7 +36,7 @@ public class Commandjump extends EssentialsCommand
|
||||
throw new Exception(Util.i18n("jumpError"), ex);
|
||||
}
|
||||
|
||||
Charge charge = new Charge(this.getName(), ess);
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
user.getTeleport().teleport(loc, charge);
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
||||
public class Commandkick extends EssentialsCommand
|
||||
@@ -22,18 +21,15 @@ public class Commandkick extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
User u;
|
||||
try
|
||||
User u = getPlayer(server, args, 0);
|
||||
if (u.isAuthorized("essentials.kick.exempt"))
|
||||
{
|
||||
u = ess.getUser(server.matchPlayer(args[0]).get(0));
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
sender.sendMessage(Util.i18n("playerNotFound"));
|
||||
sender.sendMessage(Util.i18n("kickExempt"));
|
||||
return;
|
||||
}
|
||||
|
||||
charge(sender);
|
||||
u.kickPlayer(args.length > 1 ? getFinalArg(args, 1) : Util.i18n("kickDefault"));
|
||||
final String kickReason = args.length > 1 ? getFinalArg(args, 1) : Util.i18n("kickDefault");
|
||||
u.kickPlayer(kickReason);
|
||||
server.broadcastMessage(Util.format("playerKicked", u.getName(), kickReason));
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -109,7 +109,7 @@ public class Commandkit extends EssentialsCommand
|
||||
items = (List<String>)kit;
|
||||
}
|
||||
|
||||
Charge charge = new Charge("kit-" + kitName, ess);
|
||||
Trade charge = new Trade("kit-" + kitName, ess);
|
||||
try
|
||||
{
|
||||
charge.isAffordableFor(user);
|
||||
|
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import org.bukkit.entity.Player;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
|
@@ -0,0 +1,58 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
|
||||
public class Commandnuke extends EssentialsCommand
|
||||
{
|
||||
public Commandnuke()
|
||||
{
|
||||
super("nuke");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws NoSuchFieldException, NotEnoughArgumentsException
|
||||
{
|
||||
List<Player> targets;
|
||||
if (args.length > 0)
|
||||
{
|
||||
targets = new ArrayList<Player>();
|
||||
int pos = 0;
|
||||
for (String arg : args)
|
||||
{
|
||||
targets.add(getPlayer(server, args, pos));
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
targets = Arrays.asList(server.getOnlinePlayers());
|
||||
}
|
||||
ess.getTNTListener().enable();
|
||||
for (Player player : targets)
|
||||
{
|
||||
if (player == null) {
|
||||
continue;
|
||||
}
|
||||
player.sendMessage("May death rain upon them");
|
||||
final Location loc = player.getLocation();
|
||||
final World world = loc.getWorld();
|
||||
for (int x = -10; x <= 10; x += 5)
|
||||
{
|
||||
for (int z = -10; z <= 10; z += 5)
|
||||
{
|
||||
final Location tntloc = new Location(world, loc.getBlockX() + x, 127, loc.getBlockZ() + z);
|
||||
final TNTPrimed tnt = world.spawn(tntloc, TNTPrimed.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
||||
public class Commandrealname extends EssentialsCommand
|
||||
@@ -20,15 +21,15 @@ public class Commandrealname extends EssentialsCommand
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
String whois = args[0].toLowerCase();
|
||||
final String whois = args[0].toLowerCase();
|
||||
charge(user);
|
||||
for (Player p : server.getOnlinePlayers())
|
||||
{
|
||||
User u = ess.getUser(p);
|
||||
String dn = u.getDisplayName().toLowerCase();
|
||||
if (!whois.equals(dn)
|
||||
&& !whois.equals(ess.getSettings().getNicknamePrefix() + dn)
|
||||
&& !whois.equals(u.getName().toLowerCase()))
|
||||
final User u = ess.getUser(p);
|
||||
final String displayName = ChatColor.stripColor(u.getDisplayName()).toLowerCase();
|
||||
if (!whois.equals(displayName)
|
||||
&& !displayName.equals(ChatColor.stripColor(ess.getSettings().getNicknamePrefix()) + whois)
|
||||
&& !whois.equalsIgnoreCase(u.getName()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@@ -1,9 +1,8 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.InventoryWorkaround;
|
||||
import com.earth2me.essentials.ItemDb;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.logging.Level;
|
||||
@@ -68,7 +67,7 @@ public class Commandsell extends EssentialsCommand
|
||||
}
|
||||
if (is == null)
|
||||
{
|
||||
is = ItemDb.get(args[0]);
|
||||
is = ess.getItemDb().get(args[0]);
|
||||
}
|
||||
sellItem(user, is, args, false);
|
||||
}
|
||||
@@ -151,11 +150,13 @@ public class Commandsell extends EssentialsCommand
|
||||
}
|
||||
|
||||
charge(user);
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, new ItemStack(is.getType(), amount, is.getDurability()));
|
||||
final ItemStack ris = new ItemStack(is.getType(), amount, is.getDurability());
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, ris);
|
||||
user.updateInventory();
|
||||
Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(worth*amount, ess), ess);
|
||||
user.giveMoney(worth * amount);
|
||||
user.sendMessage(Util.format("itemSold", Util.formatCurrency(worth * amount), amount, Util.formatCurrency(worth)));
|
||||
logger.log(Level.INFO, Util.format("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(), Util.formatCurrency(worth * amount), amount, Util.formatCurrency(worth)));
|
||||
user.sendMessage(Util.format("itemSold", Util.formatCurrency(worth * amount, ess), amount, Util.formatCurrency(worth, ess)));
|
||||
logger.log(Level.INFO, Util.format("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(), Util.formatCurrency(worth * amount, ess), amount, Util.formatCurrency(worth, ess)));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -15,8 +15,31 @@ public class Commandsethome extends EssentialsCommand
|
||||
@Override
|
||||
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
user.setHome(args.length > 0 && args[0].equalsIgnoreCase("default"));
|
||||
if (args.length > 0)
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
user.setHome(args[0].equalsIgnoreCase("default"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (user.isAuthorized("essentials.sethome.others"))
|
||||
{
|
||||
User usersHome = ess.getUser(ess.getServer().getPlayer(args[0]));
|
||||
if(usersHome == null)
|
||||
{
|
||||
usersHome = ess.getOfflineUser(args[0]);
|
||||
}
|
||||
usersHome.setHome(user.getLocation(), args[1].equalsIgnoreCase("default"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
user.setHome(false);
|
||||
}
|
||||
charge(user);
|
||||
user.sendMessage(Util.i18n("homeSet"));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
|
||||
|
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.ItemDb;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -23,7 +21,7 @@ public class Commandsetworth extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
ItemStack stack = ItemDb.get(args[0]);
|
||||
ItemStack stack = ess.getItemDb().get(args[0]);
|
||||
charge(user);
|
||||
ess.getWorth().setPrice(stack, Double.parseDouble(args[1]));
|
||||
user.sendMessage(Util.i18n("worthSet"));
|
||||
|
@@ -5,7 +5,10 @@ import com.earth2me.essentials.Util;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
<<<<<<< HEAD
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
=======
|
||||
>>>>>>> master
|
||||
import org.bukkit.craftbukkit.block.CraftCreatureSpawner;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import net.minecraft.server.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
@@ -13,7 +12,6 @@ import net.minecraft.server.PathEntity;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.entity.CraftCreeper;
|
||||
import org.bukkit.craftbukkit.entity.CraftSheep;
|
||||
import org.bukkit.craftbukkit.entity.CraftSlime;
|
||||
@@ -60,6 +58,12 @@ public class Commandspawnmob extends EssentialsCommand
|
||||
}
|
||||
}
|
||||
|
||||
if (ess.getSettings().getProtectPreventSpawn(mobType.toLowerCase())
|
||||
|| (mountType != null && ess.getSettings().getProtectPreventSpawn(mountType.toLowerCase())))
|
||||
{
|
||||
user.sendMessage(Util.i18n("unableToSpawnMob"));
|
||||
return;
|
||||
}
|
||||
|
||||
Entity spawnedMob = null;
|
||||
Mob mob = null;
|
||||
@@ -224,7 +228,8 @@ public class Commandspawnmob extends EssentialsCommand
|
||||
{
|
||||
((CraftWolf)spawned).setAngry(true);
|
||||
}
|
||||
if ("Creeper".equalsIgnoreCase(type) && data.equalsIgnoreCase("powered")) {
|
||||
if ("Creeper".equalsIgnoreCase(type) && data.equalsIgnoreCase("powered"))
|
||||
{
|
||||
((CraftCreeper)spawned).setPowered(true);
|
||||
}
|
||||
}
|
||||
|
@@ -2,8 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
|
||||
@@ -16,37 +14,26 @@ public class Commandtempban extends EssentialsCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
User p = null;
|
||||
try
|
||||
final User player = getPlayer(server, args, 0, true);
|
||||
if (player.isAuthorized("essentials.tempban.exempt"))
|
||||
{
|
||||
p = getPlayer(server, args, 0);
|
||||
}
|
||||
catch (NoSuchFieldException ex)
|
||||
{
|
||||
p = ess.getOfflineUser(args[0]);
|
||||
}
|
||||
if (p == null)
|
||||
{
|
||||
sender.sendMessage(Util.format("playerNotFound"));
|
||||
sender.sendMessage(Util.i18n("tempbanExempt"));
|
||||
return;
|
||||
}
|
||||
final String time = getFinalArg(args, 1);
|
||||
final long banTimestamp = Util.parseDateDiff(time, true);
|
||||
|
||||
String time = getFinalArg(args, 1);
|
||||
long banTimestamp = Util.parseDateDiff(time, true);
|
||||
|
||||
p = ess.getUser(server.matchPlayer(args[0]).get(0));
|
||||
String banReason = Util.format("tempBanned", Util.formatDateDiff(banTimestamp));
|
||||
p.setBanReason(banReason);
|
||||
p.setBanTimeout(banTimestamp);
|
||||
p.kickPlayer(banReason);
|
||||
((CraftServer)server).getHandle().a(p.getName());
|
||||
sender.sendMessage(Util.format("playerBanned", p.getName()));
|
||||
Essentials.getStatic().loadBanList();
|
||||
final String banReason = Util.format("tempBanned", Util.formatDateDiff(banTimestamp));
|
||||
player.setBanReason(banReason);
|
||||
player.setBanTimeout(banTimestamp);
|
||||
player.kickPlayer(banReason);
|
||||
ess.getBans().banByName(player.getName());
|
||||
server.broadcastMessage(Util.format("playerBanned", player.getName(), banReason));
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,8 @@ public class Commandtime extends EssentialsCommand
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
if (args.length < 2)
|
||||
{
|
||||
if (user.isAuthorized("essentials.time.world"))
|
||||
{
|
||||
final World world = user.getWorld();
|
||||
@@ -30,24 +32,17 @@ public class Commandtime extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
if (user.isAuthorized("essentials.time.player"))
|
||||
{
|
||||
|
||||
long time = user.getPlayerTime();
|
||||
time -= time % 24000;
|
||||
if ("day".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
final World world = user.getWorld();
|
||||
user.setPlayerTime(time + 24000 - world.getTime(), true);
|
||||
return;
|
||||
charge(user);
|
||||
setPlayerTime(user, commandLabel);
|
||||
}
|
||||
if ("night".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
final World world = user.getWorld();
|
||||
user.setPlayerTime(time + 37700 - world.getTime(), true);
|
||||
return;
|
||||
}
|
||||
throw new Exception(Util.i18n("onlyDayNight"));
|
||||
else
|
||||
{
|
||||
if (user.isAuthorized("essentials.time.others"))
|
||||
{
|
||||
User u = getPlayer(server, args, 1);
|
||||
charge(user);
|
||||
setPlayerTime(u, args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,10 +54,18 @@ public class Commandtime extends EssentialsCommand
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
if (args.length < 2)
|
||||
{
|
||||
for (World world : server.getWorlds())
|
||||
{
|
||||
setWorldTime(world, args[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
User u = getPlayer(server, args, 1);
|
||||
setPlayerTime(u, args[0]);
|
||||
}
|
||||
|
||||
sender.sendMessage(Util.i18n("timeSet"));
|
||||
}
|
||||
@@ -83,4 +86,27 @@ public class Commandtime extends EssentialsCommand
|
||||
}
|
||||
throw new Exception(Util.i18n("onlyDayNight"));
|
||||
}
|
||||
|
||||
private void setPlayerTime(final User user, final String timeString) throws Exception
|
||||
{
|
||||
long time = user.getPlayerTime();
|
||||
time -= time % 24000;
|
||||
if ("day".equalsIgnoreCase(timeString))
|
||||
{
|
||||
final World world = user.getWorld();
|
||||
user.setPlayerTime(time + 24000 - world.getTime(), true);
|
||||
return;
|
||||
}
|
||||
if ("night".equalsIgnoreCase(timeString))
|
||||
{
|
||||
final World world = user.getWorld();
|
||||
user.setPlayerTime(time + 37700 - world.getTime(), true);
|
||||
return;
|
||||
}
|
||||
if ("reset".equalsIgnoreCase(timeString))
|
||||
{
|
||||
user.resetPlayerTime();
|
||||
}
|
||||
throw new Exception(Util.i18n("onlyDayNight"));
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
|
||||
@@ -22,8 +21,7 @@ public class Commandtogglejail extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
User p = getPlayer(server, args, 0);
|
||||
|
||||
User p = getPlayer(server, args, 0, true);
|
||||
if (p.isAuthorized("essentials.jail.exempt"))
|
||||
{
|
||||
sender.sendMessage(Util.i18n("mayNotJail"));
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
@@ -21,7 +21,7 @@ public class Commandtop extends EssentialsCommand
|
||||
int topZ = user.getLocation().getBlockZ();
|
||||
int topY = user.getWorld().getHighestBlockYAt(topX, topZ);
|
||||
charge(user);
|
||||
user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Charge(this.getName(), ess));
|
||||
user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Trade(this.getName(), ess));
|
||||
user.sendMessage(Util.i18n("teleportTop"));
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.Console;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
@@ -30,7 +30,7 @@ public class Commandtp extends EssentialsCommand
|
||||
throw new Exception(Util.format("teleportDisabled", p.getDisplayName()));
|
||||
}
|
||||
user.sendMessage(Util.i18n("teleporting"));
|
||||
Charge charge = new Charge(this.getName(), ess);
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
user.getTeleport().teleport(p, charge);
|
||||
break;
|
||||
@@ -44,7 +44,7 @@ public class Commandtp extends EssentialsCommand
|
||||
charge(user);
|
||||
User target = getPlayer(server, args, 0);
|
||||
User toPlayer = getPlayer(server, args, 1);
|
||||
target.getTeleport().now(toPlayer);
|
||||
target.getTeleport().now(toPlayer, false);
|
||||
target.sendMessage(Util.format("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName()));
|
||||
break;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class Commandtp extends EssentialsCommand
|
||||
sender.sendMessage(Util.i18n("teleporting"));
|
||||
User target = getPlayer(server, args, 0);
|
||||
User toPlayer = getPlayer(server, args, 1);
|
||||
target.getTeleport().now(toPlayer);
|
||||
target.getTeleport().now(toPlayer, false);
|
||||
target.sendMessage(Util.format("teleportAtoB", Console.NAME, toPlayer.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
@@ -23,7 +23,7 @@ public class Commandtpaccept extends EssentialsCommand
|
||||
throw new Exception(Util.i18n("noPendingRequest"));
|
||||
}
|
||||
|
||||
Charge charge = new Charge(this.getName(), ess);
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
if (user.isTeleportRequestHere())
|
||||
{
|
||||
charge.isAffordableFor(user);
|
||||
|
@@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -46,15 +45,11 @@ public class Commandtpall extends EssentialsCommand
|
||||
}
|
||||
try
|
||||
{
|
||||
u.getTeleport().now(p);
|
||||
u.getTeleport().now(p, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sender.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
logger.log(Level.WARNING, ex.getMessage(), ex);
|
||||
}
|
||||
ess.showError(sender, ex, getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
@@ -21,7 +21,7 @@ public class Commandtphere extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(Util.format("teleportDisabled", p.getDisplayName()));
|
||||
}
|
||||
p.getTeleport().teleport(user, new Charge(this.getName(), ess));
|
||||
p.getTeleport().teleport(user, new Trade(this.getName(), ess));
|
||||
user.sendMessage(Util.i18n("teleporting"));
|
||||
p.sendMessage(Util.i18n("teleporting"));
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ public class Commandtpo extends EssentialsCommand
|
||||
//Just basically the old tp command
|
||||
User p = getPlayer(server, args, 0);
|
||||
charge(user);
|
||||
user.getTeleport().now(p);
|
||||
user.getTeleport().now(p, false);
|
||||
user.sendMessage(Util.i18n("teleporting"));
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ public class Commandtpohere extends EssentialsCommand
|
||||
//Just basically the old tphere command
|
||||
User p = getPlayer(server, args, 0);
|
||||
charge(user);
|
||||
p.getTeleport().now(user);
|
||||
p.getTeleport().now(user, false);
|
||||
user.sendMessage(Util.i18n("teleporting"));
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
@@ -26,7 +26,7 @@ public class Commandtppos extends EssentialsCommand
|
||||
int y = Integer.parseInt(args[1]);
|
||||
int z = Integer.parseInt(args[2]);
|
||||
Location l = new Location(user.getWorld(), x, y, z);
|
||||
Charge charge = new Charge(this.getName(), ess);
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
user.sendMessage(Util.i18n("teleporting"));
|
||||
user.getTeleport().teleport(l, charge);
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
|
||||
public class Commandunban extends EssentialsCommand
|
||||
@@ -14,15 +14,15 @@ public class Commandunban extends EssentialsCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
((CraftServer)server).getHandle().b(args[0]);
|
||||
User u = getPlayer(server, args, 0, true);
|
||||
ess.getBans().unbanByName(u.getName());
|
||||
sender.sendMessage(Util.i18n("unbannedPlayer"));
|
||||
ess.loadBanList();
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
|
||||
public class Commandunbanip extends EssentialsCommand
|
||||
@@ -14,15 +13,14 @@ public class Commandunbanip extends EssentialsCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
((CraftServer)server).getHandle().d(args[0]);
|
||||
ess.getBans().unbanByIp(args[0]);
|
||||
sender.sendMessage(Util.i18n("unbannedIP"));
|
||||
ess.loadBanList();
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.InventoryWorkaround;
|
||||
import com.earth2me.essentials.ItemDb;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.List;
|
||||
@@ -56,7 +55,7 @@ public class Commandunlimited extends EssentialsCommand
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = ItemDb.get(args[0], 1);
|
||||
ItemStack stack = ess.getItemDb().get(args[0], 1);
|
||||
|
||||
String itemname = stack.getType().toString().toLowerCase().replace("_", "");
|
||||
if (!user.isAuthorized("essentials.unlimited.item-all")
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
@@ -73,7 +73,7 @@ public class Commandwarp extends EssentialsCommand
|
||||
|
||||
private void warpUser(User user, String name) throws Exception
|
||||
{
|
||||
Charge charge = new Charge(this.getName(), ess);
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
if (ess.getSettings().getPerWarpPermission())
|
||||
{
|
||||
|
@@ -41,7 +41,7 @@ public class Commandwhois extends EssentialsCommand
|
||||
sender.sendMessage(Util.format("whoisLocation", u.getLocation().getWorld().getName(), u.getLocation().getBlockX(), u.getLocation().getBlockY(), u.getLocation().getBlockZ()));
|
||||
if (!ess.getSettings().isEcoDisabled())
|
||||
{
|
||||
sender.sendMessage(Util.format("whoisMoney", Util.formatCurrency(u.getMoney())));
|
||||
sender.sendMessage(Util.format("whoisMoney", Util.formatCurrency(u.getMoney(), ess)));
|
||||
}
|
||||
sender.sendMessage(u.isAfk()
|
||||
? Util.i18n("whoisStatusAway")
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@@ -68,7 +68,7 @@ public class Commandworld extends EssentialsCommand
|
||||
Location loc = user.getLocation();
|
||||
loc = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);
|
||||
|
||||
Charge charge = new Charge(this.getName(), ess);
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
user.getTeleport().teleport(loc, charge);
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import com.earth2me.essentials.ItemDb;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -22,7 +21,7 @@ public class Commandworth extends EssentialsCommand
|
||||
|
||||
if (args.length > 0)
|
||||
{
|
||||
is = ItemDb.get(args[0]);
|
||||
is = ess.getItemDb().get(args[0]);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -49,13 +48,13 @@ public class Commandworth extends EssentialsCommand
|
||||
? Util.format("worthMeta",
|
||||
is.getType().toString().toLowerCase().replace("_", ""),
|
||||
is.getDurability(),
|
||||
Util.formatCurrency(worth * amount),
|
||||
Util.formatCurrency(worth * amount, ess),
|
||||
amount,
|
||||
Util.formatCurrency(worth))
|
||||
Util.formatCurrency(worth, ess))
|
||||
: Util.format("worth",
|
||||
is.getType().toString().toLowerCase().replace("_", ""),
|
||||
Util.formatCurrency(worth * amount),
|
||||
Util.formatCurrency(worth * amount, ess),
|
||||
amount,
|
||||
Util.formatCurrency(worth)));
|
||||
Util.formatCurrency(worth, ess)));
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,10 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Charge;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import java.util.List;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import org.bukkit.entity.Player;
|
||||
import com.earth2me.essentials.User;
|
||||
@@ -35,10 +34,23 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||
}
|
||||
|
||||
protected User getPlayer(Server server, String[] args, int pos) throws NoSuchFieldException, NotEnoughArgumentsException
|
||||
{
|
||||
return getPlayer(server, args, pos, false);
|
||||
}
|
||||
|
||||
protected User getPlayer(Server server, String[] args, int pos, boolean getOffline) throws NoSuchFieldException, NotEnoughArgumentsException
|
||||
{
|
||||
if (args.length <= pos) throw new NotEnoughArgumentsException();
|
||||
List<Player> matches = server.matchPlayer(args[pos]);
|
||||
if (matches.size() < 1) throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
||||
|
||||
if (matches.size() < 1)
|
||||
{
|
||||
if (!getOffline) throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
||||
User u = ess.getOfflineUser(args[pos]);
|
||||
if (u == null) throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
||||
return u;
|
||||
}
|
||||
|
||||
for (Player p : matches)
|
||||
{
|
||||
if (p.getDisplayName().startsWith(args[pos]))
|
||||
@@ -89,7 +101,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
Charge charge = new Charge(this.getName(), ess);
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
charge.charge(ess.getUser((Player)sender));
|
||||
}
|
||||
}
|
||||
|
@@ -68,6 +68,14 @@ public class Methods {
|
||||
if(method.getDescription().getName().equals(name)) plugin = method; else plugin = manager.getPlugin(name);
|
||||
if(plugin == null) continue;
|
||||
|
||||
if(!plugin.isEnabled()) {
|
||||
this.self = true;
|
||||
//Logger.getLogger("Minecraft").log(Level.SEVERE, name + " Plugin was found, but not enabled before Essentials. Read the Essentials thread for help.");
|
||||
//manager.enablePlugin(plugin);
|
||||
}
|
||||
|
||||
if(plugin == null) continue;
|
||||
|
||||
Method current = this.createMethod(plugin);
|
||||
if(current == null) continue;
|
||||
|
||||
@@ -91,7 +99,9 @@ public class Methods {
|
||||
break;
|
||||
}
|
||||
|
||||
if(count != 0) {
|
||||
if(this.preferred.isEmpty()) this.Method = attached;
|
||||
|
||||
if(count == 0) {
|
||||
if(this.preferred.equalsIgnoreCase(attached.getName()))
|
||||
this.Method = attached;
|
||||
} else {
|
||||
|
@@ -78,7 +78,6 @@ public class BOSE implements Method {
|
||||
|
||||
public boolean add(double amount) {
|
||||
int IntAmount = (int)Math.ceil(amount);
|
||||
int balance = (int)this.balance();
|
||||
return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false);
|
||||
}
|
||||
|
||||
|
475
Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
Normal file
475
Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
Normal file
@@ -0,0 +1,475 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class EssentialsSign
|
||||
{
|
||||
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
|
||||
protected transient final String signName;
|
||||
private static final String FORMAT_SUCCESS = "§1[%s]";
|
||||
private static final String FORMAT_TEMPLATE = "[%s]";
|
||||
private static final String FORMAT_FAIL = "§4[%s]";
|
||||
|
||||
public EssentialsSign(final String signName)
|
||||
{
|
||||
this.signName = signName;
|
||||
}
|
||||
|
||||
public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess)
|
||||
{
|
||||
final ISign sign = new EventSign(event);
|
||||
sign.setLine(0, String.format(FORMAT_FAIL, this.signName));
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase() + ".create")
|
||||
|| user.isAuthorized("essentials.signs.create." + signName.toLowerCase())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
final boolean ret = onSignCreate(sign, user, getUsername(user), ess);
|
||||
if (ret)
|
||||
{
|
||||
sign.setLine(0, getSuccessName());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getSuccessName()
|
||||
{
|
||||
return String.format(FORMAT_SUCCESS, this.signName);
|
||||
}
|
||||
|
||||
public String getTemplateName()
|
||||
{
|
||||
return String.format(FORMAT_TEMPLATE, this.signName);
|
||||
}
|
||||
|
||||
private String getUsername(final User user)
|
||||
{
|
||||
return user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
|
||||
}
|
||||
|
||||
public final boolean onSignInteract(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
final ISign sign = new BlockSign(block);
|
||||
final User user = ess.getUser(player);
|
||||
try
|
||||
{
|
||||
return (user.isAuthorized("essentials.signs." + signName.toLowerCase() + ".use")
|
||||
|| user.isAuthorized("essentials.signs.use." + signName.toLowerCase()))
|
||||
&& onSignInteract(sign, user, getUsername(user), ess);
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
return false;
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean onSignBreak(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
final ISign sign = new BlockSign(block);
|
||||
final User user = ess.getUser(player);
|
||||
try
|
||||
{
|
||||
return (user.isAuthorized("essentials.signs." + signName.toLowerCase() + ".break")
|
||||
|| user.isAuthorized("essentials.signs.break." + signName.toLowerCase()))
|
||||
&& onSignBreak(sign, user, getUsername(user), ess);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean onSignBreak(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean onBlockPlace(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
User user = ess.getUser(player);
|
||||
try
|
||||
{
|
||||
return onBlockPlace(block, user, getUsername(user), ess);
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean onBlockInteract(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
User user = ess.getUser(player);
|
||||
try
|
||||
{
|
||||
return onBlockInteract(block, user, getUsername(user), ess);
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean onBlockBreak(final Block block, final Player player, final IEssentials ess)
|
||||
{
|
||||
User user = ess.getUser(player);
|
||||
try
|
||||
{
|
||||
return onBlockBreak(block, user, getUsername(user), ess);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showError(user, ex, signName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onBlockExplode(final Block block, final IEssentials ess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onBlockBurn(final Block block, final IEssentials ess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean checkIfBlockBreaksSigns(final Block block)
|
||||
{
|
||||
if (block.getFace(BlockFace.UP).getType() == Material.SIGN_POST)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
final BlockFace[] directions = new BlockFace[]
|
||||
{
|
||||
BlockFace.NORTH,
|
||||
BlockFace.EAST,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST
|
||||
};
|
||||
for (BlockFace blockFace : directions)
|
||||
{
|
||||
final Block signblock = block.getFace(blockFace);
|
||||
if (signblock.getType() == Material.WALL_SIGN)
|
||||
{
|
||||
final org.bukkit.material.Sign sign = (org.bukkit.material.Sign)signblock.getState().getData();
|
||||
if (sign.getFacing() == blockFace)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean onBlockPlace(final Block block, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean onBlockInteract(final Block block, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean onBlockBreak(final Block block, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set<Material> getBlocks()
|
||||
{
|
||||
return EMPTY_SET;
|
||||
}
|
||||
|
||||
protected final void validateTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
|
||||
{
|
||||
final String line = sign.getLine(index).trim();
|
||||
if (line.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
final Trade trade = getTrade(sign, index, 0, ess);
|
||||
final Double money = trade.getMoney();
|
||||
if (money != null)
|
||||
{
|
||||
sign.setLine(index, Util.formatCurrency(money, ess));
|
||||
}
|
||||
}
|
||||
|
||||
protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex,
|
||||
final User player, final IEssentials ess) throws SignException
|
||||
{
|
||||
final Trade trade = getTrade(sign, amountIndex, itemIndex, player, ess);
|
||||
final ItemStack item = trade.getItemStack();
|
||||
sign.setLine(amountIndex, Integer.toString(item.getAmount()));
|
||||
sign.setLine(itemIndex, sign.getLine(itemIndex).trim());
|
||||
}
|
||||
|
||||
protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex,
|
||||
final User player, final IEssentials ess) throws SignException
|
||||
{
|
||||
|
||||
final ItemStack item = getItemStack(sign.getLine(itemIndex), 1, ess);
|
||||
final int amount = Math.min(getIntegerPositive(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize());
|
||||
if (item.getTypeId() == 0 || amount < 1)
|
||||
{
|
||||
throw new SignException(Util.i18n("moreThanZero"));
|
||||
}
|
||||
item.setAmount(amount);
|
||||
return new Trade(item, ess);
|
||||
}
|
||||
|
||||
protected final void validateInteger(final ISign sign, final int index) throws SignException
|
||||
{
|
||||
final String line = sign.getLine(index).trim();
|
||||
if (line.isEmpty())
|
||||
{
|
||||
throw new SignException("Empty line " + index);
|
||||
}
|
||||
final int quantity = getIntegerPositive(line);
|
||||
sign.setLine(index, Integer.toString(quantity));
|
||||
}
|
||||
|
||||
protected final int getIntegerPositive(final String line) throws SignException
|
||||
{
|
||||
final int quantity = getInteger(line);
|
||||
if (quantity < 1)
|
||||
{
|
||||
throw new SignException(Util.i18n("moreThanZero"));
|
||||
}
|
||||
return quantity;
|
||||
}
|
||||
|
||||
protected final int getInteger(final String line) throws SignException
|
||||
{
|
||||
try
|
||||
{
|
||||
final int quantity = Integer.parseInt(line);
|
||||
|
||||
return quantity;
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
throw new SignException("Invalid sign", ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected final ItemStack getItemStack(final String itemName, final int quantity, final IEssentials ess) throws SignException
|
||||
{
|
||||
try
|
||||
{
|
||||
final ItemStack item = ess.getItemDb().get(itemName);
|
||||
item.setAmount(quantity);
|
||||
return item;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new SignException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected final Double getMoney(final String line) throws SignException
|
||||
{
|
||||
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
|
||||
return isMoney ? getDoublePositive(line.substring(1)) : null;
|
||||
}
|
||||
|
||||
protected final Double getDoublePositive(final String line) throws SignException
|
||||
{
|
||||
final double quantity = getDouble(line);
|
||||
if (Math.round(quantity*100.0) < 1.0)
|
||||
{
|
||||
throw new SignException(Util.i18n("moreThanZero"));
|
||||
}
|
||||
return quantity;
|
||||
}
|
||||
|
||||
protected final Double getDouble(final String line) throws SignException
|
||||
{
|
||||
try
|
||||
{
|
||||
return Double.parseDouble(line);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
throw new SignException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected final Trade getTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
|
||||
{
|
||||
return getTrade(sign, index, 1, ess);
|
||||
}
|
||||
|
||||
protected final Trade getTrade(final ISign sign, final int index, final int decrement, final IEssentials ess) throws SignException
|
||||
{
|
||||
final String line = sign.getLine(index).trim();
|
||||
if (line.isEmpty())
|
||||
{
|
||||
return new Trade(signName.toLowerCase() + "sign", ess);
|
||||
}
|
||||
|
||||
final Double money = getMoney(line);
|
||||
if (money == null)
|
||||
{
|
||||
final String[] split = line.split("[ :]+", 2);
|
||||
if (split.length != 2)
|
||||
{
|
||||
throw new SignException(Util.i18n("invalidCharge"));
|
||||
}
|
||||
final int quantity = getIntegerPositive(split[0]);
|
||||
|
||||
final String item = split[1].toLowerCase();
|
||||
if (item.equalsIgnoreCase("times"))
|
||||
{
|
||||
sign.setLine(index, (quantity - decrement) + " times");
|
||||
return new Trade(signName.toLowerCase() + "sign", ess);
|
||||
}
|
||||
else
|
||||
{
|
||||
final ItemStack stack = getItemStack(item, quantity, ess);
|
||||
sign.setLine(index, quantity + " " + item);
|
||||
return new Trade(stack, ess);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Trade(money, ess);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class EventSign implements ISign
|
||||
{
|
||||
private final transient SignChangeEvent event;
|
||||
private final transient Block block;
|
||||
|
||||
public EventSign(final SignChangeEvent event)
|
||||
{
|
||||
this.event = event;
|
||||
this.block = event.getBlock();
|
||||
}
|
||||
|
||||
public final String getLine(final int index)
|
||||
{
|
||||
return event.getLine(index);
|
||||
}
|
||||
|
||||
public final void setLine(final int index, final String text)
|
||||
{
|
||||
event.setLine(index, text);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return block;
|
||||
}
|
||||
|
||||
public void updateSign()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class BlockSign implements ISign
|
||||
{
|
||||
private final transient Sign sign;
|
||||
private final transient Block block;
|
||||
|
||||
public BlockSign(final Block block)
|
||||
{
|
||||
this.block = block;
|
||||
this.sign = new CraftSign(block);
|
||||
}
|
||||
|
||||
public final String getLine(final int index)
|
||||
{
|
||||
return sign.getLine(index);
|
||||
}
|
||||
|
||||
public final void setLine(final int index, final String text)
|
||||
{
|
||||
sign.setLine(index, text);
|
||||
}
|
||||
|
||||
public final Block getBlock()
|
||||
{
|
||||
return block;
|
||||
}
|
||||
|
||||
public final void updateSign()
|
||||
{
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface ISign
|
||||
{
|
||||
String getLine(final int index);
|
||||
|
||||
void setLine(final int index, final String text);
|
||||
|
||||
public Block getBlock();
|
||||
|
||||
void updateSign();
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
|
||||
|
||||
public class SignBalance extends EssentialsSign
|
||||
{
|
||||
public SignBalance()
|
||||
{
|
||||
super("Balance");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
player.sendMessage(Util.format("balance", player.getMoney()));
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,187 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
|
||||
public class SignBlockListener extends BlockListener
|
||||
{
|
||||
private final transient IEssentials ess;
|
||||
private final static Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
|
||||
public SignBlockListener(IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(final BlockBreakEvent event)
|
||||
{
|
||||
if (event.isCancelled() || ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (protectSignsAndBlocks(event.getBlock(), event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean protectSignsAndBlocks(final Block block, final Player player)
|
||||
{
|
||||
final int mat = block.getTypeId();
|
||||
if (mat == Material.SIGN_POST.getId() || mat == Material.WALL_SIGN.getId())
|
||||
{
|
||||
final Sign csign = new CraftSign(block);
|
||||
for (Signs signs : Signs.values())
|
||||
{
|
||||
final EssentialsSign sign = signs.getSign();
|
||||
if (csign.getLine(0).equalsIgnoreCase(sign.getSuccessName())
|
||||
&& !sign.onSignBreak(block, player, ess))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// prevent any signs be broken by destroying the block they are attached to
|
||||
if (EssentialsSign.checkIfBlockBreaksSigns(block))
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Prevented that a block was broken next to a sign.");
|
||||
return true;
|
||||
}
|
||||
for (Signs signs : Signs.values())
|
||||
{
|
||||
final EssentialsSign sign = signs.getSign();
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockBreak(block, player, ess))
|
||||
{
|
||||
LOGGER.log(Level.INFO, "A block was protected by a sign.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignChange(final SignChangeEvent event)
|
||||
{
|
||||
if (event.isCancelled() || ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (Signs signs : Signs.values())
|
||||
{
|
||||
final EssentialsSign sign = signs.getSign();
|
||||
if (event.getLine(0).equalsIgnoreCase(sign.getSuccessName()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (event.getLine(0).equalsIgnoreCase(sign.getTemplateName())
|
||||
&& !sign.onSignCreate(event, ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
if (user.isAuthorized("essentials.signs.color"))
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
event.setLine(i, event.getLine(i).replaceAll("&([0-9a-f])", "§$1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlace(final BlockPlaceEvent event)
|
||||
{
|
||||
if (event.isCancelled() || ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Block against = event.getBlockAgainst();
|
||||
if (against.getType() == Material.WALL_SIGN
|
||||
|| against.getType() == Material.SIGN_POST)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Block block = event.getBlock();
|
||||
if (block.getType() == Material.WALL_SIGN
|
||||
|| block.getType() == Material.SIGN_POST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (Signs signs : Signs.values())
|
||||
{
|
||||
final EssentialsSign sign = signs.getSign();
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockPlace(block, event.getPlayer(), ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBurn(final BlockBurnEvent event)
|
||||
{
|
||||
if (event.isCancelled() || ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Block block = event.getBlock();
|
||||
if ((block.getType() == Material.WALL_SIGN
|
||||
|| block.getType() == Material.SIGN_POST
|
||||
|| EssentialsSign.checkIfBlockBreaksSigns(block)))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
for (Signs signs : Signs.values())
|
||||
{
|
||||
final EssentialsSign sign = signs.getSign();
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockBurn(block, ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockIgnite(final BlockIgniteEvent event)
|
||||
{
|
||||
if (event.isCancelled() || ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (protectSignsAndBlocks(event.getBlock(), event.getPlayer()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
35
Essentials/src/com/earth2me/essentials/signs/SignBuy.java
Normal file
35
Essentials/src/com/earth2me/essentials/signs/SignBuy.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
|
||||
|
||||
public class SignBuy extends EssentialsSign
|
||||
{
|
||||
public SignBuy()
|
||||
{
|
||||
super("Buy");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
validateTrade(sign, 1, 2, player, ess);
|
||||
validateTrade(sign, 3, ess);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||
{
|
||||
final Trade items = getTrade(sign, 1, 2, player, ess);
|
||||
final Trade charge = getTrade(sign, 3, ess);
|
||||
charge.isAffordableFor(player);
|
||||
items.pay(player);
|
||||
charge.charge(player);
|
||||
Trade.log("Sign", "Buy", "Interact", username, charge, username, items, ess);
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.minecraft.server.InventoryPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
|
||||
|
||||
|
||||
public class SignDisposal extends EssentialsSign
|
||||
{
|
||||
public SignDisposal()
|
||||
{
|
||||
super("Disposal");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess)
|
||||
{
|
||||
final CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(player.getHandle()));
|
||||
inv.clear();
|
||||
player.showInventory(inv);
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
|
||||
|
||||
public class SignEntityListener extends EntityListener
|
||||
{
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public SignEntityListener(IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event)
|
||||
{
|
||||
for (Block block : event.blockList())
|
||||
{
|
||||
if ((block.getType() == Material.WALL_SIGN
|
||||
|| block.getType() == Material.SIGN_POST
|
||||
|| EssentialsSign.checkIfBlockBreaksSigns(block)))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
for (Signs signs : Signs.values())
|
||||
{
|
||||
final EssentialsSign sign = signs.getSign();
|
||||
if (sign.getBlocks().contains(block.getType()))
|
||||
{
|
||||
event.setCancelled(!sign.onBlockExplode(block, ess));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
|
||||
public class SignException extends Exception
|
||||
{
|
||||
public SignException(final String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SignException(final String message, final Throwable throwable)
|
||||
{
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
38
Essentials/src/com/earth2me/essentials/signs/SignFree.java
Normal file
38
Essentials/src/com/earth2me/essentials/signs/SignFree.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.InventoryWorkaround;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.minecraft.server.InventoryPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class SignFree extends EssentialsSign
|
||||
{
|
||||
public SignFree()
|
||||
{
|
||||
super("Free");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
getItemStack(sign.getLine(1), 1, ess);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
final ItemStack item = getItemStack(sign.getLine(1), 1, ess);
|
||||
item.setAmount(item.getType().getMaxStackSize()*9*4);
|
||||
final CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(player.getHandle()));
|
||||
inv.clear();
|
||||
InventoryWorkaround.addItem(inv, true, item);
|
||||
player.showInventory(inv);
|
||||
Trade.log("Sign", "Free", "Interact", username, null, username, new Trade(item, ess), ess);
|
||||
return true;
|
||||
}
|
||||
}
|
34
Essentials/src/com/earth2me/essentials/signs/SignHeal.java
Normal file
34
Essentials/src/com/earth2me/essentials/signs/SignHeal.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
|
||||
|
||||
public class SignHeal extends EssentialsSign
|
||||
{
|
||||
public SignHeal()
|
||||
{
|
||||
super("Heal");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
validateTrade(sign, 1, ess);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
||||
{
|
||||
final Trade charge = getTrade(sign, 1, ess);
|
||||
charge.isAffordableFor(player);
|
||||
player.setHealth(20);
|
||||
player.sendMessage(Util.i18n("youAreHealed"));
|
||||
charge.charge(player);
|
||||
return true;
|
||||
}
|
||||
}
|
32
Essentials/src/com/earth2me/essentials/signs/SignMail.java
Normal file
32
Essentials/src/com/earth2me/essentials/signs/SignMail.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SignMail extends EssentialsSign
|
||||
{
|
||||
public SignMail()
|
||||
{
|
||||
super("Mail");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
final List<String> mail = player.getMails();
|
||||
if (mail.isEmpty())
|
||||
{
|
||||
player.sendMessage(Util.i18n("noNewMail"));
|
||||
return false;
|
||||
}
|
||||
for (String s : mail)
|
||||
{
|
||||
player.sendMessage(s);
|
||||
}
|
||||
player.sendMessage(Util.i18n("markMailAsRead"));
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
|
||||
public class SignPlayerListener extends PlayerListener
|
||||
{
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public SignPlayerListener(IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.isCancelled() || ess.getSettings().areSignsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Block block = event.getClickedBlock();
|
||||
final int mat = block.getTypeId();
|
||||
if (mat == Material.SIGN_POST.getId() || mat == Material.WALL_SIGN.getId())
|
||||
{
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
final Sign csign = new CraftSign(block);
|
||||
for (Signs signs : Signs.values())
|
||||
{
|
||||
final EssentialsSign sign = signs.getSign();
|
||||
if (csign.getLine(0).equalsIgnoreCase(sign.getSuccessName()))
|
||||
{
|
||||
sign.onSignInteract(block, event.getPlayer(), ess);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Signs signs : Signs.values())
|
||||
{
|
||||
final EssentialsSign sign = signs.getSign();
|
||||
if (sign.getBlocks().contains(block.getType())
|
||||
&& !sign.onBlockInteract(block, event.getPlayer(), ess))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user