Skip to content

Commit

Permalink
Merge pull request #10 from LucBerge/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
LucBerge authored Dec 27, 2020
2 parents d754589 + baa7e44 commit 22fd9a7
Show file tree
Hide file tree
Showing 35 changed files with 592 additions and 464 deletions.
155 changes: 80 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,80 @@
# zSorter

The zSorter plugin allows you to manager sorting system in game. It is an alternate solution to standard slow and laggy systems.

## How it works

A sorter is a sorting system composed of multiple inputs and outputs (chests, hoppers...). Inputs and outputs are ordered by priority from 1 to infinity and outputs can handle multiple items.
An output can also be defined as an overflow.

The algorithm starts by looking for an item in the inputs. The input of priority 1 will be the first to be empty, then the 2...
If an item is found, the algorithm will list all the possible outputs and will try to put the item in the output. If the output of priority 1 is full, it will look for the output of priority 2, then 3...

## Commands

List all the existing sorters :
```
/sorter list
```

Create a sorter:
```
/sorter create <name> <description...>
```

Update a sorter description:
```
/sorter update <name> <new-description...>
```

Change a sorter speed (by default set to 1):
```
/sorter speed <name> <speed>
```

Delete a sorter:
```
/sorter delete <name>
```

Display a sorter informations (By default OUTPUTS mode):
```
/sorter info <name> <mode>
```

Enable/Disable a sorter:
```
/sorter toggle <name>
```

Define the target block as an input:
```
/sorter set_input <name> <priority>
```

Define the target block as an output (no items to define it as an overflow):
```
/sorter set_output <name> <priority> <items...>
```

Remove the target block from inputs:
```
/sorter remove_input <name>
```

Remove the target block from outputs :
```
/sorter remove_output <name>
```

## Permissions

The following permission allows you to use all the above commands.
```
zsorter.admin
```
# zSorter

The zSorter plugin allows you to manager sorting system in game. It is an alternate solution to standard slow and laggy systems.

## How it works

A sorter is a sorting system composed of multiple inputs and outputs (chests, hoppers...). Inputs and outputs are ordered by priority from 1 to infinity and outputs can handle multiple items.
An output can also be defined as an overflow.

The algorithm starts by looking for an item in the inputs. The input of priority 1 will be the first to be empty, then the 2...
If an item is found, the algorithm will list all the possible outputs and will try to put the item in the output. If the output of priority 1 is full, it will look for the output of priority 2, then 3...

## Commands

List all the existing sorters :
```
/sorter list
```

Create a sorter:
```
/sorter create <name> <description...>
```

Update a sorter description:
```
/sorter update <name> <new-description...>
```

Change a sorter speed (by default set to 1):
```
/sorter speed <name> <speed>
```

Delete a sorter:
```
/sorter delete <name>
```

Display a sorter informations (By default OUTPUTS mode):
```
/sorter info <name> <mode>
```

Enable/Disable a sorter:
```
/sorter toggle <name>
```

Define the target block as an input:
```
/sorter set_input <name> <priority>
```

Define the target block as an output (no items to define it as an overflow):
```
/sorter set_output <name> <priority> <items...>
```

Remove the target block from inputs:
```
/sorter remove_input <name>
```

Remove the target block from outputs :
```
/sorter remove_output <name>
```

Highlight all the inputs and outputs of the sorter during 1 minute. The single outputs can also be define by left clicking on a holder.
```
/sorter magic <name>
```

## Permissions

The following permission allows you to use all the above commands.
```
zsorter.admin
```
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.zcraft.zSorter</groupId>
<artifactId>zSorter</artifactId>
<version>0.3</version>
<version>0.4</version>
<build>
<plugins>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.zcraft.zSorter</groupId>
<artifactId>zSorter</artifactId>
<version>0.3</version>
<version>0.4</version>

<packaging>jar</packaging>

Expand Down
14 changes: 2 additions & 12 deletions src/main/java/fr/zcraft/zsorter/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,9 @@ public class Config extends Configuration
* The default language of the plugin.
*/
static public final ConfigurationItem<Locale> LANGUAGE = item("language", Locale.class);

/**
* The maximum number of sorter per map
*/
static public final ConfigurationItem<Integer> MAX_BANKS = item("max_sorters", 100);

/**
* The maximum inputs for one sorter.
*/
static public final ConfigurationItem<Integer> MAX_INPUTS = item("max_inputs", 100);

/**
* The maximum outputs for one sorter.
* The magic effect cooldown.
*/
static public final ConfigurationItem<Integer> MAX_OUTPUTS = item("max_ouputs", 10000);
static public final ConfigurationItem<Integer> MAGIC_EFFECT_DURATION = item("magic_effect_duration", 1200);
}
20 changes: 12 additions & 8 deletions src/main/java/fr/zcraft/zsorter/ZSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
import java.io.IOException;

