1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-21 22:06:22 +02:00

EssentialsSpawn and EssentialsChat should build now again

This commit is contained in:
snowleo
2012-01-02 22:38:47 +01:00
parent a20e96af4e
commit 41e0e64a5f
16 changed files with 216 additions and 39 deletions

View File

@@ -17,4 +17,6 @@ public interface IGroups extends IStorageObjectHolder<Groups>
String getSuffix(IUser player); String getSuffix(IUser player);
int getHomeLimit(IUser player); int getHomeLimit(IUser player);
String getChatFormat(IUser player);
} }

View File

@@ -6,11 +6,9 @@ import com.earth2me.essentials.storage.IStorageObjectHolder;
public interface ISettings extends IStorageObjectHolder<Settings> public interface ISettings extends IStorageObjectHolder<Settings>
{ {
public String getLocale(); public String getLocale();
public boolean isDebug(); public boolean isDebug();
public void setDebug(boolean b); public void setDebug(boolean b);
} }

View File

@@ -40,7 +40,7 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
Location getHome(String name) throws Exception; Location getHome(String name) throws Exception;
Location getHome(Location loc) throws Exception; Location getHome(Location loc);
boolean isHidden(); boolean isHidden();

View File

@@ -26,7 +26,8 @@ public class Commandpowertool extends EssentialsCommand
// check to see if this is a clear all command // check to see if this is a clear all command
if (command != null && command.equalsIgnoreCase("d:")) if (command != null && command.equalsIgnoreCase("d:"))
{ {
user.clearAllPowertools(); user.acquireWriteLock();
user.getData().clearAllPowertools();
user.sendMessage(_("powerToolClearAll")); user.sendMessage(_("powerToolClearAll"));
return; return;
} }
@@ -38,7 +39,7 @@ public class Commandpowertool extends EssentialsCommand
} }
final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " "); final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " ");
List<String> powertools = user.getPowertool(itemStack); List<String> powertools = user.getData().getPowertool(itemStack.getType());
if (command != null && !command.isEmpty()) if (command != null && !command.isEmpty())
{ {
if (command.equalsIgnoreCase("l:")) if (command.equalsIgnoreCase("l:"))
@@ -110,6 +111,7 @@ public class Commandpowertool extends EssentialsCommand
user.sendMessage(_("powerToolRemoveAll", itemName)); user.sendMessage(_("powerToolRemoveAll", itemName));
} }
user.setPowertool(itemStack, powertools); user.acquireWriteLock();
user.getData().setPowertool(itemStack.getType(), powertools);
} }
} }

View File

@@ -15,12 +15,14 @@ public class Commandpowertooltoggle extends EssentialsCommand
@Override @Override
protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception protected void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
if (!user.hasPowerTools()) if (!user.getData().hasPowerTools())
{ {
user.sendMessage(_("noPowerTools")); user.sendMessage(_("noPowerTools"));
return; return;
} }
user.sendMessage(user.togglePowerToolsEnabled() user.acquireWriteLock();
user.getData().setPowerToolsEnabled(!user.getData().isPowerToolsEnabled());
user.sendMessage(user.getData().isPowerToolsEnabled()
? _("powerToolsEnabled") ? _("powerToolsEnabled")
: _("powerToolsDisabled")); : _("powerToolsDisabled"));
} }

View File

@@ -304,7 +304,7 @@ public class EssentialsPlayerListener extends PlayerListener
final IUser user = ess.getUser(event.getPlayer()); final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock(); user.acquireReadLock();
final ItemStack hand = user.getItemInHand(); final ItemStack hand = user.getItemInHand();
if (hand == null || hand.getType() == Material.AIR || !user.getData().isPowertoolsenabled()) if (hand == null || hand.getType() == Material.AIR || !user.getData().isPowerToolsEnabled())
{ {
return; return;
} }

View File

