-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b679130
Showing
10 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: CI | ||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-java@v3 | ||
with: | ||
java-version: '18' | ||
distribution: 'adopt' | ||
- name: Publish package | ||
run: mvn --batch-mode deploy | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
target/ | ||
dependency-reduced-pom.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 iamtakagi | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# sudachi | ||
|
||
## Getting Started | ||
|
||
### Installation | ||
|
||
`pom.xml` | ||
```xml | ||
<repository> | ||
<id>github</id> | ||
<name>GitHub Packages</name> | ||
<url>https://maven.pkg.github.com/2mug1/sudachi</url> | ||
</repository> | ||
|
||
<dependency> | ||
<groupId>net.iamtakagi</groupId> | ||
<artifactId>sudachi</artifactId> | ||
<version>1.0.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
``` | ||
|
||
`build.gradle` | ||
```gradle | ||
repositories { | ||
maven (url = "https://maven.pkg.github.com/2mug1/sudachi") | ||
} | ||
dependencies { | ||
implementation("net.iamtakagi:sudachi:1.0.0") | ||
} | ||
``` | ||
|
||
## LICENSE | ||
[MIT License](./LICENSE) (© 2022 iamtakagi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<distributionManagement> | ||
<repository> | ||
<id>github</id> | ||
<name>GitHub Packages</name> | ||
<url>https://maven.pkg.github.com/2mug1/sudachi</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<groupId>net.iamtakagi</groupId> | ||
<artifactId>sudachi</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>18</maven.compiler.source> | ||
<maven.compiler.target>18</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>papermc</id> | ||
<url>https://papermc.io/repo/repository/maven-public/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.24</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.11.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-text</artifactId> | ||
<version>1.9</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.9.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.papermc.paper</groupId> | ||
<artifactId>paper-api</artifactId> | ||
<version>1.19.2-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.4.3</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>testCompile</id> | ||
<phase>test-compile</phase> | ||
<goals> | ||
<goal>testCompile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<source>18</source> | ||
<target>18</target> | ||
<compilerArgument>-parameters</compilerArgument> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package net.iamtakagi.sudachi; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import lombok.Getter; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.bukkit.scoreboard.DisplaySlot; | ||
import org.bukkit.scoreboard.Objective; | ||
import org.bukkit.scoreboard.Scoreboard; | ||
|
||
@Getter | ||
public class Board { | ||
|
||
private final BoardAdapter adapter; | ||
private final Player player; | ||
private List<BoardEntry> entries = new ArrayList<>(); | ||
private Set<BoardTimer> timers = new HashSet<>(); | ||
private Set<String> keys = new HashSet<>(); | ||
private Scoreboard scoreboard; | ||
private Objective objective; | ||
|
||
public Board(Plugin plugin, Player player, BoardAdapter adapter) { | ||
this.adapter = adapter; | ||
this.player = player; | ||
|
||
this.init(plugin); | ||
} | ||
|
||
private void init(Plugin plugin) { | ||
if (!this.player.getScoreboard().equals(plugin.getServer().getScoreboardManager().getMainScoreboard())) { | ||
this.scoreboard = this.player.getScoreboard(); | ||
} else { | ||
this.scoreboard = plugin.getServer().getScoreboardManager().getNewScoreboard(); | ||
} | ||
|
||
this.objective = this.scoreboard.registerNewObjective("Default", "dummy"); | ||
|
||
this.objective.setDisplaySlot(DisplaySlot.SIDEBAR); | ||
this.objective.setDisplayName(this.adapter.getTitle(player)); | ||
} | ||
|
||
public String getNewKey(BoardEntry entry) { | ||
for (ChatColor color : ChatColor.values()) { | ||
String colorText = color + "" + ChatColor.WHITE; | ||
|
||
if (entry.getText().length() > 16) { | ||
String sub = entry.getText().substring(0, 16); | ||
colorText = colorText + ChatColor.getLastColors(sub); | ||
} | ||
|
||
if (!keys.contains(colorText)) { | ||
keys.add(colorText); | ||
return colorText; | ||
} | ||
} | ||
|
||
throw new IndexOutOfBoundsException("No more keys available!"); | ||
} | ||
|
||
public List<String> getBoardEntriesFormatted() { | ||
List<String> toReturn = new ArrayList<>(); | ||
|
||
for (BoardEntry entry : new ArrayList<>(entries)) { | ||
toReturn.add(entry.getText()); | ||
} | ||
|
||
return toReturn; | ||
} | ||
|
||
public BoardEntry getByPosition(int position) { | ||
for (int i = 0; i < this.entries.size(); i++) { | ||
if (i == position) { | ||
return this.entries.get(i); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public BoardTimer getCooldown(String id) { | ||
for (BoardTimer cooldown : getTimers()) { | ||
if (cooldown.getId().equals(id)) { | ||
return cooldown; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public Set<BoardTimer> getTimers() { | ||
this.timers.removeIf(cooldown -> System.currentTimeMillis() >= cooldown.getEnd()); | ||
return this.timers; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.iamtakagi.sudachi; | ||
|
||
import java.util.List; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.scoreboard.Scoreboard; | ||
|
||
public interface BoardAdapter { | ||
|
||
String getTitle(Player player); | ||
|
||
List<String> getScoreboard(Player player, Board board); | ||
|
||
long getInterval(); | ||
|
||
void onScoreboardCreate(Player player, Scoreboard board); | ||
|
||
void preLoop(); | ||
|
||
} |
Oops, something went wrong.