Compare commits

..
8 Commits
Author SHA1 Message Date
Martin Robertz 1afc652dc4 Merge pull request #11 from GTNewHorizons/describeUndo
Fix NPE
2022-05-11 22:03:07 +02:00
Martin Robertz 356fbdbdcc Merge pull request #12 from GTNewHorizons/fix-long-chat-crash
Add a chat message length limit to avoid crashing with too big packets
2022-05-06 18:23:42 +02:00
Jakub Szewczyk 1d76f7db78 Do not trim messages for rcon&dedicated server 2022-05-06 09:04:58 +01:00
Jakub Szewczyk 8abb3efbfb Add a chat message length limit to avoid crashing with too big packets sent to clients. 2022-05-05 20:26:18 +01:00
miozune b86eeb4cc6 ic2 maven 2022-05-02 17:02:42 +09:00
miozune a7f9afb6c4 Fix NPE 2022-05-02 14:49:21 +09:00
Martin Robertz 236744c74e Merge pull request #10 from GTNewHorizons/fix/loot-function-warning
Fix runtime warning
2022-03-05 12:26:41 +01:00
Glease eb2b529dea Fix runtime warning 2022-03-05 03:28:37 +08:00
9 changed files with 54 additions and 45 deletions

No files matched your search

+2 -2
View File
@@ -1,4 +1,4 @@
//version: 1646409286 //version: 1650343995
/* /*
DO NOT CHANGE THIS FILE! DO NOT CHANGE THIS FILE!
@@ -568,7 +568,7 @@ publishing {
artifact source: shadowJar, classifier: "" artifact source: shadowJar, classifier: ""
} }
if(!noPublishedSources) { if(!noPublishedSources) {
artifact source: sourcesJar, classifier: "src" artifact source: sourcesJar, classifier: "sources"
} }
artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev" artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev"
if (apiPackage) { if (apiPackage) {
+1
View File
@@ -8,6 +8,7 @@ repositories {
maven { maven {
name = "ic2" name = "ic2"
url = "https://maven.ic2.player.to/" url = "https://maven.ic2.player.to/"
url = "https://maven2.ic2.player.to/"
metadataSources { metadataSources {
mavenPom() mavenPom()
artifact() artifact()
@@ -35,6 +35,8 @@ public interface IPlayer {
@ZenMethod @ZenMethod
void sendChat(IChatMessage message); void sendChat(IChatMessage message);
int MAX_CHAT_MESSAGE_LENGTH = 512;
@ZenMethod @ZenMethod
void sendChat(String message); void sendChat(String message);
@@ -12,7 +12,5 @@ public interface ILootFunction {
String getName(); String getName();
@ZenSetter @ZenSetter
void setName(); void setName(String name);
} }
@@ -37,22 +37,22 @@ public class CommandBlockPlayer implements IPlayer{
public IData getData(){ public IData getData(){
return null; return null;
} }
@Override @Override
public int getXP() { public int getXP() {
return 0; return 0;
} }
@Override @Override
public void setXP(int xp) { public void setXP(int xp) {
} }
@Override @Override
public void removeXP(int xp) { public void removeXP(int xp) {
} }
@Override @Override
public void update(IData data){ public void update(IData data){
@@ -70,6 +70,10 @@ public class CommandBlockPlayer implements IPlayer{
@Override @Override
public void sendChat(String message){ public void sendChat(String message){
if (message.length() > MAX_CHAT_MESSAGE_LENGTH)
{
message = message.substring(0, MAX_CHAT_MESSAGE_LENGTH);
}
sender.addChatMessage(new ChatComponentText(message)); sender.addChatMessage(new ChatComponentText(message));
} }
@@ -51,25 +51,25 @@ public class MCPlayer implements IPlayer {
public IData getData() { public IData getData() {
return NBTConverter.from(player.getEntityData(), true); return NBTConverter.from(player.getEntityData(), true);
} }
@Override @Override
public int getXP() { public int getXP() {
return player.experienceLevel; return player.experienceLevel;
} }
@Override @Override
public void setXP(int xp) { public void setXP(int xp) {
player.experienceLevel = 0; player.experienceLevel = 0;
player.addExperienceLevel(xp); player.addExperienceLevel(xp);
} }
@Override @Override
public void removeXP(int xp) { public void removeXP(int xp) {
final int newLvl = Math.max(0, player.experienceLevel - xp); final int newLvl = Math.max(0, player.experienceLevel - xp);
player.experienceLevel = 0; player.experienceLevel = 0;
player.addExperienceLevel(newLvl); player.addExperienceLevel(newLvl);
} }
@Override @Override
public void update(IData data) { public void update(IData data) {
NBTConverter.updateMap(player.getEntityData(), data); NBTConverter.updateMap(player.getEntityData(), data);
@@ -87,6 +87,10 @@ public class MCPlayer implements IPlayer {
@Override @Override
public void sendChat(String message) { public void sendChat(String message) {
if (message.length() > MAX_CHAT_MESSAGE_LENGTH)
{
message = message.substring(0, MAX_CHAT_MESSAGE_LENGTH);
}
player.addChatMessage(new ChatComponentText(message)); player.addChatMessage(new ChatComponentText(message));
} }
@@ -38,22 +38,22 @@ public class RconPlayer implements IPlayer {
public IData getData() { public IData getData() {
return null; return null;
} }
@Override @Override
public int getXP() { public int getXP() {
return 0; return 0;
} }
@Override @Override
public void setXP(int xp) { public void setXP(int xp) {
} }
@Override @Override
public void removeXP(int xp) { public void removeXP(int xp) {
} }
@Override @Override
public void update(IData data) { public void update(IData data) {
@@ -170,7 +170,7 @@ public final class MCRecipeManager implements IRecipeManager {
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) { public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) {
if(checkShapelessNulls(output, ingredients)) if(checkShapelessNulls(output, ingredients))
return; return;
recipesToAdd.add(new ActionAddShapelessRecipe(output, ingredients, function, action)); recipesToAdd.add(new ActionAddShapelessRecipe(output, ingredients, function, action));
} }
@@ -267,7 +267,7 @@ public final class MCRecipeManager implements IRecipeManager {
return getIItemStack(result); return getIItemStack(result);
} }
} }
public abstract static class ActionBaseRemoveRecipes implements IUndoableAction { public abstract static class ActionBaseRemoveRecipes implements IUndoableAction {
public abstract boolean matches(IRecipe r); public abstract boolean matches(IRecipe r);
public abstract Set<IRecipe> find(); public abstract Set<IRecipe> find();
@@ -284,7 +284,7 @@ public final class MCRecipeManager implements IRecipeManager {
public void addOutput(IIngredient output, @Optional boolean nbtMatch) { public void addOutput(IIngredient output, @Optional boolean nbtMatch) {
outputs.add(Pair.of(output, nbtMatch)); outputs.add(Pair.of(output, nbtMatch));
} }
public void clearOutputs() { public void clearOutputs() {
outputs.clear(); outputs.clear();
} }
@@ -350,13 +350,13 @@ public final class MCRecipeManager implements IRecipeManager {
} }
} }
public static class ActionRemoveShapelessRecipes extends ActionBaseRemoveRecipes implements IUndoableAction { public static class ActionRemoveShapelessRecipes extends ActionBaseRemoveRecipes implements IUndoableAction {
final IIngredient output; final IIngredient output;
final IIngredient[] ingredients; final IIngredient[] ingredients;
final boolean wildcard; final boolean wildcard;
Set<IRecipe> toRemove = new HashSet<>(); Set<IRecipe> toRemove = new HashSet<>();
public ActionRemoveShapelessRecipes(IIngredient output, IIngredient[] ingredients, boolean wildcard) { public ActionRemoveShapelessRecipes(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
this.output = output; this.output = output;
this.ingredients = ingredients; this.ingredients = ingredients;
@@ -434,7 +434,7 @@ public final class MCRecipeManager implements IRecipeManager {
public void apply() { public void apply() {
toRemove = find(); toRemove = find();
MineTweakerAPI.logInfo("Removing " + toRemove.size() + " Shapeless recipes."); MineTweakerAPI.logInfo("Removing " + toRemove.size() + " Shapeless recipes.");
super.removeRecipes(toRemove); super.removeRecipes(toRemove);
} }
@Override @Override
@@ -468,7 +468,7 @@ public final class MCRecipeManager implements IRecipeManager {
return null; return null;
} }
} }
public static class ActionRemoveShapedRecipes extends ActionBaseRemoveRecipes implements IUndoableAction { public static class ActionRemoveShapedRecipes extends ActionBaseRemoveRecipes implements IUndoableAction {
final IIngredient output; final IIngredient output;
final IIngredient[][] ingredients; final IIngredient[][] ingredients;
@@ -548,7 +548,7 @@ public final class MCRecipeManager implements IRecipeManager {
toRemove = find(); toRemove = find();
MineTweakerAPI.logInfo(toRemove.size() + " removed"); MineTweakerAPI.logInfo(toRemove.size() + " removed");
super.removeRecipes(toRemove); super.removeRecipes(toRemove);
} }
@Override @Override
@@ -582,20 +582,20 @@ public final class MCRecipeManager implements IRecipeManager {
return null; return null;
} }
} }
public static class ActionBaseAddRecipe implements IUndoableAction { public static class ActionBaseAddRecipe implements IUndoableAction {
private final IRecipe iRecipe; private final IRecipe iRecipe;
private final ICraftingRecipe craftingRecipe; private final ICraftingRecipe craftingRecipe;
protected final IItemStack output; protected final IItemStack output;
protected final boolean isShaped; protected final boolean isShaped;
protected final boolean isRestoring; protected final boolean isRestoring;
private ActionBaseAddRecipe(IRecipe iRecipe) { private ActionBaseAddRecipe(IRecipe iRecipe) {
this.iRecipe = iRecipe; this.iRecipe = iRecipe;
this.craftingRecipe = null; this.craftingRecipe = null;
this.isRestoring = true; this.isRestoring = true;
this.isShaped = iRecipe instanceof ShapedRecipes; this.isShaped = iRecipe instanceof ShapedRecipes;
this.output = new MCItemStack(iRecipe.getRecipeOutput()); this.output = new MCItemStack(iRecipe.getRecipeOutput());
} }
@@ -604,10 +604,10 @@ public final class MCRecipeManager implements IRecipeManager {
this.iRecipe = RecipeConverter.convert(craftingRecipe); this.iRecipe = RecipeConverter.convert(craftingRecipe);
this.craftingRecipe = craftingRecipe; this.craftingRecipe = craftingRecipe;
this.isRestoring = false; this.isRestoring = false;
this.output = output; this.output = output;
this.isShaped = isShaped; this.isShaped = isShaped;
} }
@Override @Override
@@ -639,7 +639,7 @@ public final class MCRecipeManager implements IRecipeManager {
@Override @Override
public String describeUndo() { public String describeUndo() {
return "Undoing addition of " + output.getDisplayName(); return "Undoing addition of " + (output != null ? output.getDisplayName() : "invalid output");
} }
@Override @Override
@@ -653,7 +653,7 @@ public final class MCRecipeManager implements IRecipeManager {
super(new ShapedRecipe(output, ingredients, function, action, mirrored), output, true); super(new ShapedRecipe(output, ingredients, function, action, mirrored), output, true);
} }
} }
private static class ActionAddShapelessRecipe extends ActionBaseAddRecipe { private static class ActionAddShapelessRecipe extends ActionBaseAddRecipe {
public ActionAddShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) { public ActionAddShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) {
super(new ShapelessRecipe(output, ingredients, function, action), output, false); super(new ShapelessRecipe(output, ingredients, function, action), output, false);
@@ -698,7 +698,7 @@ public final class MCRecipeManager implements IRecipeManager {
return null; return null;
} }
} }
public static void applyAdditionsAndRemovals() { public static void applyAdditionsAndRemovals() {
System.out.println("MineTweaker: Applying additions and removals"); System.out.println("MineTweaker: Applying additions and removals");
MineTweakerAPI.apply(MCRecipeManager.actionRemoveRecipesNoIngredients); MineTweakerAPI.apply(MCRecipeManager.actionRemoveRecipesNoIngredients);
@@ -722,7 +722,7 @@ public final class MCRecipeManager implements IRecipeManager {
recipesToRemove.forEach(ActionBaseRemoveRecipes::apply); recipesToRemove.forEach(ActionBaseRemoveRecipes::apply);
} }
MCRecipeManager.recipesToAdd.forEach(MineTweakerAPI::apply); MCRecipeManager.recipesToAdd.forEach(MineTweakerAPI::apply);
actionRemoveRecipesNoIngredients.clearOutputs(); actionRemoveRecipesNoIngredients.clearOutputs();
recipesToRemove.clear();; recipesToRemove.clear();;
recipesToAdd.clear(); recipesToAdd.clear();
@@ -48,22 +48,22 @@ public class ServerPlayer implements IPlayer {
// TODO: implement // TODO: implement
return null; return null;
} }
@Override @Override
public int getXP() { public int getXP() {
return 0; return 0;
} }
@Override @Override
public void setXP(int xp) { public void setXP(int xp) {
} }
@Override @Override
public void removeXP(int xp) { public void removeXP(int xp) {
} }
@Override @Override
public void update(IData data) { public void update(IData data) {
// TODO: implement // TODO: implement