Compare commits

...
6 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
8 changed files with 53 additions and 42 deletions

No files matched your search

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