@@ -24,13 +24,6 @@ public class General implements StorageObject
}) })
private String locale; private String locale;
@Comment( @Comment(
{
"Should we announce to the server when someone logs in for the first time?",
"If so, use this format, replacing {DISPLAYNAME} with the player name.",
"If not, set to ''"
})
private String newPlayerAnnouncement = "&dWelcome {DISPLAYNAME} to the server!";
@Comment(
{ {
"The number of items given, if the quantity parameter is left out in /item or /give.", "The number of items given, if the quantity parameter is left out in /item or /give.",
"If this number is below 1, the maximum stack size size is given. If oversized stacks", "If this number is below 1, the maximum stack size size is given. If oversized stacks",

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.settings;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IGroups; import com.earth2me.essentials.api.IGroups;
import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
import java.io.File; import java.io.File;
@@ -11,6 +12,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import lombok.Cleanup;
public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IGroups public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IGroups
@@ -147,4 +149,20 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
} }
return 0; return 0;
} }
@Override
public String getChatFormat(final IUser player)
{
for (GroupOptions groupOptions : getGroups(player))
{
if (groupOptions.getMessageFormat() != null)
{
return groupOptions.getMessageFormat();
}
}
@Cleanup
ISettings settings = ess.getSettings();
settings.acquireReadLock();
return settings.getData().getChat().getDefaultFormat();
}
} }

View File

@@ -1,5 +1,6 @@
package com.earth2me.essentials.settings; package com.earth2me.essentials.settings;
import com.earth2me.essentials.storage.Comment;
import com.earth2me.essentials.storage.MapValueType; import com.earth2me.essentials.storage.MapValueType;
import com.earth2me.essentials.storage.StorageObject; import com.earth2me.essentials.storage.StorageObject;
import java.util.HashMap; import java.util.HashMap;
@@ -13,6 +14,27 @@ import org.bukkit.Location;
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class Spawns implements StorageObject public class Spawns implements StorageObject
{ {
@Comment(
{
"Should we announce to the server when someone logs in for the first time?",
"If so, use this format, replacing {DISPLAYNAME} with the player name.",
"If not, set to ''"
})
private String newPlayerAnnouncement = "&dWelcome {DISPLAYNAME} to the server!";
@Comment(
{
"Priority of the respawn event listener",
"Set this to lowest, if you want e.g. Multiverse to handle the respawning",
"Set this to normal, if you want EssentialsSpawn to handle the respawning",
"Set this to highest, if you want to force EssentialsSpawn to handle the respawning"
})
private String respawnPriority = "normal";
@Comment({
"When we spawn for the first time, which spawnpoint do we use?",
"Set to none if you want to use the spawn point of the world."
})
private String newbieSpawn = "none";
@Comment("List of all spawnpoints")
@MapValueType(Location.class) @MapValueType(Location.class)
private Map<String, Location> spawns = new HashMap<String, Location>(); private Map<String, Location> spawns = new HashMap<String, Location>();
} }

View File

@@ -565,12 +565,6 @@ public class User extends UserBase implements IUser
return ess.getPermissionsHandler().canBuild(base, getGroup()); return ess.getPermissionsHandler().canBuild(base, getGroup());
} }
@Override
public Location getHome(Location loc) throws Exception
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override @Override
public Location getHome(String name) throws Exception public Location getHome(String name) throws Exception
{ {

View File

@@ -397,4 +397,45 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
unlock(); unlock();
} }
} }
public Location getHome(Location loc)
{
acquireReadLock();
try
{
if (getData().getHomes() == null)
{
return null;
}
ArrayList<Location> worldHomes = new ArrayList<Location>();
for (Location location : getData().getHomes().values())
{
if (location.getWorld().equals(loc.getWorld())) {
worldHomes.add(location);
}
}
if (worldHomes.isEmpty()) {
return null;
}
if (worldHomes.size() == 1) {
return worldHomes.get(0);
}
double distance = Double.MAX_VALUE;
Location target = null;
for (Location location : worldHomes)
{
final double d = loc.distanceSquared(location);
if (d < distance) {
target = location;
distance = d;
}
}
return target;
}
finally
{
unlock();
}
}
} }

