1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
package com.earth2me.essentials.protect;
import com.earth2me.essentials.protect.data.IProtectedBlock;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class EssentialsProtect extends JavaPlugin implements IProtect
{
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private static com.mchange.v2.log.MLogger C3P0logger;
private final transient Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
private final transient Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class);
private final transient Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
private transient IProtectedBlock storage = null;
private transient EssentialsConnect ess = null;
@Override
public void onLoad()
{
C3P0logger = com.mchange.v2.log.MLog.getLogger(com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.class);
C3P0logger.setFilter(new Filter()
{
public boolean isLoggable(LogRecord lr)
{
return lr.getLevel() != Level.INFO;
}
});
}
public void onEnable()
{
final PluginManager pm = this.getServer().getPluginManager();
final Plugin essPlugin = pm.getPlugin("Essentials");
if (essPlugin == null || !essPlugin.isEnabled())
{
enableEmergencyMode(pm);
return;
}
ess = new EssentialsConnect(essPlugin, this);
final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this);
pm.registerEvents(playerListener, this);
final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
pm.registerEvents(blockListener, this);
final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this);
pm.registerEvents(entityListener, this);
final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(this);
pm.registerEvents(weatherListener, this);
}
private void enableEmergencyMode(final PluginManager pm)
{
//final EmergencyListener emListener = new EmergencyListener();
//pm.registerEvents(emListener, this);
//TODO: Remove deprecated listners in a few weeks.
final EmergencyBlockListener emBlockListener = new EmergencyBlockListener();
final EmergencyEntityListener emEntityListener = new EmergencyEntityListener();
final EmergencyPlayerListener emPlayerListener = new EmergencyPlayerListener();
pm.registerEvent(Type.PLAYER_JOIN, emPlayerListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_BURN, emBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_IGNITE, emBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_FROMTO, emBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_BREAK, emBlockListener, Priority.Low, this);
pm.registerEvent(Type.ENTITY_DAMAGE, emEntityListener, Priority.Low, this);
pm.registerEvent(Type.ENTITY_EXPLODE, emEntityListener, Priority.Low, this);
for (Player player : getServer().getOnlinePlayers())
{
player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors.");
}
LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now.");
}
@Override
public boolean checkProtectionItems(final ProtectConfig list, final int id)
{
final List<Integer> itemList = settingsList.get(list);
return itemList != null && !itemList.isEmpty() && itemList.contains(id);
}
@Override
public IProtectedBlock getStorage()
{
return storage;
}
@Override
public void setStorage(IProtectedBlock pb)
{
storage = pb;
}
public EssentialsConnect getEssentialsConnect()
{
return ess;
}
public Map<ProtectConfig, Boolean> getSettingsBoolean()
{
return settingsBoolean;
}
public Map<ProtectConfig, String> getSettingsString()
{
return settingsString;
}
public Map<ProtectConfig, List<Integer>> getSettingsList()
{
return settingsList;
}
@Override
public boolean getSettingBool(final ProtectConfig protectConfig)
{
final Boolean bool = settingsBoolean.get(protectConfig);
return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
}
@Override
public String getSettingString(final ProtectConfig protectConfig)
{
final String str = settingsString.get(protectConfig);
return str == null ? protectConfig.getDefaultValueString() : str;
}
public void onDisable()
{
if (storage != null)
{
storage.onPluginDeactivation();
}
// Sleep for a second to allow the database to close.
try
{
Thread.sleep(1000);
}
catch (InterruptedException ex)
{
}
}
}
|