Skip to content
Permalink
Browse files

Clean up PR'd code

  • Loading branch information...
mcmonkey4eva committed Apr 25, 2016
1 parent 71e8dd0 commit 59ffb8cec8dac9c871d3e0851cd48ce5b865c838
@@ -64,6 +64,10 @@ Created by mcmonkey4eva on behalf of the Citizens and Denizen teams.
- /sentinel kill - Kills the NPC.
- /sentinel respawn - Respawns the NPC.

### Sentry user?

Type "/sentinel sentryimport" on a server running both Sentry and Sentinel to instantly transfer all data to Sentinel!

### Permissions
- sentinel.basic for the /sentinel command
- sentinel.admin to edit other player's Sentinel NPCs.
@@ -69,7 +69,7 @@ public void onEnable() {
instance = this;
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SentinelTrait.class).withName("sentinel"));
saveDefaultConfig();
if (getConfig().getInt("config version", 0) != 2) {
if (getConfig().getInt("config version", 0) != 3) {
getLogger().warning("Outdated Sentinel config - please delete it to regenerate it!");
}
BukkitRunnable postLoad = new BukkitRunnable() {
@@ -147,13 +147,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage(prefixBad + "Sentry plugin must be installed to perform import!");
}
else {
sender.sendMessage(prefixGood + "Converting all npcs from sentry to sentinel...");
sender.sendMessage(prefixGood + "Converting all NPCs from Sentry to Sentinel...");
int imported = SentryImport.PerformImport();
sender.sendMessage(prefixGood + "Imported " + imported + " sentries. You may now restart and remove the sentry plugin.");
sender.sendMessage(prefixGood + "Imported " + imported + " Sentry NPCs. You may now restart and remove the Sentry plugin.");
}
return true;
}
// All commands below this point will require a sentinel to be selected
else if (sentinel == null && !arg0.equals("help")) {
sender.sendMessage(prefixBad + "Must have an NPC selected!");
return true;
@@ -34,6 +34,18 @@

public class SentinelTrait extends Trait {

public static final double healthMin = 0.01;

public static final double healthMax = 2000;

public static final int attackRateMin = 10;

public static final int attackRateMax = 2000;

public static final int healRateMin = 0;

public static final int healRateMax = 2000;

public SentinelTrait() {
super("sentinel");
}
@@ -113,9 +125,6 @@ public SentinelTrait() {
@Persist("armor")
public double armor = -1.0;

public static final int healthMin = 1;
public static final int healthMax = 2000;

@Persist("health")
public double health = 20.0;

@@ -131,15 +140,9 @@ public SentinelTrait() {
@Persist("fightback")
public boolean fightback = true;

public static final int attackRateMin = 10;
public static final int attackRateMax = 2000;

@Persist("attackRate")
public int attackRate = 30;

public static final int healRateMin = 0;
public static final int healRateMax = 2000;

@Persist("healRate")
public int healRate = 30;

@@ -11,33 +11,27 @@
import net.citizensnpcs.api.npc.NPC;

public class SentryImport implements Listener {

// Converts sentries to sentinels. Returns the number of NPCs converted
@SuppressWarnings("deprecation")

/**
* 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();
// This can happen if citizens was reloaded
if (sentry == null) {
continue;
}
convertedCount++;

// Now we've got our instance, lets create the sentinel trait instead
npc.removeTrait(SentryTrait.class);
if (!npc.hasTrait(SentinelTrait.class)) {
npc.addTrait(SentinelTrait.class);
}
SentinelTrait sentinel = npc.getTrait(SentinelTrait.class);

// Import time, import everything as best as we can
sentinel.armor = sentry.Armor;
sentinel.attackRate = (int)Math.ceil(sentry.AttackRateSeconds * 20);
sentinel.attackRate = (int)(sentry.AttackRateSeconds * 20);
if (sentinel.attackRate < SentinelTrait.attackRateMin) {
sentinel.attackRate = SentinelTrait.attackRateMin;
}
@@ -46,84 +40,122 @@ else if (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 < SentinelTrait.healRateMin) {
sentinel.healRate = SentinelTrait.healRateMin;
}
else if (sentinel.healRate > SentinelTrait.healRateMax) {
sentinel.healRate = SentinelTrait.healRateMax;
}

// Import targets
for (String t: sentry.validTargets){
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.MOBS);
sentinel.targets.add(SentinelTarget.PLAYERS);
sentinel.targets.add(SentinelTarget.NPCS);
}
else if(t.contains("ENTITY:MONSTER")) {
else if (t.contains("ENTITY:MONSTER")) {
sentinel.targets.add(SentinelTarget.MONSTERS);
}
else if(t.contains("ENTITY:PLAYER")) {
else if (t.contains("ENTITY:PLAYER")) {
sentinel.targets.add(SentinelTarget.PLAYERS);
}
else if(t.contains("ENTITY:NPC")) {
else if (t.contains("ENTITY:NPC")) {
sentinel.targets.add(SentinelTarget.NPCS);
}
else{
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) {
// 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")) {
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")) {
else if (sections[0].equals("PLAYER")) {
sentinel.playerNameTargets.add(sections[1]);
}
else if(sections[0].equals("ENTITY")) {
else if (sections[0].equals("ENTITY")) {
SentinelTarget target = SentinelTarget.forName(sections[1]);
if (target != null) {
sentinel.targets.add(target);
}
}
/*
These target specifiers are not implemented in Sentinel yet and so can't be imported
else if (sections[0].equals("EVENT"))
else if (sections[0].equals("FACTION"))
else if (sections[0].equals("FACTIONENEMIES"))
else if (sections[0].equals("TOWN"))
else if (sections[0].equals("NATIONENEMIES"))
else if (sections[0].equals("NATION"))
else if (sections[0].equals("WARTEAM"))
else if (sections[0].equals("TEAM"))
else if (sections[0].equals("CLAN"))
*/
}
}
// Import ignores, remove default ignore OWNER
sentinel.ignores.remove(SentinelTarget.OWNER);
for (String t: sentry.ignoreTargets){
}
for (String t: sentry.ignoreTargets) {
if (t.contains("ENTITY:ALL")) {
sentinel.ignores.add(SentinelTarget.MOBS);
sentinel.ignores.add(SentinelTarget.PLAYERS);
sentinel.ignores.add(SentinelTarget.NPCS);
}
else if(t.contains("ENTITY:MONSTER")) {
else if (t.contains("ENTITY:MONSTER")) {
sentinel.ignores.add(SentinelTarget.MONSTERS);
}
else if(t.contains("ENTITY:PLAYER")) {
else if (t.contains("ENTITY:PLAYER")) {
sentinel.ignores.add(SentinelTarget.PLAYERS);
}
else if(t.contains("ENTITY:NPC")) {
else if (t.contains("ENTITY:NPC")) {
sentinel.ignores.add(SentinelTarget.NPCS);
}
else if(t.contains("ENTITY:OWNER")) {
else if (t.contains("ENTITY:OWNER")) {
sentinel.ignores.add(SentinelTarget.OWNER);
}
else{
else {
String[] sections = t.split(":");
if (sections.length != 2) {
// Invalid target identifier?
@@ -132,85 +164,25 @@ else if(t.contains("ENTITY:OWNER")) {
// Sentry was spacing tolerant, so we should be too.
sections[0] = sections[0].trim();
sections[1] = sections[1].trim();
if(sections[0].equals("NPC")) {
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")) {
else if (sections[0].equals("PLAYER")) {
sentinel.playerNameIgnores.add(sections[1]);
}
else if(sections[0].equals("ENTITY")) {
else if (sections[0].equals("ENTITY")) {
SentinelTarget target = SentinelTarget.forName(sections[1]);
if (target != null) {
sentinel.ignores.add(target);
}
}
/*
These target specifiers are not implemented in Sentinel yet and so can't be imported
else if (sections[0].equals("EVENT"))
else if (sections[0].equals("FACTION"))
else if (sections[0].equals("TOWN"))
else if (sections[0].equals("NATION"))
else if (sections[0].equals("WARTEAM"))
else if (sections[0].equals("TEAM"))
else if (sections[0].equals("CLAN"))
*/
}
}
sentinel.fightback = sentry.Retaliate;


// We need to convert the absolutely insane way sentry handled heal rate, into seconds per health
double hpHealedPerPeriod = 1;
if (sentry.HealRate < .5) {
hpHealedPerPeriod = .5 / sentry.HealRate;
}
// The healRate is both used to calculate the hp healed per period, as well as defining
// the period itself.
double secondsPerHpPoint = sentry.HealRate / hpHealedPerPeriod;
// Finally convert to ticks for sentinel and check bounds
sentinel.healRate = (int)Math.ceil(20 * secondsPerHpPoint);
if (sentinel.healRate < SentinelTrait.healRateMin) {
sentinel.healRate = SentinelTrait.healRateMin;
}
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;
// With sentries, they'll always attack anything they can see
// Projectile range and chaseRange are always equal for them
sentinel.range = sentry.sentryRange;
sentinel.rangedChase = false;
sentinel.respawnTime = sentry.RespawnDelaySeconds * 20;
sentinel.safeShot = false;
sentinel.spawnPoint = sentry.Spawn;

// Sentry uses player name to determine who its guarding, we'll need to
// convert to UUID if we can
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);
}
}
}
npc.removeTrait(SentryTrait.class);
}
return convertedCount;
}


}
@@ -41,4 +41,4 @@ random:
update rate: 10

# Do not touch!
config version: 2
config version: 3
@@ -66,9 +66,9 @@ permissions:
sentinel.kill: true
# /sentinel respawn
sentinel.respawn: true
# /sentinel sentryimport
sentinel.sentryimport: true
# /sentinel info, /sentinel targets, /sentinel stats
sentinel.info: true
# Edit other people's NPCs
sentinel.admin: true
# Import sentry data
sentinel.sentryimport: true

0 comments on commit 59ffb8c

Please sign in to comment.
You can’t perform that action at this time.