View File

@@ -49,7 +49,7 @@ public class UserData implements StorageObject
private String geolocation; private String geolocation;
private boolean socialspy; private boolean socialspy;
private boolean npc; private boolean npc;
private boolean powertoolsenabled; private boolean powerToolsEnabled;
public UserData() public UserData()
{ {
@@ -70,9 +70,30 @@ public class UserData implements StorageObject
return powerTools == null ? Collections.<String>emptyList() : powerTools.get(mat); return powerTools == null ? Collections.<String>emptyList() : powerTools.get(mat);
} }
public boolean hasPowerTools()
{
return powerTools != null && !powerTools.isEmpty();
}
public void setPowertool(Material mat, List<String> commands)
{
if (powerTools == null)
{
powerTools = new HashMap<Material, List<String>>();
}
powerTools.put(mat, commands);
}
public void clearAllPowertools()
{
powerTools = null;
}
public void removeHome(String home) public void removeHome(String home)
{ {
if (homes == null) { if (homes == null)
{
return; return;
} }
homes.remove(home); homes.remove(home);

View File

@@ -4,7 +4,9 @@ import com.earth2me.essentials.ChargeException;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.settings.GroupOptions;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -112,7 +114,8 @@ public abstract class EssentialsChatPlayer extends PlayerListener
{ {
event.setMessage(event.getMessage().replaceAll("&([0-9a-f])", "\u00a7$1")); event.setMessage(event.getMessage().replaceAll("&([0-9a-f])", "\u00a7$1"));
} }
event.setFormat(ess.getSettings().getChatFormat(user.getGroup()).replace('&', '\u00a7').replace("\u00a7\u00a7", "&").replace("{DISPLAYNAME}", "%1$s").replace("{GROUP}", user.getGroup()).replace("{MESSAGE}", "%2$s").replace("{WORLDNAME}", user.getWorld().getName()).replace("{SHORTWORLDNAME}", user.getWorld().getName().substring(0, 1).toUpperCase(Locale.ENGLISH))); String format = ess.getGroups().getChatFormat(user);
event.setFormat(format.replace('&', '\u00a7').replace("\u00a7\u00a7", "&").replace("{DISPLAYNAME}", "%1$s").replace("{GROUP}", user.getGroup()).replace("{MESSAGE}", "%2$s").replace("{WORLDNAME}", user.getWorld().getName()).replace("{SHORTWORLDNAME}", user.getWorld().getName().substring(0, 1).toUpperCase(Locale.ENGLISH)));
} }
protected String getChatType(final String message) protected String getChatType(final String message)
@@ -132,8 +135,14 @@ public abstract class EssentialsChatPlayer extends PlayerListener
protected void handleLocalChat(final Map<PlayerChatEvent, String> charges, final PlayerChatEvent event) protected void handleLocalChat(final Map<PlayerChatEvent, String> charges, final PlayerChatEvent event)
{ {
long radius = 0;
long radius = ess.getSettings().getChatRadius(); ISettings settings = ess.getSettings();
settings.acquireReadLock();
try {
radius = settings.getData().getChat().getLocalRadius();
} finally {
settings.unlock();
}
radius *= radius; radius *= radius;
final IUser user = ess.getUser(event.getPlayer()); final IUser user = ess.getUser(event.getPlayer());

View File

@@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.ICommandHandler; import com.earth2me.essentials.api.ICommandHandler;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IEssentialsModule; import com.earth2me.essentials.api.IEssentialsModule;
import com.earth2me.essentials.api.ISettings;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -43,7 +44,7 @@ public class EssentialsSpawn extends JavaPlugin
commandHandler = new EssentialsCommandHandler(EssentialsSpawn.class.getClassLoader(), "com.earth2me.essentials.spawn.Command", "essentials.", spawns, ess); commandHandler = new EssentialsCommandHandler(EssentialsSpawn.class.getClassLoader(), "com.earth2me.essentials.spawn.Command", "essentials.", spawns, ess);
final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns); final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns);
pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, ess.getSettings().getRespawnPriority(), this); pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, spawns.getRespawnPriority(), this);
pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Low, this); pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Low, this);
LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.spawn;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -29,7 +30,15 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
{ {
final IUser user = ess.getUser(event.getPlayer()); final IUser user = ess.getUser(event.getPlayer());
if (ess.getSettings().getRespawnAtHome()) boolean respawnAtHome = false;
ISettings settings = ess.getSettings();
settings.acquireReadLock();
try {
respawnAtHome = ess.getSettings().getData().getCommands().getHome().isRespawnAtHome();
} finally {
settings.unlock();
}
if (respawnAtHome)
{ {
Location home = user.getHome(user.getLocation()); Location home = user.getHome(user.getLocation());
if (home == null) if (home == null)
@@ -53,20 +62,29 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
public void onPlayerJoin(final PlayerJoinEvent event) public void onPlayerJoin(final PlayerJoinEvent event)
{ {
final IUser user = ess.getUser(event.getPlayer()); final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock();
if (!user.isNew() || user.getBedSpawnLocation() != null) try
{ {
return;
if (!user.getData().isNewplayer() || user.getBedSpawnLocation() != null)
{
return;
}
user.acquireWriteLock();
user.getData().setNewplayer(false);
} }
user.setNew(false); finally
if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn())) {
user.unlock();
}
if (spawns.getNewbieSpawn() != null)
{ {
ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user)); ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user));
} }
if (ess.getSettings().getAnnounceNewPlayers()) if (spawns.getAnnounceNewPlayers())
{ {
ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user)); ess.broadcastMessage(user, spawns.getAnnounceNewPlayerFormat(user));
} }
} }
@@ -85,7 +103,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
{ {
try try
{ {
Location spawn = spawns.getSpawn(ess.getSettings().getNewbieSpawn()); Location spawn = spawns.getNewbieSpawn();
if (spawn != null) if (spawn != null)
{ {
user.getTeleport().now(spawn, false, TeleportCause.PLUGIN); user.getTeleport().now(spawn, false, TeleportCause.PLUGIN);

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.spawn;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IEssentialsModule; import com.earth2me.essentials.api.IEssentialsModule;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.settings.Spawns; import com.earth2me.essentials.settings.Spawns;
import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
import java.io.File; import java.io.File;
@@ -10,6 +11,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.event.Event.Priority;
public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule
@@ -87,4 +89,58 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE
} }
return ess.getServer().getWorlds().get(0).getSpawnLocation(); return ess.getServer().getWorlds().get(0).getSpawnLocation();
} }
public Priority getRespawnPriority()
{
acquireReadLock();
try
{
for (Priority priority : Priority.values())
{
if (priority.toString().equalsIgnoreCase(getData().getRespawnPriority())) {
return priority;
}
}
return Priority.Normal;
} finally {
unlock();
}
}
public Location getNewbieSpawn()
{
acquireReadLock();
try
{
if (getData().getNewbieSpawn() == null || getData().getNewbieSpawn().isEmpty() ||
getData().getNewbieSpawn().equalsIgnoreCase("none")) {
return null;
}
return getSpawn(getData().getNewbieSpawn());
} finally {
unlock();
}
}
public boolean getAnnounceNewPlayers()
{
acquireReadLock();
try
{
return getData().getNewPlayerAnnouncement() != null && !getData().getNewPlayerAnnouncement().isEmpty();
} finally {
unlock();
}
}
public String getAnnounceNewPlayerFormat(IUser user)
{
acquireReadLock();
try
{
return getData().getNewPlayerAnnouncement().replace('&', '§').replace("§§", "&").replace("{PLAYER}", user.getDisplayName()).replace("{DISPLAYNAME}", user.getDisplayName()).replace("{GROUP}", user.getGroup()).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getAddress().toString());
} finally {
unlock();
}
}
} }