Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update java version and some refactoring #7

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '17'
distribution: 'temurin'

- run: './gradlew shadowJar --stacktrace'
Expand Down
12 changes: 9 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'

sourceCompatibility = 1.8
targetCompatibility = 1.8
java.toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
// Optional: vendor.set(JvmVendorSpec.[VENDOR])
}

sourceCompatibility = "17"
targetCompatibility = "17"

group = parent.group;
version = parent.version;

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.release = 17
}

jar {
Expand Down Expand Up @@ -52,4 +58,4 @@ subprojects {
}
}
}
}
}
8 changes: 7 additions & 1 deletion bukkit/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'io.github.goooler.shadow' version "8.1.8"
niekschoemaker marked this conversation as resolved.
Show resolved Hide resolved
}

repositories {
Expand All @@ -20,6 +20,10 @@ dependencies {
implementation project(':api')
implementation project(':common')

implementation 'io.ebean:ebean:14.5.0'
implementation 'io.ebean:ebean-querybean:14.5.0'
implementation 'io.ebean:ebean-ddl-generator:14.5.0'

compileOnly 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT'
compileOnly 'commons-lang:commons-lang:2.6'
Expand Down Expand Up @@ -48,6 +52,8 @@ shadowJar {
exclude(dependency(':gson'))
}

mergeServiceFiles()
niekschoemaker marked this conversation as resolved.
Show resolved Hide resolved

// doLast {
// copy {
// from "build/libs/" + archiveFileName.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public AbstractScheduler getScheduler() {
return scheduler;
}

@Override
public boolean isPrimaryThread() {
return Bukkit.isPrimaryThread();
}

@Override
public void log(String msg) {
getLogger().info(msg);
Expand All @@ -91,6 +96,9 @@ public void log(String msg, Level level) {

@Override
public String colorify(String msg) {
if (msg == "") {
return msg;
}
// RGB support: <#rrggbb>
Matcher matcher = hexColorPattern.matcher(msg);
while (matcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.gufli.kingdomcraft.common.KingdomCraftImpl;
import com.gufli.kingdomcraft.common.command.CommandBase;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.List;
Expand All @@ -44,15 +45,16 @@ public List<String> autocomplete(PlatformPlayer player, String[] args) {

@Override
public void execute(PlatformSender sender, String[] args) {
PlatformPlayer player = (PlatformPlayer) sender;
BukkitPlayer player = (BukkitPlayer) sender;
Player gamePlayer = player.getPlayer();

Kingdom kingdom = player.getUser().getKingdom();
if ( kingdom == null ) {
kdc.getMessages().send(sender, "cmdErrorSenderNoKingdom");
return;
}

ItemStack item = ((BukkitPlayer) player).getPlayer().getItemInHand();
ItemStack item = gamePlayer.getInventory().getItemInMainHand();
if ( item == null || item.getType() == Material.AIR ) {
kdc.getMessages().send(sender, "cmdEditItemInvalid");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ public Player getPlayer() {

@Override
public boolean equals(Object obj) {
return obj instanceof BukkitPlayer && ((BukkitPlayer) obj).player == player;
if (!(obj instanceof BukkitPlayer bukkitPlayer)) {
return false;
}

return bukkitPlayer.player.getUniqueId().equals(player.getUniqueId()) && bukkitPlayer.player.getEntityId() == player.getEntityId();
}

@Override
public int hashCode() {
return player.getUniqueId().hashCode();
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public OfflinePlayer getPlayer() {

@Override
public boolean equals(Object obj) {
return obj instanceof OfflineBukkitPlayer && ((OfflineBukkitPlayer) obj).player == player;
if (!(obj instanceof OfflineBukkitPlayer bukkitPlayer)) {
return false;
}

return bukkitPlayer.player.getUniqueId().equals(player.getUniqueId());
}

@Override
public int hashCode() {
return player.getUniqueId().hashCode();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.gufli.kingdomcraft.api.events.UserLeaveKingdomEvent;
import com.gufli.kingdomcraft.bukkit.KingdomCraftBukkitPlugin;
import com.gufli.kingdomcraft.bukkit.entity.BukkitPlayer;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public class DisplayNameListener {
Expand Down Expand Up @@ -63,27 +65,32 @@ private void update(PlatformPlayer pp) {
return;
}

String prefix = plugin.getKdc().getPlaceholderManager().handle(pp, "{kingdom_prefix}");
if ( !prefix.equals("") && !plugin.decolorify(prefix).endsWith(" ")) {
prefix += " ";
}

String suffix = plugin.getKdc().getPlaceholderManager().handle(pp, "{kingdom_suffix}");
if ( !suffix.equals("") && !plugin.decolorify(suffix).startsWith(" ")) {
suffix = " " + suffix;
}

Player player = ((BukkitPlayer) pp).getPlayer();

if ( prefix.equals("") && suffix.equals("") ) {
player.setDisplayName(player.getName());
return;
}

prefix = plugin.colorify(prefix);
suffix = plugin.colorify(suffix);

player.setDisplayName(prefix + player.getName() + suffix);
plugin.getScheduler().executeAsync(() -> {
String prefix = plugin.getKdc().getPlaceholderManager().handle(pp, "{kingdom_prefix}");
if ( !prefix.equals("") && !plugin.decolorify(prefix).endsWith(" ")) {
prefix += " ";
}

String suffix = plugin.getKdc().getPlaceholderManager().handle(pp, "{kingdom_suffix}");
if ( !suffix.equals("") && !plugin.decolorify(suffix).startsWith(" ")) {
suffix = " " + suffix;
}

String prefixFinal = plugin.colorify(prefix);
String suffixFinal = plugin.colorify(suffix);

plugin.getScheduler().executeSync(() -> {
Player player = ((BukkitPlayer) pp).getPlayer();

if (prefixFinal.equals("") && suffixFinal.equals("")) {
player.setDisplayName(player.getName());
return;
}

player.setDisplayName(prefixFinal + player.getName() + suffixFinal);
});

});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ private <T extends Cancellable> void handleEvent(T e, Entity entity, Entity dama
damager.remove();
}

long lastNotification = 0;
if ( d.has("LAST_FRIENDLYFIRE_NOTIFICATION") ) {
lastNotification = d.get("LAST_FRIENDLYFIRE_NOTIFICATION", Long.class);
Long lastNotification = d.get("LAST_FRIENDLYFIRE_NOTIFICATION", Long.class);
if ( lastNotification == null ) {
lastNotification = 0L;
}

if ( System.currentTimeMillis() - lastNotification > 5000 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public void onReload(PluginReloadEvent e) {
//

void clear(PlatformPlayer player) {
if ( !player.has(PERMISSIONS_KEY) ) {
PermissionAttachment pa = player.get(PERMISSIONS_KEY, PermissionAttachment.class);
if ( pa == null ) {
return;
}

PermissionAttachment pa = player.get(PERMISSIONS_KEY, PermissionAttachment.class);
Player p = ((BukkitPlayer) player).getPlayer();
p.removeAttachment(pa);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public MenuChatListener(KingdomCraftBukkitPlugin plugin) {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent event) {
PlatformPlayer player = plugin.getKdc().getPlayer(event.getPlayer().getUniqueId());
Consumer<String> c = (Consumer<String>)player.get("MENU_CHAT_CALLBACK", Consumer.class);

if ( !player.has("MENU_CHAT_CALLBACK") ) {
if ( c == null ) {
return;
}

event.setCancelled(true);

Consumer c = player.get("MENU_CHAT_CALLBACK", Consumer.class);
player.remove("MENU_CHAT_CALLBACK");

if ( !event.getMessage().equalsIgnoreCase("cancel") ) {
Expand All @@ -59,11 +59,12 @@ public void onChat(AsyncPlayerChatEvent event) {

player.sendMessage(ChatColor.GREEN + "Cancelled!");

if ( !player.has("MENU_CHAT_CANCEL") ) {
Runnable r = player.get("MENU_CHAT_CANCEL", Runnable.class);

if ( r == null ) {
return;
}

Runnable r = player.get("MENU_CHAT_CANCEL", Runnable.class);
plugin.getScheduler().sync().execute(() -> r.run());

player.remove("MENU_CHAT_CANCEL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ public void onRankChange(UserRankChangeEvent e) {
}

private void loadExternals() {
allExternals.clear();
plugin.getKdc().getPermissionManager().getGroups().forEach(group -> {
allExternals.addAll(group.getExternals());
plugin.getScheduler().executeAsync(() -> {
allExternals.clear();
plugin.getKdc().getPermissionManager().getGroups().forEach(group -> {
allExternals.addAll(group.getExternals());
});
});
}

Expand All @@ -89,29 +91,30 @@ private void update(User user) {
}

private void update(PlatformPlayer player) {
Player bplayer = Bukkit.getPlayer(player.getUniqueId());

List<String> externals = new ArrayList<>();
Rank rank = player.getUser().getRank();
if ( rank != null ) {
plugin.getKdc().getPermissionManager().getGroups(rank).forEach(group
-> externals.addAll(group.getExternals()));
}
plugin.getScheduler().executeAsync(() -> {
Player bplayer = Bukkit.getPlayer(player.getUniqueId());

List<String> externals = new ArrayList<>();
Rank rank = player.getUser().getRank();
if ( rank != null ) {
plugin.getKdc().getPermissionManager().getGroups(rank).forEach(group
-> externals.addAll(group.getExternals()));
}

List<String> distinctExternals = new ArrayList<>(allExternals);
distinctExternals.removeIf(externals::contains);
List<String> distinctExternals = new ArrayList<>(allExternals);
distinctExternals.removeIf(externals::contains);

for ( String group : distinctExternals ) {
if ( permissionProvider.playerInGroup(bplayer, group) ) {
permissionProvider.playerRemoveGroup(bplayer, group);
for ( String group : distinctExternals ) {
if ( permissionProvider.playerInGroup(bplayer, group) ) {
permissionProvider.playerRemoveGroup(bplayer, group);
}
}
}

for ( String group : externals ) {
if ( !permissionProvider.playerInGroup(bplayer, group) ) {
permissionProvider.playerAddGroup(bplayer, group);
for ( String group : externals ) {
if ( !permissionProvider.playerInGroup(bplayer, group) ) {
permissionProvider.playerAddGroup(bplayer, group);
}
}
}
});
}

}
16 changes: 8 additions & 8 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id('io.ebean') version '12.1.8'
id('io.ebean') version '14.5.0'
}

apply plugin: 'io.ebean'
Expand All @@ -19,19 +19,19 @@ dependencies {
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'

implementation 'io.ebean:ebean:12.11.1'
implementation 'io.ebean:ebean-querybean:12.11.1'
implementation 'io.ebean:ebean-ddl-generator:12.11.1'
annotationProcessor 'io.ebean:querybean-generator:12.11.1'
implementation 'io.ebean:ebean:14.5.0'
implementation 'io.ebean:ebean-querybean:14.5.0'
implementation 'io.ebean:ebean-ddl-generator:14.5.0'
annotationProcessor 'io.ebean:querybean-generator:14.5.0'

implementation 'com.google.guava:guava:17.0'

implementation 'javax.validation:validation-api:2.0.1.Final'
implementation 'jakarta.validation:jakarta.validation-api:3.1.0'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.1'

implementation 'mysql:mysql-connector-java:8.0.25'
implementation 'com.h2database:h2:1.4.200'
implementation 'com.mysql:mysql-connector-j:9.0.0'
implementation 'com.h2database:h2:2.3.230'
implementation 'org.postgresql:postgresql:42.3.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public interface KingdomCraftPlugin {

File getDataFolder();

boolean isPrimaryThread();

}
Loading