Solved Add a library?

Discussion in 'Plugin Development' started by ZachBora, May 6, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ZachBora

    Hello,

    Say I would like to add a library to my plugin, like the org.apache.commons.Collections, is there a way to do this without having to force the server owner to download something?

    I am using Maven. I know that Bukkit uses a part of apache commons but it doesn't seem to include collections.
     
  2. Offline

    xize

    ZachBora

    have you tried the craftbukkit package instead of the bukkit package?

    else you should add this in your pom, make sure you add apache repo to:

    Code:
          <dependency>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
      <version>3.2.1</version>
          </dependency>
     
    
    and then shade it ;-)
     
  3. Offline

    ZachBora

    xize I'll give that a try, haven't been able to try anything at all yet because Internet is down at home and I can't install java stuff at work.

    Edit: I do not want to rely on Craftbukkit.
     
  4. Offline

    ZeusAllMighty11

    You can shade it with the Maven Shade Plugin.. Makes it easily accessible but will add to your file size. Make sure to only include the pieces you need.
     
  5. Offline

    ZachBora

    I decided to use com.google.common since that's already in bukkit.

    Example plots class
    Code:java
    1.  
    2. import java.util.concurrent.ConcurrentHashMap;
    3. import org.bukkit.World;
    4. import org.bukkit.entity.Player;
    5. import com.google.common.base.Predicate;
    6. import com.google.common.collect.Maps;
    7.  
    8. public class Plots extends ConcurrentHashMap<String, Plot> {
    9.  
    10. private static final long serialVersionUID = 1L;
    11.  
    12. public void add(String id, Plot plot) {
    13. this.put(id, plot);
    14. }
    15.  
    16. public Plots filterBy(final World world) {
    17. return filter(new Predicate<Plot>() {
    18. @Override
    19. public boolean apply(Plot plot) {
    20. return plot.getWorld().equalsIgnoreCase(world.getName());
    21. }
    22. });
    23. }
    24.  
    25. public Plots filterBy(final Player player) {
    26. return filter(new Predicate<Plot>() {
    27. @Override
    28. public boolean apply(Plot plot) {
    29. return plot.getOwnerId().equals(player.getUniqueId());
    30. }
    31. });
    32. }
    33.  
    34. public Plots filter(Predicate<Plot> condition) {
    35. return (Plots) Maps.filterValues(this, condition);
    36. }
    37. }
    38.  


    Example usage
    Code:java
    1.  
    2. public void Main() {
    3. Plots plots = new Plots();
    4.  
    5. World world = Bukkit.getWorlds().get(0); //just an example
    6. Player player = world.getPlayers().get(0); //just an example
    7.  
    8. Map<String, Plot> filteredList = plots.filterBy(world).filterBy(player);
    9. }
    10.  
     
Thread Status:
Not open for further replies.

Share This Page