2011-03-30 04:03:21 +00:00
|
|
|
package com.earth2me.essentials.protect;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.Essentials;
|
2011-05-11 22:30:34 +00:00
|
|
|
import com.earth2me.essentials.IConf;
|
2011-03-30 04:03:21 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2011-05-10 19:57:59 +00:00
|
|
|
import com.earth2me.essentials.Util;
|
2011-06-01 11:26:12 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2011-03-30 04:03:21 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.Event.Priority;
|
|
|
|
import org.bukkit.event.Event.Type;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
|
2011-05-11 22:30:34 +00:00
|
|
|
public class EssentialsProtect extends JavaPlugin implements IConf
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
|
|
|
private EssentialsProtectBlockListener blockListener = null;
|
|
|
|
private EssentialsProtectPlayerListener playerListener = null;
|
|
|
|
private EssentialsProtectEntityListener entityListener = null;
|
2011-04-27 01:33:45 +00:00
|
|
|
private EssentialsProtectWeatherListener weatherListener = null;
|
2011-05-03 21:37:36 +00:00
|
|
|
private EssentialsProtectServerListener serverListener = null;
|
2011-03-30 04:03:21 +00:00
|
|
|
public static final String AUTHORS = Essentials.AUTHORS;
|
|
|
|
private static final Logger logger = Logger.getLogger("Minecraft");
|
2011-06-01 11:26:12 +00:00
|
|
|
public static Map<String, Boolean> genSettings = null;
|
|
|
|
public static Map<String, String> dataSettings = null;
|
|
|
|
public static Map<String, Boolean> guardSettings = null;
|
|
|
|
public static Map<String, Boolean> playerSettings = null;
|
|
|
|
public static List<Integer> usageList = null;
|
|
|
|
public static List<Integer> blackListPlace = null;
|
|
|
|
public static List<Integer> breakBlackList = null;
|
|
|
|
public static List<Integer> onPlaceAlert = null;
|
|
|
|
public static List<Integer> onUseAlert = null;
|
|
|
|
public static List<Integer> onBreakAlert = null;
|
2011-03-30 04:03:21 +00:00
|
|
|
|
|
|
|
public EssentialsProtect()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onEnable()
|
|
|
|
{
|
|
|
|
PluginManager pm = this.getServer().getPluginManager();
|
|
|
|
|
|
|
|
playerListener = new EssentialsProtectPlayerListener(this);
|
|
|
|
blockListener = new EssentialsProtectBlockListener(this);
|
|
|
|
entityListener = new EssentialsProtectEntityListener(this);
|
2011-04-27 01:33:45 +00:00
|
|
|
weatherListener = new EssentialsProtectWeatherListener(this);
|
2011-05-03 21:37:36 +00:00
|
|
|
serverListener = new EssentialsProtectServerListener(this);
|
|
|
|
|
2011-03-30 14:28:46 +00:00
|
|
|
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);
|
2011-05-03 21:37:36 +00:00
|
|
|
|
|
|
|
//blocklistener
|
2011-03-30 14:28:46 +00:00
|
|
|
pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
|
|
|
|
pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this);
|
2011-03-30 04:03:21 +00:00
|
|
|
pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
|
|
|
|
pm.registerEvent(Type.BLOCK_BURN, blockListener, Priority.Highest, this);
|
2011-05-03 21:37:36 +00:00
|
|
|
pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
|
|
|
|
|
|
|
|
//entitylistener
|
2011-03-30 04:03:21 +00:00
|
|
|
pm.registerEvent(Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this);
|
2011-03-30 14:28:46 +00:00
|
|
|
pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this);
|
2011-04-07 20:32:00 +00:00
|
|
|
pm.registerEvent(Type.ENTITY_TARGET, entityListener, Priority.Highest, this);
|
2011-03-30 04:03:21 +00:00
|
|
|
pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
|
2011-05-03 21:37:36 +00:00
|
|
|
|
|
|
|
//weatherlistener
|
2011-04-27 01:33:45 +00:00
|
|
|
pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this);
|
|
|
|
pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this);
|
|
|
|
pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this);
|
2011-05-03 21:37:36 +00:00
|
|
|
|
|
|
|
//serverlistener
|
|
|
|
pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Highest, this);
|
|
|
|
|
2011-05-10 21:14:38 +00:00
|
|
|
reloadConfig();
|
2011-05-11 22:30:34 +00:00
|
|
|
Essentials.getStatic().addReloadListener(this);
|
2011-05-10 19:57:59 +00:00
|
|
|
if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) {
|
|
|
|
logger.log(Level.WARNING, Util.i18n("versionMismatchAll"));
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
2011-05-10 19:57:59 +00:00
|
|
|
logger.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS));
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
|
2011-06-01 11:26:12 +00:00
|
|
|
public static boolean checkProtectionItems(List<Integer> itemList, int id)
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
2011-04-01 22:06:00 +00:00
|
|
|
return !itemList.isEmpty() && itemList.contains(id);
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable()
|
|
|
|
{
|
|
|
|
genSettings.clear();
|
|
|
|
dataSettings.clear();
|
2011-04-27 01:33:45 +00:00
|
|
|
|
2011-03-30 04:03:21 +00:00
|
|
|
blockListener = null;
|
|
|
|
playerListener = null;
|
|
|
|
entityListener = null;
|
|
|
|
genSettings = null;
|
|
|
|
dataSettings = null;
|
|
|
|
guardSettings = null;
|
|
|
|
playerSettings = null;
|
|
|
|
usageList = null;
|
|
|
|
blackListPlace = null;
|
|
|
|
onPlaceAlert = null;
|
|
|
|
onUseAlert = null;
|
|
|
|
onBreakAlert = null;
|
|
|
|
}
|
|
|
|
|
2011-05-10 21:14:38 +00:00
|
|
|
public void reloadConfig()
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
dataSettings = Essentials.getStatic().getSettings().getEpDBSettings();
|
|
|
|
genSettings = Essentials.getStatic().getSettings().getEpSettings();
|
|
|
|
guardSettings = Essentials.getStatic().getSettings().getEpGuardSettings();
|
|
|
|
usageList = Essentials.getStatic().getSettings().epBlackListUsage();
|
|
|
|
blackListPlace = Essentials.getStatic().getSettings().epBlackListPlacement();
|
|
|
|
breakBlackList = Essentials.getStatic().getSettings().epBlockBreakingBlacklist();
|
|
|
|
onPlaceAlert = Essentials.getStatic().getSettings().getEpAlertOnPlacement();
|
|
|
|
onUseAlert = Essentials.getStatic().getSettings().getEpAlertOnUse();
|
|
|
|
onBreakAlert = Essentials.getStatic().getSettings().getEpAlertOnBreak();
|
|
|
|
playerSettings = Essentials.getStatic().getSettings().getEpPlayerSettings();
|
2011-03-30 12:56:34 +00:00
|
|
|
EssentialsProtectData.createSqlTable();
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
2011-03-30 12:56:34 +00:00
|
|
|
|
|
|
|
public void alert(User user, String item, String type)
|
|
|
|
{
|
|
|
|
Location loc = user.getLocation();
|
|
|
|
for (Player p : this.getServer().getOnlinePlayers())
|
|
|
|
{
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
User alertUser = Essentials.getStatic().getUser(p);
|
2011-03-30 12:56:34 +00:00
|
|
|
if (alertUser.isAuthorized("essentials.protect.alerts"))
|
2011-05-10 19:57:59 +00:00
|
|
|
alertUser.sendMessage(Util.format("alertFormat", user.getName(), type, item, EssentialsProtectData.formatCoords(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
|
2011-03-30 12:56:34 +00:00
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
}
|