Skip to content

Commit

Permalink
Try to migrate ocelot modifiers trait for new MC versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jan 11, 2020
1 parent 44054d5 commit a0e3b23
Show file tree
Hide file tree
Showing 3 changed files with 321 additions and 295 deletions.
70 changes: 39 additions & 31 deletions main/src/main/java/net/citizensnpcs/trait/OcelotModifiers.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.trait.versioned.CatTrait;
import net.citizensnpcs.util.NMS;

/**
Expand All @@ -14,35 +15,42 @@
*/
@TraitName("ocelotmodifiers")
public class OcelotModifiers extends Trait {
@Persist("sitting")
private boolean sitting;
@Persist("type")
private Ocelot.Type type = Ocelot.Type.WILD_OCELOT;

public OcelotModifiers() {
super("ocelotmodifiers");
}

@Override
public void onSpawn() {
updateModifiers();
}

public void setSitting(boolean sit) {
this.sitting = sit;
updateModifiers();
}

public void setType(Ocelot.Type type) {
this.type = type;
updateModifiers();
}

private void updateModifiers() {
if (npc.getEntity() instanceof Ocelot) {
Ocelot ocelot = (Ocelot) npc.getEntity();
ocelot.setCatType(type);
NMS.setSitting(ocelot, sitting);
}
}
@Persist("sitting")
private boolean sitting;
@Persist("type")
private Ocelot.Type type = Ocelot.Type.WILD_OCELOT;

public OcelotModifiers() {
super("ocelotmodifiers");
}

@Override
public void onSpawn() {
updateModifiers();
}

public void setSitting(boolean sit) {
this.sitting = sit;
updateModifiers();
}

public void setType(Ocelot.Type type) {
this.type = type;
updateModifiers();
}

private void updateModifiers() {
if (npc.getEntity() instanceof Ocelot) {
Ocelot ocelot = (Ocelot) npc.getEntity();
try {
ocelot.setCatType(type);
} catch (UnsupportedOperationException ex) {
npc.getTrait(CatTrait.class).setSitting(sitting);
npc.getTrait(CatTrait.class).setType(type);
npc.removeTrait(OcelotModifiers.class);
return;
}
NMS.setSitting(ocelot, sitting);
}
}
}
108 changes: 63 additions & 45 deletions main/src/main/java/net/citizensnpcs/trait/versioned/CatTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.DyeColor;
import org.bukkit.entity.Cat;
import org.bukkit.entity.Ocelot.Type;

import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
Expand All @@ -10,49 +11,66 @@

@TraitName("cattrait")
public class CatTrait extends Trait {
@Persist
private DyeColor collarColor = null;
@Persist
private boolean lying = false;
@Persist
private boolean sitting = false;
@Persist
private Cat.Type type = Cat.Type.BLACK;

public CatTrait() {
super("cattrait");
}

public boolean isLyingDown() {
return lying;
}

@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Cat) {
Cat cat = (Cat) npc.getEntity();
cat.setSitting(sitting);
cat.setCatType(type);
if (collarColor != null) {
cat.setCollarColor(collarColor);
}
NMS.setLyingDown(cat, lying);
}
}

public void setCollarColor(DyeColor color) {
this.collarColor = color;
}

public void setLyingDown(boolean lying) {
this.lying = lying;
}

public void setSitting(boolean sitting) {
this.sitting = sitting;
}

public void setType(Cat.Type type) {
this.type = type;
}
@Persist
private DyeColor collarColor = null;
@Persist
private boolean lying = false;
@Persist
private boolean sitting = false;
@Persist
private Cat.Type type = Cat.Type.BLACK;

public CatTrait() {
super("cattrait");
}

public boolean isLyingDown() {
return lying;
}

@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Cat) {
Cat cat = (Cat) npc.getEntity();
cat.setSitting(sitting);
cat.setCatType(type);
if (collarColor != null) {
cat.setCollarColor(collarColor);
}
NMS.setLyingDown(cat, lying);
}
}

public void setCollarColor(DyeColor color) {
this.collarColor = color;
}

public void setLyingDown(boolean lying) {
this.lying = lying;
}

public void setSitting(boolean sitting) {
this.sitting = sitting;
}

public void setType(Cat.Type type) {
this.type = type;
}

public void setType(Type type2) {
switch (type2) {
case WILD_OCELOT:
this.type = Cat.Type.CALICO;
break;
case BLACK_CAT:
this.type = Cat.Type.BLACK;
break;
case RED_CAT:
this.type = Cat.Type.RED;
break;
case SIAMESE_CAT:
this.type = Cat.Type.SIAMESE;
break;
}
}
}
Loading

0 comments on commit a0e3b23

Please sign in to comment.