-
Notifications
You must be signed in to change notification settings - Fork 5
/
Craftizens.java
103 lines (86 loc) · 3.5 KB
/
Craftizens.java
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
import java.util.HashSet;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.logging.*;
public class Craftizens extends Plugin {
static final Logger log = Logger.getLogger("Minecraft");
public static boolean DEBUG = true;
public static String NPC_PREFIX = "§e";
public static String NPC_SUFFIX = " (NPC)";
public static String TEXT_COLOR = Colors.Yellow;
public static int INTERACT_ITEM = 340;
public static int INTERACT_ITEM_2 = 340;
public static int INTERACT_RANGE = 2;
public static int INTERACT_ANGLE_VARIATION = 25;
public static int QADMIN_BOUNDARY_MARKER = 340;
public static boolean QUESTS_ENABLED = true;
public static CraftizenDataSource data;
public static HashSet<Craftizen> npcs;
public static HashMap<String,Object> pendingQuests;
public static HashMap<String,ArrayList<Quest>> activeQuests;
public static HashMap<String,QuestInfo> newQuests;
private static CraftizenTicker ticker;
private static CraftizensListener listener;
public void initialize() {
listener = new CraftizensListener();
etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.ARM_SWING, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.PLAYER_MOVE, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.LOGIN, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.DISCONNECT, listener, this, PluginListener.Priority.MEDIUM);
}
public void enable() {
// load properties
PropertiesFile props = new PropertiesFile("craftizens.properties");
DEBUG = props.getBoolean("debug-mode",false);
NPC_PREFIX = props.getString("npc-name-prefix","§e");
NPC_SUFFIX = props.getString("npc-name-suffix"," (NPC)");
TEXT_COLOR = "§" + props.getString("quest-text-color","e");
INTERACT_ITEM = props.getInt("npc-interact-item",340);
INTERACT_ITEM_2 = props.getInt("npc-interact-item-2",340);
INTERACT_RANGE = props.getInt("npc-interact-range",2);
INTERACT_ANGLE_VARIATION = props.getInt("npc-interact-angle-variation",25);
QADMIN_BOUNDARY_MARKER = props.getInt("qadmin-boundary-marker",340);
QUESTS_ENABLED = props.getBoolean("quests-enabled",true);
String dataSource = props.getString("data-source","mysql");
if (dataSource.equals("mysql")) {
data = new CraftizenSQLDataSource();
} else {
data = new CraftizenFlatfileDataSource();
}
Craftizen.getPlayerList();
npcs = data.loadCraftizens();
ticker = new CraftizenTicker(2000);
Thread t = new Thread(ticker);
t.start();
// load quests
pendingQuests = new HashMap<String,Object>();
activeQuests = new HashMap<String,ArrayList<Quest>>();
for (Player p : etc.getServer().getPlayerList()) {
CraftizensListener.loadActiveQuests(p);
}
log.info("Craftizens v0.7 loaded successfully!");
}
public void disable() {
ticker.stop();
ticker = null;
for (Craftizen npc : npcs) {
npc.delete();
}
npcs = null;
// save quest progress
for (String s : activeQuests.keySet()) {
for (Quest q : activeQuests.get(s)) {
if (q != null) {
q.saveProgress();
}
}
}
pendingQuests = null;
activeQuests = null;
newQuests = null;
data = null;
}
}