mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 08:45:11 +00:00
Added handler support to NPC API.
This commit is contained in:
1 parent
69f96519dc
commit
d50f51e208
40 files changed
+1471
-56
No files matched your search
@@ -6,7 +6,9 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
@@ -15,8 +17,12 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.scripted.handler.IFactionHandler;
|
||||
import noppes.npcs.scripted.handler.data.IFaction;
|
||||
|
||||
public class FactionController {
|
||||
public class FactionController implements IFactionHandler {
|
||||
public HashMap<Integer,Faction> factions;
|
||||
|
||||
private static FactionController instance;
|
||||
@@ -124,10 +130,14 @@ public class FactionController {
|
||||
}
|
||||
}
|
||||
|
||||
public Faction getFaction(int faction) {
|
||||
public Faction get(int faction) {
|
||||
return factions.get(faction);
|
||||
}
|
||||
|
||||
public List<IFaction> list() {
|
||||
return new ArrayList(this.factions.values());
|
||||
}
|
||||
|
||||
public void saveFaction(Faction faction) {
|
||||
|
||||
if(faction.id < 0){
|
||||
@@ -145,6 +155,30 @@ public class FactionController {
|
||||
factions.put(faction.id, faction);
|
||||
saveFactions();
|
||||
}
|
||||
|
||||
public Faction create(Faction faction) {
|
||||
String name = faction.getName();
|
||||
int color = faction.getColor();
|
||||
|
||||
for(faction = new Faction(); this.hasName(name); name = name + "_") {
|
||||
}
|
||||
|
||||
faction.name = name;
|
||||
faction.color = color;
|
||||
this.saveFaction(faction);
|
||||
return faction;
|
||||
}
|
||||
|
||||
public Faction create(String name, int color) {
|
||||
Faction faction;
|
||||
for(faction = new Faction(); this.hasName(name); name = name + "_") {
|
||||
}
|
||||
|
||||
faction.name = name;
|
||||
faction.color = color;
|
||||
this.saveFaction(faction);
|
||||
return faction;
|
||||
}
|
||||
|
||||
public int getUnusedId(){
|
||||
if(lastUsedID == 0){
|
||||
@@ -155,11 +189,20 @@ public class FactionController {
|
||||
lastUsedID++;
|
||||
return lastUsedID;
|
||||
}
|
||||
public void removeFaction(int id) {
|
||||
if(id < 0 || factions.size() <= 1)
|
||||
return;
|
||||
factions.remove(id);
|
||||
saveFactions();
|
||||
public IFaction delete(int id) {
|
||||
if (id >= 0 && this.factions.size() > 1) {
|
||||
Faction faction = (Faction)this.factions.remove(id);
|
||||
saveFactions();
|
||||
if (faction == null) {
|
||||
return null;
|
||||
} else {
|
||||
this.saveFactions();
|
||||
faction.id = -1;
|
||||
return faction;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getFirstFactionId() {
|
||||
|
||||
Reference in new issue
Block a user