Skip to content

Commit

Permalink
Do not use Apache WordUtils. Wrote own wrap method.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 13, 2024
1 parent 6a2ed07 commit 8586307
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 31 deletions.
117 changes: 98 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
<!-- Some JAVA encoding settings -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>17</java.version>

<!-- SPIGOT API version -->
<spigot.version>1.15.2-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>

<!-- BentoBox API version -->
<bentobox.version>1.14.0</bentobox.version>
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>

<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
Expand Down Expand Up @@ -152,9 +152,18 @@
<!-- Build contains information for maven. It allows to create correct
jar file. -->
<build>
<!-- By default ${revision} is ${build.version}-SNAPSHOT -->
<!-- If GIT_BRANCH variable is set to origin/master, then it will
be only ${build.version}. -->

<!-- By default ${build.number} is -LOCAL. -->
<!-- If the BUILD_NUMBER variable is set, then it will be -b[number]. -->
<!-- If GIT_BRANCH variable is set to origin/master, then it will
be the empty string. -->
<finalName>${project.name}-${revision}${build.number}</finalName>

<defaultGoal>clean package</defaultGoal>

<resources>
<resource>
<directory>src/main/resources</directory>
Expand All @@ -166,6 +175,14 @@
<filtering>false</filtering>
<includes>
<include>*.yml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/blueprints</directory>
<targetPath>./blueprints</targetPath>
<filtering>false</filtering>
<includes>
<include>*.blu</include>
<include>*.json</include>
</includes>
</resource>
Expand All @@ -180,20 +197,57 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>blu</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<version>3.1.2</version>
<!--suppress MavenModelInspection -->
<configuration>
<argLine>
${argLine}
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.math=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens
java.base/java.util.stream=ALL-UNNAMED
--add-opens java.base/java.text=ALL-UNNAMED
--add-opens
java.base/java.util.regex=ALL-UNNAMED
--add-opens
java.base/java.nio.channels.spi=ALL-UNNAMED
--add-opens java.base/sun.nio.ch=ALL-UNNAMED
--add-opens java.base/java.net=ALL-UNNAMED
--add-opens
java.base/java.util.concurrent=ALL-UNNAMED
--add-opens java.base/sun.nio.fs=ALL-UNNAMED
--add-opens java.base/sun.nio.cs=ALL-UNNAMED
--add-opens java.base/java.nio.file=ALL-UNNAMED
--add-opens
java.base/java.nio.charset=ALL-UNNAMED
--add-opens
java.base/java.lang.reflect=ALL-UNNAMED
--add-opens
java.logging/java.util.logging=ALL-UNNAMED
--add-opens java.base/java.lang.ref=ALL-UNNAMED
--add-opens java.base/java.util.jar=ALL-UNNAMED
--add-opens java.base/java.util.zip=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -203,15 +257,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<version>3.3.0</version>
<configuration>
<show>public</show>
<failOnError>false</failOnError>
<additionalJOption>-Xdoclint:none</additionalJOption>
<!-- To compile with Java 11, this tag may be required -->
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>install</phase>
<goals>
<goal>jar</goal>
</goals>
Expand All @@ -233,25 +289,48 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<configuration>
<minimizeJar>true</minimizeJar>
<append>true</append>
<excludes>
<!-- This is required to prevent Jacoco from adding
synthetic fields to a JavaBean class (causes errors in testing) -->
<exclude>**/*Names*</exclude>
<!-- Prevents the Material is too large to mock error -->
<exclude>org/bukkit/Material*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<phase>package</phase>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>shade</goal>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
package world.bentobox.controlpanel.managers;


import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -22,6 +15,14 @@
import java.util.Map;
import java.util.Objects;

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database;
Expand Down Expand Up @@ -86,6 +87,7 @@ public void load()
* This method loads given controlPanelObject inside cache.
* @param controlPanelObject Object that must be added to cache.
*/
@SuppressWarnings("deprecation")
private void load(ControlPanelObject controlPanelObject)
{
// Migrate older data
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/world/bentobox/controlpanel/panels/GuiUtils.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package world.bentobox.controlpanel.panels;


import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
Expand Down Expand Up @@ -142,7 +143,7 @@ public static List<String> stringSplit(String string, int warpLength, boolean co
List<String> result = new ArrayList<>();

Arrays.stream(string.split("\\|")).
map(line -> Arrays.asList(WordUtils.wrap(line, warpLength).split(System.getProperty("line.separator")))).
map(line -> Arrays.asList(wrap(line, warpLength).split(System.getProperty("line.separator")))).
forEach(result::addAll);

// Fix colors, as splitting my lost that information.
Expand All @@ -159,6 +160,31 @@ public static List<String> stringSplit(String string, int warpLength, boolean co
return result;
}

static String wrap(String text, int maxWidth) {
BreakIterator boundary = BreakIterator.getLineInstance();
boundary.setText(text);

StringBuilder wrappedText = new StringBuilder();
int start = boundary.first();
int end = boundary.next();
int lineLength = 0;

while (end != BreakIterator.DONE) {
String word = text.substring(start, end);
lineLength += word.length();

if (lineLength >= maxWidth) {
wrappedText.append("\n");
lineLength = word.length();
}
wrappedText.append(word);
start = end;
end = boundary.next();
}

return wrappedText.toString();
}


/**
* Simple splitter
Expand Down

0 comments on commit 8586307

Please sign in to comment.