-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
SentryImport.java
189 lines (183 loc) · 8.17 KB
/
SentryImport.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package org.mcmonkey.sentinel;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.Listener;
import net.aufdemrand.sentry.SentryInstance;
import net.aufdemrand.sentry.SentryTrait;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
public class SentryImport implements Listener {
/**
* Converts Sentry NPCs to Sentinel NPCs. Returns the number of NPCs converted.
*/
public static int PerformImport() {
int convertedCount = 0;
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (!npc.hasTrait(SentryTrait.class)) {
continue;
}
SentryInstance sentry = npc.getTrait(SentryTrait.class).getInstance();
if (sentry == null) {
continue;
}
convertedCount++;
if (!npc.hasTrait(SentinelTrait.class)) {
npc.addTrait(SentinelTrait.class);
}
SentinelTrait sentinel = npc.getTrait(SentinelTrait.class);
sentinel.armor = Math.min(sentry.Armor * 0.1, 1.0);
sentinel.attackRate = (int) (sentry.AttackRateSeconds * 20);
if (sentinel.attackRate < SentinelPlugin.instance.tickRate) {
sentinel.attackRate = SentinelPlugin.instance.tickRate;
}
else if (sentinel.attackRate > SentinelTrait.attackRateMax) {
sentinel.attackRate = SentinelTrait.attackRateMax;
}
sentinel.chaseRange = sentry.sentryRange;
sentinel.closeChase = true;
sentinel.rangedChase = false;
sentinel.damage = sentry.Strength;
sentinel.enemyDrops = sentry.KillsDropInventory;
sentinel.fightback = sentry.Retaliate;
double hpHealedPerPeriod = 1;
if (sentry.HealRate < .5) {
hpHealedPerPeriod = .5 / sentry.HealRate;
}
double secondsPerHpPoint = sentry.HealRate / hpHealedPerPeriod;
sentinel.healRate = (int) (20 * secondsPerHpPoint);
if (sentinel.healRate < SentinelPlugin.instance.tickRate) {
sentinel.healRate = SentinelPlugin.instance.tickRate;
}
else if (sentinel.healRate > SentinelTrait.healRateMax) {
sentinel.healRate = SentinelTrait.healRateMax;
}
double health = sentry.sentryHealth;
if (health < SentinelTrait.healthMin) {
health = SentinelTrait.healthMin;
}
else if (health > SentinelTrait.healthMax) {
health = SentinelTrait.healthMax;
}
sentinel.setHealth(health);
sentinel.setInvincible(sentry.Invincible);
sentinel.needsAmmo = false;
sentinel.range = sentry.sentryRange;
sentinel.respawnTime = sentry.RespawnDelaySeconds * 20;
sentinel.safeShot = false;
sentinel.spawnPoint = sentry.Spawn;
if (sentry.guardTarget != null && sentry.guardTarget.length() > 0) {
OfflinePlayer op = Bukkit.getOfflinePlayer(sentry.guardTarget);
if (op != null) {
UUID playerId = op.getUniqueId();
if (playerId != null) {
sentinel.setGuarding(playerId);
}
}
}
sentinel.targets.clear();
sentinel.eventTargets.clear();
sentinel.playerNameTargets.clear();
sentinel.npcNameTargets.clear();
sentinel.groupTargets.clear();
sentinel.ignores.clear();
sentinel.playerNameIgnores.clear();
sentinel.npcNameIgnores.clear();
sentinel.groupIgnores.clear();
for (String t : sentry.validTargets) {
if (t.contains("ENTITY:ALL")) {
sentinel.targets.add(SentinelTarget.forName("MOBS"));
sentinel.targets.add(SentinelTarget.PLAYERS);
sentinel.targets.add(SentinelTarget.NPCS);
}
else if (t.contains("ENTITY:MONSTER")) {
sentinel.targets.add(SentinelTarget.forName("MONSTERS"));
}
else if (t.contains("ENTITY:PLAYER")) {
sentinel.targets.add(SentinelTarget.PLAYERS);
}
else if (t.contains("ENTITY:NPC")) {
sentinel.targets.add(SentinelTarget.NPCS);
}
else if (t.contains("EVENT:PVP")) {
sentinel.eventTargets.add("pvp");
}
else if (t.contains("EVENT:PVE")) {
sentinel.eventTargets.add("pve");
}
else if (t.contains("EVENT:PVNPC")) {
sentinel.eventTargets.add("pvnpc");
}
else {
String[] sections = t.split(":");
if (sections.length != 2) {
continue;
}
sections[0] = sections[0].trim();
sections[1] = sections[1].trim();
if (sections[0].equals("NPC")) {
sentinel.npcNameTargets.add(sections[1]);
}
else if (sections[0].equals("GROUP")) {
sentinel.groupTargets.add(sections[1]);
}
else if (sections[0].equals("PLAYER")) {
sentinel.playerNameTargets.add(sections[1]);
}
else if (sections[0].equals("ENTITY")) {
SentinelTarget target = SentinelTarget.forName(sections[1]);
if (target != null) {
sentinel.targets.add(target);
}
}
}
}
for (String t : sentry.ignoreTargets) {
if (t.contains("ENTITY:ALL")) {
sentinel.ignores.add(SentinelTarget.forName("MOBS"));
sentinel.ignores.add(SentinelTarget.PLAYERS);
sentinel.ignores.add(SentinelTarget.NPCS);
}
else if (t.contains("ENTITY:MONSTER")) {
sentinel.ignores.add(SentinelTarget.forName("MONSTERS"));
}
else if (t.contains("ENTITY:PLAYER")) {
sentinel.ignores.add(SentinelTarget.PLAYERS);
}
else if (t.contains("ENTITY:NPC")) {
sentinel.ignores.add(SentinelTarget.NPCS);
}
else if (t.contains("ENTITY:OWNER")) {
sentinel.ignores.add(SentinelTarget.OWNER);
}
else {
String[] sections = t.split(":");
if (sections.length != 2) {
// Invalid target identifier?
continue;
}
// Sentry was spacing tolerant, so we should be too.
sections[0] = sections[0].trim();
sections[1] = sections[1].trim();
if (sections[0].equals("NPC")) {
sentinel.npcNameIgnores.add(sections[1]);
}
else if (sections[0].equals("GROUP")) {
sentinel.groupIgnores.add(sections[1]);
}
else if (sections[0].equals("PLAYER")) {
sentinel.playerNameIgnores.add(sections[1]);
}
else if (sections[0].equals("ENTITY")) {
SentinelTarget target = SentinelTarget.forName(sections[1]);
if (target != null) {
sentinel.ignores.add(target);
}
}
}
}
npc.removeTrait(SentryTrait.class);
}
return convertedCount;
}
}