mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 10:49:47 +00:00
Merge branch 'packet' into animation-events-2
This commit is contained in:
commit
16f2901fbc
119 files changed
+2688
-931
No files matched your search
@@ -34,7 +34,6 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
public HashMap<Integer, HashMap<Integer, CustomEffect>> indexMapper = new HashMap<>();
|
||||
|
||||
public HashMap<Integer, CustomEffect> customEffectsSync = new HashMap<>();
|
||||
public HashMap<Integer, CustomEffect> customEffects = new HashMap<>();
|
||||
|
||||
public HashMap<Integer, EffectScript> customEffectScriptHandlers = new HashMap<>();
|
||||
private HashMap<Integer, String> bootOrder;
|
||||
@@ -42,15 +41,21 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
private int lastUsedID = 0;
|
||||
public ConcurrentHashMap<UUID, ConcurrentHashMap<EffectKey, PlayerEffect>> playerEffects = new ConcurrentHashMap<>();
|
||||
|
||||
public CustomEffectController() {}
|
||||
public CustomEffectController(){
|
||||
HashMap<Integer, CustomEffect> customEffects = new HashMap<>();
|
||||
registerEffectMap(0, customEffects);
|
||||
}
|
||||
|
||||
public static CustomEffectController getInstance() {
|
||||
return Instance;
|
||||
}
|
||||
|
||||
public <T extends CustomEffect> void registerEffectMap(int index, HashMap<Integer, T> effectHashMap) {
|
||||
HashMap<Integer, CustomEffect> map = new HashMap<>(effectHashMap);
|
||||
indexMapper.put(index, map);
|
||||
indexMapper.put(index, (HashMap<Integer, CustomEffect>) effectHashMap);
|
||||
}
|
||||
|
||||
public HashMap<Integer, CustomEffect> getCustomEffects(){
|
||||
return indexMapper.get(0);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
@@ -104,12 +109,12 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
|
||||
if (effect.id == -1) {
|
||||
int id = getUnusedId();
|
||||
while (customEffects.containsKey(id)) {
|
||||
while (getCustomEffects().containsKey(id)) {
|
||||
id = getUnusedId();
|
||||
}
|
||||
effect.id = id;
|
||||
}
|
||||
customEffects.put(effect.id, effect);
|
||||
getCustomEffects().put(effect.id, effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -122,14 +127,14 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
public void deleteEffect(String name) {
|
||||
ICustomEffect effect = getEffect(name);
|
||||
if (effect != null) {
|
||||
CustomEffect foundEffect = customEffects.remove(effect.getID());
|
||||
CustomEffect foundEffect = getCustomEffects().remove(effect.getID());
|
||||
customEffectScriptHandlers.remove(effect.getID());
|
||||
if (foundEffect != null && foundEffect.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equals(foundEffect.name + ".json")) {
|
||||
if (file.getName().equalsIgnoreCase(foundEffect.name + ".json")) {
|
||||
file.delete();
|
||||
SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
break;
|
||||
@@ -143,14 +148,14 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
public void delete(int id) {
|
||||
ICustomEffect effect = get(id);
|
||||
if (effect != null) {
|
||||
CustomEffect foundEffect = customEffects.remove(effect.getID());
|
||||
CustomEffect foundEffect = getCustomEffects().remove(effect.getID());
|
||||
customEffectScriptHandlers.remove(effect.getID());
|
||||
if (foundEffect != null && foundEffect.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equals(foundEffect.name + ".json")) {
|
||||
if (file.getName().equalsIgnoreCase(foundEffect.name + ".json")) {
|
||||
file.delete();
|
||||
SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
break;
|
||||
@@ -162,7 +167,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
}
|
||||
|
||||
public int getUnusedId() {
|
||||
for (int catid : customEffects.keySet()) {
|
||||
for (int catid : getCustomEffects().keySet()) {
|
||||
if (catid > lastUsedID)
|
||||
lastUsedID = catid;
|
||||
}
|
||||
@@ -299,15 +304,13 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
customEffect.setID(getUnusedId());
|
||||
while (has(customEffect.getName()))
|
||||
customEffect.setName(customEffect.getName() + "_");
|
||||
} else {
|
||||
CustomEffect existing = customEffects.get(customEffect.getID());
|
||||
if (existing != null && !existing.name.equals(customEffect.getName()))
|
||||
while (has(customEffect.getName()))
|
||||
customEffect.setName(customEffect.getName() + "_");
|
||||
}
|
||||
|
||||
customEffects.remove(customEffect.getID());
|
||||
customEffects.put(customEffect.getID(), (CustomEffect) customEffect);
|
||||
while (hasOther(customEffect.getName(), customEffect.getID()))
|
||||
customEffect.setName(customEffect.getName() + "_");
|
||||
|
||||
getCustomEffects().remove(customEffect.getID());
|
||||
getCustomEffects().put(customEffect.getID(), (CustomEffect) customEffect);
|
||||
|
||||
saveEffectLoadMap();
|
||||
|
||||
@@ -329,7 +332,15 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
return customEffects.get(customEffect.getID());
|
||||
return getCustomEffects().get(customEffect.getID());
|
||||
}
|
||||
|
||||
private boolean hasOther(String name, int id) {
|
||||
for (CustomEffect effect : getCustomEffects().values()) {
|
||||
if (effect.getID() != id && effect.getName().equalsIgnoreCase(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clearEffects(EntityPlayer player) {
|
||||
@@ -377,7 +388,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
Map<EffectKey, PlayerEffect> currentEffects = getPlayerEffects(player);
|
||||
CustomEffect parent = get(id, index);
|
||||
if (parent != null) {
|
||||
PlayerEffect playerEffect = new PlayerEffect(id, duration, level);
|
||||
PlayerEffect playerEffect = new PlayerEffect(id, duration, level, index);
|
||||
playerEffect.index = index;
|
||||
currentEffects.put(new EffectKey(id, index), playerEffect);
|
||||
parent.onAdded(player, playerEffect);
|
||||
@@ -418,7 +429,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
if (effect.duration == -100)
|
||||
continue;
|
||||
if (effect.duration <= 0) {
|
||||
CustomEffect parent = CustomEffectController.Instance.get(effect.id);
|
||||
CustomEffect parent = CustomEffectController.Instance.get(effect.id, effect.index);
|
||||
if (parent != null) {
|
||||
parent.onRemoved(player, effect, ExpirationType.RUN_OUT);
|
||||
}
|
||||
@@ -437,7 +448,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
}
|
||||
|
||||
private void loadCustomEffects() {
|
||||
customEffects.clear();
|
||||
getCustomEffects().clear();
|
||||
|
||||
File dir = getDir();
|
||||
if (!dir.exists()) {
|
||||
@@ -455,9 +466,9 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
}
|
||||
int originalID = effect.id;
|
||||
int setID = effect.id;
|
||||
while (bootOrder.containsKey(setID) || customEffects.containsKey(setID)) {
|
||||
while (bootOrder.containsKey(setID) || getCustomEffects().containsKey(setID)) {
|
||||
if (bootOrder.containsKey(setID))
|
||||
if (bootOrder.get(setID).equals(effect.name))
|
||||
if (bootOrder.get(setID).equalsIgnoreCase(effect.name))
|
||||
break;
|
||||
setID++;
|
||||
}
|
||||
@@ -466,13 +477,13 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
LogWriter.info("Found Custom Effect ID Mismatch: " + effect.name + ", New ID: " + setID);
|
||||
effect.save();
|
||||
}
|
||||
customEffects.put(effect.id, effect);
|
||||
getCustomEffects().put(effect.id, effect);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
registerEffectMap(0, customEffects);
|
||||
this.registerEffectMap(0, getCustomEffects());
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
|
||||
@@ -513,8 +524,8 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
private NBTTagCompound writeMapNBT() {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
NBTTagList customEffectsList = new NBTTagList();
|
||||
for (Integer key : this.customEffects.keySet()) {
|
||||
CustomEffect customEffect = this.customEffects.get(key);
|
||||
for (Integer key : this.getCustomEffects().keySet()) {
|
||||
CustomEffect customEffect = this.getCustomEffects().get(key);
|
||||
if (!customEffect.getName().isEmpty()) {
|
||||
NBTTagCompound effectCompound = new NBTTagCompound();
|
||||
effectCompound.setString("Name", customEffect.getName());
|
||||
|
||||
@@ -12,34 +12,11 @@ public class PlayerEffect implements IPlayerEffect {
|
||||
public byte level;
|
||||
public int index;
|
||||
|
||||
public PlayerEffect(int id, int duration, byte level) {
|
||||
public PlayerEffect(int id, int duration, byte level, int index) {
|
||||
this.id = id;
|
||||
this.duration = duration;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public static PlayerEffect readEffectData(NBTTagCompound nbt) {
|
||||
int id = nbt.getInteger("Id");
|
||||
int index = nbt.getInteger("Index");
|
||||
if (id > 0) {
|
||||
CustomEffectController controller = CustomEffectController.getInstance();
|
||||
boolean found = controller.has(id);
|
||||
// StatusEffectController.getInstance().customEffects.containsKey(id);
|
||||
if (found) {
|
||||
byte level = nbt.getByte("Level");
|
||||
int dur = nbt.getInteger("Dur");
|
||||
return new PlayerEffect(id, dur, level);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeEffectData(NBTTagCompound nbt) {
|
||||
nbt.setInteger("Id", this.id);
|
||||
nbt.setByte("Level", this.level);
|
||||
nbt.setInteger("Dur", this.duration);
|
||||
nbt.setInteger("Index", this.index);
|
||||
return nbt;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,7 +51,7 @@ public class PlayerEffect implements IPlayerEffect {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
CustomEffect effect = CustomEffectController.getInstance().get(this.id);
|
||||
CustomEffect effect = CustomEffectController.getInstance().get(this.id, this.index);
|
||||
if(effect != null)
|
||||
return effect.getName();
|
||||
|
||||
@@ -84,7 +61,7 @@ public class PlayerEffect implements IPlayerEffect {
|
||||
@Override
|
||||
public void performEffect(IPlayer player) {
|
||||
if (player != null && player.getMCEntity() != null && player.getMCEntity() instanceof EntityPlayer) {
|
||||
CustomEffect effect = CustomEffectController.getInstance().get(this.id);
|
||||
CustomEffect effect = CustomEffectController.getInstance().get(this.id, this.index);
|
||||
if(effect != null)
|
||||
effect.onTick((EntityPlayer) player.getMCEntity(), this);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ public class PlayerEffectData {
|
||||
effect.duration = duration;
|
||||
effect.level = level;
|
||||
} else {
|
||||
effect = new PlayerEffect(id, duration, level);
|
||||
effect.index = index;
|
||||
effect = new PlayerEffect(id, duration, level, index);
|
||||
effects.put(key, effect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ public class RecipesDefault {
|
||||
addRecipe("Mob Cloner", CustomItems.cloner, true, "XX","XY"," Y",'X', Items.bread,'Y', Items.stick);
|
||||
addRecipe("Carpentry Bench", CustomItems.carpentyBench, true, "XYX","Z Z","Z Z", 'X', Blocks.planks, 'Z', Items.stick, 'Y', Blocks.crafting_table);
|
||||
|
||||
ItemStack anvil = new ItemStack(CustomItems.carpentyBench);
|
||||
anvil.setItemDamage(1);
|
||||
addRecipe("Anvil", anvil, true, "XXX","Z Z","Z Z", 'X', Blocks.iron_block, 'Z', Items.iron_ingot);
|
||||
|
||||
if(!ConfigMain.DisableExtraItems){
|
||||
addRecipe("Mana", CustomItems.mana, true, "XY",'X',Items.redstone,'Y',Items.glowstone_dust);
|
||||
addRecipe("Gun Wooden", CustomItems.gunWood, false, "XXXY"," ZM "," M ",'Y', Blocks.lever, 'M', Items.stick, 'Z', Blocks.stone_button,'X', Blocks.planks);
|
||||
@@ -146,7 +150,7 @@ public class RecipesDefault {
|
||||
addRecipe("Sign Wood5", new ItemStack(CustomItems.sign, 1, 4), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,4), 'Y', Items.iron_ingot);
|
||||
addRecipe("Sign Wood6", new ItemStack(CustomItems.sign, 1, 5), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,5), 'Y', Items.iron_ingot);
|
||||
|
||||
addRecipe("Lamp", new ItemStack(CustomItems.lamp), false, "XXX","YZY","XXX", 'X', Items.iron_ingot, 'Y', Blocks.glass, 'Z', Blocks.torch);
|
||||
addRecipe("Lamp", new ItemStack(CustomItems.lantern), false, "XXX","YZY","XXX", 'X', Items.iron_ingot, 'Y', Blocks.glass, 'Z', Blocks.torch);
|
||||
addRecipe("Candle", new ItemStack(CustomItems.candle), false, "XZX"," X ", 'X', Items.iron_ingot, 'Z', Blocks.torch);
|
||||
addRecipe("BigSign", new ItemStack(CustomItems.bigsign, 2), false, "XXX","XXX","XXX", 'X', Blocks.planks);
|
||||
|
||||
|
||||
Reference in new issue
Block a user