mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-25 10:38:00 +01:00
Merge remote branch 'remotes/origin/master' into release
This commit is contained in:
commit
c7c7e5e4ce
@ -49,6 +49,9 @@ import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event.Type;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.world.WorldListener;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
@ -243,6 +246,10 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
pm.registerEvent(Type.ENTITY_REGAIN_HEALTH, entityListener, Priority.Lowest, this);
|
||||
pm.registerEvent(Type.FOOD_LEVEL_CHANGE, entityListener, Priority.Lowest, this);
|
||||
|
||||
final EssentialsWorldListener worldListener = new EssentialsWorldListener(this);
|
||||
pm.registerEvent(Type.WORLD_LOAD, worldListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Type.WORLD_UNLOAD, worldListener, Priority.Monitor, this);
|
||||
|
||||
//TODO: Check if this should be here, and not above before reload()
|
||||
jails = new Jails(this);
|
||||
confList.add(jails);
|
||||
@ -594,4 +601,46 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
{
|
||||
return i18n;
|
||||
}
|
||||
|
||||
private static class EssentialsWorldListener extends WorldListener implements Runnable {
|
||||
private transient final IEssentials ess;
|
||||
|
||||
public EssentialsWorldListener(IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onWorldLoad(WorldLoadEvent event)
|
||||
{
|
||||
ess.getJails().onReload();
|
||||
ess.getWarps().reloadConfig();
|
||||
for (IConf iConf : ((Essentials)ess).confList)
|
||||
{
|
||||
if (iConf instanceof IEssentialsModule) {
|
||||
iConf.reloadConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldUnload(WorldUnloadEvent event)
|
||||
{
|
||||
ess.getJails().onReload();
|
||||
ess.getWarps().reloadConfig();
|
||||
for (IConf iConf : ((Essentials)ess).confList)
|
||||
{
|
||||
if (iConf instanceof IEssentialsModule) {
|
||||
iConf.reloadConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
ess.reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -282,22 +282,22 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
user.updateActivity(true);
|
||||
usePowertools(event);
|
||||
if (event.getAnimationType() == PlayerAnimationType.ARM_SWING
|
||||
&& user.hasPowerTools() && user.arePowerToolsEnabled())
|
||||
{
|
||||
usePowertools(user);
|
||||
}
|
||||
}
|
||||
|
||||
private void usePowertools(final PlayerAnimationEvent event)
|
||||
private void usePowertools(final User user)
|
||||
{
|
||||
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
final ItemStack is = user.getItemInHand();
|
||||
if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled())
|
||||
int id;
|
||||
if (is == null || (id = is.getTypeId()) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
final List<String> commandList = user.getPowertool(is);
|
||||
final List<String> commandList = user.getPowertool(id);
|
||||
if (commandList == null || commandList.isEmpty())
|
||||
{
|
||||
return;
|
||||
@ -317,7 +317,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
}
|
||||
else
|
||||
{
|
||||
user.getServer().dispatchCommand(event.getPlayer(), command);
|
||||
user.getServer().dispatchCommand(user.getBase(), command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,14 +23,17 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
private transient long lastOnlineActivity;
|
||||
private transient long lastActivity = System.currentTimeMillis();
|
||||
private boolean hidden = false;
|
||||
private transient Location afkPosition;
|
||||
private transient Location afkPosition = null;
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
User(final Player base, final IEssentials ess)
|
||||
{
|
||||
super(base, ess);
|
||||
teleport = new Teleport(this, ess);
|
||||
afkPosition = getLocation();
|
||||
if (isAfk())
|
||||
{
|
||||
afkPosition = getLocation();
|
||||
}
|
||||
}
|
||||
|
||||
User update(final Player base)
|
||||
@ -386,6 +389,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
{
|
||||
afkPosition = getLocation();
|
||||
}
|
||||
else if (!set && isAfk())
|
||||
{
|
||||
afkPosition = null;
|
||||
}
|
||||
super.setAfk(set);
|
||||
}
|
||||
|
||||
|
@ -265,6 +265,11 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
return (List<String>)powertools.get(stack.getTypeId());
|
||||
}
|
||||
|
||||
public List<String> getPowertool(int id)
|
||||
{
|
||||
return (List<String>)powertools.get(id);
|
||||
}
|
||||
|
||||
public void setPowertool(ItemStack stack, List<String> commandList)
|
||||
{
|
||||
if (commandList == null || commandList.isEmpty())
|
||||
|
@ -6,7 +6,6 @@ import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -21,10 +21,11 @@ public class Util
|
||||
{
|
||||
}
|
||||
private final static Logger logger = Logger.getLogger("Minecraft");
|
||||
private final static Pattern INVALIDCHARS = Pattern.compile("[^a-z0-9]");
|
||||
|
||||
public static String sanitizeFileName(String name)
|
||||
public static String sanitizeFileName(final String name)
|
||||
{
|
||||
return name.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9]", "_");
|
||||
return INVALIDCHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
|
||||
}
|
||||
|
||||
public static String formatDateDiff(long date)
|
||||
|
@ -41,7 +41,7 @@ public class Commandhelp extends EssentialsCommand
|
||||
output = new KeywordReplacer(input, user, ess);
|
||||
}
|
||||
final TextPager pager = new TextPager(output);
|
||||
pager.showPage(pageStr, chapterPageStr, "help", user);
|
||||
pager.showPage(pageStr, chapterPageStr, commandLabel, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ public class Commandhome extends EssentialsCommand
|
||||
if (bed != null)
|
||||
{
|
||||
user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
|
||||
return;
|
||||
throw new NoChargeException();
|
||||
}
|
||||
}
|
||||
user.getTeleport().home(player, homeName.toLowerCase(Locale.ENGLISH), charge);
|
||||
@ -64,10 +64,10 @@ public class Commandhome extends EssentialsCommand
|
||||
if (bed != null)
|
||||
{
|
||||
user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
|
||||
return;
|
||||
throw new NoChargeException();
|
||||
}
|
||||
user.getTeleport().respawn(charge, TeleportCause.COMMAND);
|
||||
return;
|
||||
|
||||
}
|
||||
else if (homes.isEmpty())
|
||||
{
|
||||
@ -76,7 +76,6 @@ public class Commandhome extends EssentialsCommand
|
||||
else if (homes.size() == 1 && player.equals(user))
|
||||
{
|
||||
user.getTeleport().home(player, homes.get(0), charge);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -21,6 +21,6 @@ public class Commandinfo extends EssentialsCommand
|
||||
final IText input = new TextInput(sender, "info", true, ess);
|
||||
final IText output = new KeywordReplacer(input, sender, ess);
|
||||
final TextPager pager = new TextPager(output);
|
||||
pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, "info", sender);
|
||||
pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, commandLabel, sender);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,6 @@ public class Commandmotd extends EssentialsCommand
|
||||
final IText input = new TextInput(sender, "motd", true, ess);
|
||||
final IText output = new KeywordReplacer(input, sender, ess);
|
||||
final TextPager pager = new TextPager(output);
|
||||
pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, "motd", sender);
|
||||
pager.showPage(args.length > 0 ? args[0] : null, args.length > 1 ? args[1] : null, commandLabel, sender);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.DescParseTickFormat;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -16,11 +17,13 @@ import org.bukkit.plugin.Plugin;
|
||||
public class KeywordReplacer implements IText
|
||||
{
|
||||
private final transient IText input;
|
||||
private final transient List<String> replaced;
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess)
|
||||
{
|
||||
this.input = input;
|
||||
this.replaced = new ArrayList<String>(this.input.getLines().size());
|
||||
this.ess = ess;
|
||||
replaceKeywords(sender);
|
||||
}
|
||||
@ -41,7 +44,7 @@ public class KeywordReplacer implements IText
|
||||
world = user.getLocation().getWorld().getName();
|
||||
worldTime12 = DescParseTickFormat.format12(user.getWorld().getTime());
|
||||
worldTime24 = DescParseTickFormat.format24(user.getWorld().getTime());
|
||||
worldDate = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(DescParseTickFormat.ticksToDate(user.getWorld().getTime()));
|
||||
worldDate = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(DescParseTickFormat.ticksToDate(user.getWorld().getFullTime()));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -120,14 +123,14 @@ public class KeywordReplacer implements IText
|
||||
line = line.replace("{WORLDDATE}", worldDate);
|
||||
line = line.replace("{PLUGINS}", plugins);
|
||||
line = line.replace("{VERSION}", version);
|
||||
input.getLines().set(i, line);
|
||||
replaced.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLines()
|
||||
{
|
||||
return input.getLines();
|
||||
return replaced;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.io.*;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.*;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,9 +12,11 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class TextInput implements IText
|
||||
{
|
||||
private final transient List<String> lines = new ArrayList<String>();
|
||||
private final transient List<String> chapters = new ArrayList<String>();
|
||||
private final transient Map<String, Integer> bookmarks = new HashMap<String, Integer>();
|
||||
private final transient List<String> lines;
|
||||
private final transient List<String> chapters;
|
||||
private final transient Map<String, Integer> bookmarks;
|
||||
private final transient long lastChange;
|
||||
private final static HashMap<String, SoftReference<TextInput>> cache = new HashMap<String, SoftReference<TextInput>>();
|
||||
|
||||
public TextInput(final CommandSender sender, final String filename, final boolean createFile, final IEssentials ess) throws IOException
|
||||
{
|
||||
@ -34,33 +37,62 @@ public class TextInput implements IText
|
||||
}
|
||||
if (file.exists())
|
||||
{
|
||||
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
||||
try
|
||||
lastChange = file.lastModified();
|
||||
boolean readFromfile;
|
||||
synchronized (cache)
|
||||
{
|
||||
int lineNumber = 0;
|
||||
while (bufferedReader.ready())
|
||||
final SoftReference<TextInput> inputRef = cache.get(file.getName());
|
||||
TextInput input;
|
||||
if (inputRef == null || (input = inputRef.get()) == null || input.lastChange < lastChange)
|
||||
{
|
||||
final String line = bufferedReader.readLine();
|
||||
if (line == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (line.length() > 0 && line.charAt(0) == '#')
|
||||
{
|
||||
bookmarks.put(line.substring(1).toLowerCase(Locale.ENGLISH).replaceAll("&[0-9a-f]", ""), lineNumber);
|
||||
chapters.add(line.substring(1).replace('&', '§').replace("§§", "&"));
|
||||
}
|
||||
lines.add(line.replace('&', '§').replace("§§", "&"));
|
||||
lineNumber++;
|
||||
lines = new ArrayList<String>();
|
||||
chapters = new ArrayList<String>();
|
||||
bookmarks = new HashMap<String, Integer>();
|
||||
cache.put(file.getName(), new SoftReference<TextInput>(this));
|
||||
readFromfile = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
lines = Collections.unmodifiableList(input.getLines());
|
||||
chapters = Collections.unmodifiableList(input.getChapters());
|
||||
bookmarks = Collections.unmodifiableMap(input.getBookmarks());
|
||||
readFromfile = false;
|
||||
}
|
||||
}
|
||||
finally
|
||||
if (readFromfile)
|
||||
{
|
||||
bufferedReader.close();
|
||||
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
||||
try
|
||||
{
|
||||
int lineNumber = 0;
|
||||
while (bufferedReader.ready())
|
||||
{
|
||||
final String line = bufferedReader.readLine();
|
||||
if (line == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (line.length() > 0 && line.charAt(0) == '#')
|
||||
{
|
||||
bookmarks.put(line.substring(1).toLowerCase(Locale.ENGLISH).replaceAll("&[0-9a-f]", ""), lineNumber);
|
||||
chapters.add(line.substring(1).replace('&', '§').replace("§§", "&"));
|
||||
}
|
||||
lines.add(line.replace('&', '§').replace("§§", "&"));
|
||||
lineNumber++;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
bufferedReader.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastChange = 0;
|
||||
lines = Collections.emptyList();
|
||||
chapters = Collections.emptyList();
|
||||
bookmarks = Collections.emptyMap();
|
||||
if (createFile)
|
||||
{
|
||||
final InputStream input = ess.getResource(filename + ".txt");
|
||||
@ -68,8 +100,7 @@ public class TextInput implements IText
|
||||
try
|
||||
{
|
||||
final byte[] buffer = new byte[1024];
|
||||
int length = 0;
|
||||
length = input.read(buffer);
|
||||
int length = input.read(buffer);
|
||||
while (length > 0)
|
||||
{
|
||||
output.write(buffer, 0, length);
|
||||
|
@ -56,7 +56,7 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
final Block below = blockPlaced.getRelative(BlockFace.DOWN);
|
||||
if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
|
||||
&& prot.getSettingBool(ProtectConfig.prevent_block_on_rail)
|
||||
&& prot.getStorage().isProtected(below, user.getName()))
|
||||
&& isProtected(below, user))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -69,7 +69,7 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
{
|
||||
protect.add(blockPlaced);
|
||||
if (prot.getSettingBool(ProtectConfig.protect_below_rails)
|
||||
&& !prot.getStorage().isProtected(blockPlaced.getRelative(BlockFace.DOWN), user.getName()))
|
||||
&& !isProtected(blockPlaced.getRelative(BlockFace.DOWN), user))
|
||||
{
|
||||
protect.add(blockPlaced.getRelative(BlockFace.DOWN));
|
||||
}
|
||||
@ -82,7 +82,7 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
if (prot.getSettingBool(ProtectConfig.protect_against_signs)
|
||||
&& event.getBlockAgainst().getType() != Material.SIGN_POST
|
||||
&& event.getBlockAgainst().getType() != Material.WALL_SIGN
|
||||
&& !prot.getStorage().isProtected(event.getBlockAgainst(), user.getName()))
|
||||
&& !isProtected(event.getBlockAgainst(), user))
|
||||
{
|
||||
protect.add(event.getBlockAgainst());
|
||||
}
|
||||
@ -283,7 +283,7 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
else
|
||||
{
|
||||
|
||||
final boolean isProtected = storage.isProtected(block, user.getName());
|
||||
final boolean isProtected = isProtected(block, user);
|
||||
if (isProtected)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
@ -422,4 +422,58 @@ public class EssentialsProtectBlockListener extends BlockListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isProtected(final Block block, final User user)
|
||||
{
|
||||
final Material type = block.getType();
|
||||
if (prot.getSettingBool(ProtectConfig.protect_signs))
|
||||
{
|
||||
if (type == Material.WALL_SIGN || type == Material.SIGN_POST)
|
||||
{
|
||||
return prot.getStorage().isProtected(block, user.getName());
|
||||
}
|
||||
if (prot.getSettingBool(ProtectConfig.protect_against_signs))
|
||||
{
|
||||
final Block up = block.getRelative(BlockFace.UP);
|
||||
if (up != null && up.getType() == Material.SIGN_POST)
|
||||
{
|
||||
return prot.getStorage().isProtected(block, user.getName());
|
||||
}
|
||||
final BlockFace[] directions = new BlockFace[]
|
||||
{
|
||||
BlockFace.NORTH,
|
||||
BlockFace.EAST,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST
|
||||
};
|
||||
for (BlockFace blockFace : directions)
|
||||
{
|
||||
final Block signblock = block.getRelative(blockFace);
|
||||
if (signblock.getType() == Material.WALL_SIGN)
|
||||
{
|
||||
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign)signblock.getState().getData();
|
||||
if (signMat != null && signMat.getFacing() == blockFace)
|
||||
{
|
||||
return prot.getStorage().isProtected(block, user.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prot.getSettingBool(ProtectConfig.protect_rails)) {
|
||||
if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
|
||||
{
|
||||
return prot.getStorage().isProtected(block, user.getName());
|
||||
}
|
||||
if (prot.getSettingBool(ProtectConfig.protect_below_rails))
|
||||
{
|
||||
final Block up = block.getRelative(BlockFace.UP);
|
||||
if (up != null && (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL))
|
||||
{
|
||||
return prot.getStorage().isProtected(block, user.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user