import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPluginLoader;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;

import fr.zcraft.quartzlib.core.QuartzLib;
import fr.zcraft.quartzlib.core.QuartzPlugin;
import fr.zcraft.quartzlib.components.commands.Commands;
import fr.zcraft.quartzlib.components.i18n.I18n;
import fr.zcraft.quartzlib.core.QuartzPlugin;
import fr.zcraft.quartzlib.tools.PluginLogger;
import fr.zcraft.zsorter.commands.CreateCommand;
import fr.zcraft.zsorter.commands.DeleteCommand;
import fr.zcraft.zsorter.commands.InfoCommand;
import fr.zcraft.zsorter.commands.ListCommand;
import fr.zcraft.zsorter.commands.MagicCommand;
import fr.zcraft.zsorter.commands.RemoveInputCommand;
import fr.zcraft.zsorter.commands.RemoveOutputCommand;
import fr.zcraft.zsorter.commands.SetInputCommand;
Expand All @@ -34,8 +34,9 @@
import fr.zcraft.zsorter.events.HolderBreakEvent;
import fr.zcraft.zsorter.events.InventoryEvent;
import fr.zcraft.zsorter.events.ItemMoveEvent;
import fr.zcraft.zsorter.events.LeftClickEvent;
import fr.zcraft.zsorter.model.SorterManager;
import fr.zcraft.zsorter.model.serializer.InventoryAdapter;
import fr.zcraft.zsorter.model.serializer.InventoryHolderAdapter;
import fr.zcraft.zsorter.model.serializer.PostProcessAdapterFactory;
import fr.zcraft.zsorter.model.serializer.SorterManagerAdapter;
import fr.zcraft.zsorter.tasks.SortTask;
Expand Down Expand Up @@ -123,7 +124,8 @@ public void onEnable() {
this.getServer().getPluginManager().registerEvents(new HolderBreakEvent(), this);
this.getServer().getPluginManager().registerEvents(new InventoryEvent(), this);
this.getServer().getPluginManager().registerEvents(new ItemMoveEvent(), this);

this.getServer().getPluginManager().registerEvents(new LeftClickEvent(), this);

Commands.register("sorter",
ListCommand.class,
CreateCommand.class,
Expand All @@ -135,8 +137,10 @@ public void onEnable() {
SetInputCommand.class,
SetOutputCommand.class,
RemoveInputCommand.class,
RemoveOutputCommand.class
RemoveOutputCommand.class,
MagicCommand.class
);
Commands.registerShortcut("sorter", ListCommand.class, "sorters");

if(load()) {
SortTask.getInstance().start();
Expand All @@ -156,7 +160,7 @@ private void save() {
try {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapterFactory(new PostProcessAdapterFactory());
gsonBuilder.registerTypeHierarchyAdapter(Inventory.class, new InventoryAdapter());
gsonBuilder.registerTypeHierarchyAdapter(InventoryHolder.class, new InventoryHolderAdapter());
gsonBuilder.registerTypeAdapter(SorterManager.class, new SorterManagerAdapter());
Gson customGson = gsonBuilder.create();
FileWriter fr = new FileWriter(dataPath);
Expand All @@ -177,7 +181,7 @@ private boolean load() {
try {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapterFactory(new PostProcessAdapterFactory());
gsonBuilder.registerTypeHierarchyAdapter(Inventory.class, new InventoryAdapter());
gsonBuilder.registerTypeHierarchyAdapter(InventoryHolder.class, new InventoryHolderAdapter());
gsonBuilder.registerTypeAdapter(SorterManager.class, new SorterManagerAdapter());
Gson customGson = gsonBuilder.create();
BufferedReader br = new BufferedReader(new FileReader(dataFile));
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/fr/zcraft/zsorter/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.zcraft.zsorter.commands;

import java.util.List;
import java.util.stream.Collectors;

import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo;
Expand Down Expand Up @@ -38,10 +37,7 @@ protected void run() throws CommandException {
@Override
protected List<String> complete() throws CommandException{
if(args.length <= 1) {
return ZSorter.getInstance().getSorterManager().getNameToSorter().keySet()
.stream()
.filter(s -> s.startsWith(args[0]))
.collect(Collectors.toList());
return completeSorterName(args[0]);
}
return null;
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/fr/zcraft/zsorter/commands/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ protected void run() throws CommandException {
@Override
protected List<String> complete() throws CommandException{
if(args.length <= 1) {
return ZSorter.getInstance().getSorterManager().getNameToSorter().keySet()
.stream()
.filter(s -> s.startsWith(args[0]))
.collect(Collectors.toList());
return completeSorterName(args[0]);
}
else if(args.length <= 2) {
return Arrays.asList(DisplayMode.ITEMS, DisplayMode.OUTPUTS)
Expand Down
Loading

0 comments on commit 22fd9a7

Please sign in to comment.