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

Init Folia support #1459

Open
wants to merge 2 commits into
base: 1.6.x
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
8 changes: 7 additions & 1 deletion modules/Legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down Expand Up @@ -57,6 +57,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.19.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
Expand Down
10 changes: 9 additions & 1 deletion modules/Main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down Expand Up @@ -131,6 +131,7 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<!--
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
Expand Down Expand Up @@ -159,6 +160,13 @@
</exclusion>
</exclusions>
</dependency>
-->
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.19.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down
237 changes: 116 additions & 121 deletions src/main/java/com/massivecraft/factions/FactionsPlugin.java

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions src/main/java/com/massivecraft/factions/cmd/CmdShow.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -115,7 +114,12 @@ public void perform(CommandContext context) {
}
}
if (context.fPlayer != null && this.groupPresent()) {
new GroupGetter(messageList, context.fPlayer, faction).runTaskAsynchronously(FactionsPlugin.getInstance());
Runnable runnable = new GroupGetter(messageList, context.fPlayer, faction);//.runTaskAsynchronously(FactionsPlugin.getInstance());
if (FactionsPlugin.isFolia()) {
FactionsPlugin.getInstance().getServer().getGlobalRegionScheduler().execute(FactionsPlugin.getInstance(), runnable);
} else {
Bukkit.getScheduler().runTaskAsynchronously(FactionsPlugin.getInstance(), runnable);
}
} else {
this.sendMessages(messageList, context.sender, faction, context.fPlayer);
}
Expand Down Expand Up @@ -196,7 +200,7 @@ private boolean groupPresent() {
return false;
}

private class GroupGetter extends BukkitRunnable {
private class GroupGetter implements Runnable {
private final List<String> messageList;
private final FPlayer sender;
private final Faction faction;
Expand All @@ -215,11 +219,16 @@ public void run() {
for (OfflinePlayer player : this.players) {
map.put(player.getUniqueId(), FactionsPlugin.getInstance().getPrimaryGroup(player));
}
new Sender(this.messageList, this.sender, this.faction, map).runTask(FactionsPlugin.getInstance());
Runnable runnable = new Sender(this.messageList, this.sender, this.faction, map);//.runTask(FactionsPlugin.getInstance());
if (FactionsPlugin.isFolia()) {
FactionsPlugin.getInstance().getServer().getGlobalRegionScheduler().execute(FactionsPlugin.getInstance(), runnable);
} else {
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), runnable);
}
}
}

private class Sender extends BukkitRunnable {
private class Sender implements Runnable {
private final List<String> messageList;
private final FPlayer sender;
private final Faction faction;
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/massivecraft/factions/cmd/CmdStuck.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

public class CmdStuck extends FCommand {

Expand Down Expand Up @@ -55,7 +54,8 @@ public void perform(final CommandContext context) {
return;
}

final int id = new BukkitRunnable() {
final int id = 1;
Runnable runnable = new Runnable() {

@Override
public void run() {
Expand Down Expand Up @@ -110,7 +110,13 @@ public void finish() {
}
};
}
}.runTaskLater(FactionsPlugin.getInstance(), delay * 20).getTaskId();
};//.runTaskLater(FactionsPlugin.getInstance(), delay * 20).getTaskId();

if (FactionsPlugin.isFolia()) {
FactionsPlugin.getInstance().getServer().getGlobalRegionScheduler().runDelayed(FactionsPlugin.getInstance(), scheduledTask -> runnable.run(), delay * 20);
} else {
Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), runnable, delay * 20);
}

FactionsPlugin.getInstance().getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000));
long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
Expand Down
46 changes: 24 additions & 22 deletions src/main/java/com/massivecraft/factions/cmd/CmdTicketInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitRunnable;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -149,7 +148,7 @@ public void perform(CommandContext context) {
}
}

new BukkitRunnable() {
Runnable runnable = new Runnable() {
private String getFile(Path file) {
try {
return new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
Expand All @@ -160,6 +159,7 @@ private String getFile(Path file) {

@Override
public void run() {
Runnable runnable1 = null;
try {
Path dataPath = FactionsPlugin.getInstance().getDataFolder().toPath();
String spigotConf = getFile(Paths.get("spigot.yml"));
Expand Down Expand Up @@ -210,32 +210,34 @@ public void run() {
}
TicketResponse response = gson.fromJson(content.toString(), TicketResponse.class);

new BukkitRunnable() {
@Override
public void run() {
if (response.success) {
String url = response.message;
audience.sendMessage(Component.text().color(NamedTextColor.YELLOW).content("Share this URL: " + url).clickEvent(ClickEvent.openUrl(url)));
if (context.sender instanceof Player) {
FactionsPlugin.getInstance().getLogger().info("Share this URL: " + url);
}
} else {
audience.sendMessage(Component.text().color(NamedTextColor.RED).content("ERROR! Could not generate ticket info. See console for why."));
FactionsPlugin.getInstance().getLogger().warning("Received: " + response.message);
runnable1 = () -> {
if (response.success) {
String url1 = response.message;
audience.sendMessage(Component.text().color(NamedTextColor.YELLOW).content("Share this URL: " + url1).clickEvent(ClickEvent.openUrl(url1)));
if (context.sender instanceof Player) {
FactionsPlugin.getInstance().getLogger().info("Share this URL: " + url1);
}
} else {
audience.sendMessage(Component.text().color(NamedTextColor.RED).content("ERROR! Could not generate ticket info. See console for why."));
FactionsPlugin.getInstance().getLogger().warning("Received: " + response.message);
}
}.runTask(FactionsPlugin.getInstance());
};//.runTask(FactionsPlugin.getInstance());
} catch (Exception e) {
FactionsPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to execute ticketinfo command", e);
new BukkitRunnable() {
@Override
public void run() {
audience.sendMessage(Component.text().color(NamedTextColor.RED).content("ERROR! Could not generate ticket info. See console for why."));
}
}.runTask(FactionsPlugin.getInstance());
runnable1 = () -> audience.sendMessage(Component.text().color(NamedTextColor.RED).content("ERROR! Could not generate ticket info. See console for why."));//.runTask(FactionsPlugin.getInstance());
}
if (FactionsPlugin.isFolia()) {
FactionsPlugin.getInstance().getServer().getGlobalRegionScheduler().execute(FactionsPlugin.getInstance(), runnable1);
} else {
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), runnable1);
}
}
}.runTaskAsynchronously(FactionsPlugin.getInstance());
};//.runTaskAsynchronously(FactionsPlugin.getInstance());
if (FactionsPlugin.isFolia()) {
FactionsPlugin.getInstance().getServer().getGlobalRegionScheduler().execute(FactionsPlugin.getInstance(), runnable);
} else {
Bukkit.getScheduler().runTaskAsynchronously(FactionsPlugin.getInstance(), runnable);
}
audience.sendMessage(Component.text().color(NamedTextColor.YELLOW).content("Now running..."));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import com.massivecraft.factions.util.TL;
import com.massivecraft.factions.util.TextUtil;
import com.massivecraft.factions.util.VisualizeUtil;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -51,7 +48,6 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.NumberConversions;

import java.util.HashMap;
Expand Down Expand Up @@ -151,15 +147,16 @@ private void initPlayer(Player player) {

private void initFactionWorld(FPlayer me) {
// Check for Faction announcements. Let's delay this so they actually see it.
new BukkitRunnable() {
@Override
public void run() {
if (me.isOnline()) {
me.getFaction().sendUnreadAnnouncements(me);
}
Runnable runnable = () -> {
if (me.isOnline()) {
me.getFaction().sendUnreadAnnouncements(me);
}
}.runTaskLater(FactionsPlugin.getInstance(), 33L); // Don't ask me why.

};//.runTaskLater(FactionsPlugin.getInstance(), 33L); // Don't ask me why.
if (FactionsPlugin.isFolia()) {
FactionsPlugin.getInstance().getServer().getRegionScheduler().runDelayed(FactionsPlugin.getInstance(), me.getPlayer().getLocation() , scheduledTask -> runnable.run(), 33L);
} else {
Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), runnable, 33L);
}
if (FactionsPlugin.getInstance().conf().scoreboard().constant().isEnabled()) {
FScoreboard.init(me);
FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar());
Expand Down Expand Up @@ -234,16 +231,18 @@ public void onGameMode(PlayerGameModeChangeEvent event) {
}
if (event.getNewGameMode() == GameMode.SURVIVAL) {
FPlayer me = FPlayers.getInstance().getByPlayer(event.getPlayer());
new BukkitRunnable() {
@Override
public void run() {
if (me.isFlying()) {
me.getPlayer().setAllowFlight(true);
me.getPlayer().setFlying(true);
}
me.flightCheck();
}
}.runTask(this.plugin);
Runnable runnable = () -> {
if (me.isFlying()) {
me.getPlayer().setAllowFlight(true);
me.getPlayer().setFlying(true);
}
me.flightCheck();
};//.runTask(this.plugin);
if (FactionsPlugin.isFolia()) {
FactionsPlugin.getInstance().getServer().getRegionScheduler().run(FactionsPlugin.getInstance(), me.getPlayer().getLocation() , scheduledTask -> runnable.run());
} else {
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), runnable);
}
}
}

Expand Down Expand Up @@ -590,12 +589,12 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
(facConf.landRaidControl().power().isRespawnHomeFromNoPowerLossWorlds() || !facConf.landRaidControl().power().getWorldsNoPowerLoss().contains(event.getPlayer().getWorld().getName()))) {
event.setRespawnLocation(home);
}
new BukkitRunnable() {
@Override
public void run() {
me.flightCheck();
}
}.runTask(FactionsPlugin.getInstance());
Runnable runnable = me::flightCheck;//.runTask(FactionsPlugin.getInstance());
if (FactionsPlugin.isFolia()) {
FactionsPlugin.getInstance().getServer().getRegionScheduler().run(FactionsPlugin.getInstance(), me.getPlayer().getLocation() , scheduledTask -> runnable.run());
} else {
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), runnable);
}
}

@EventHandler(priority = EventPriority.HIGH)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package com.massivecraft.factions.scoreboards;

import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.*;
import com.massivecraft.factions.config.file.MainConfig;
import com.massivecraft.factions.tag.Tag;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

public class FTeamWrapper {
private static final Map<Faction, FTeamWrapper> wrappers = new HashMap<>();
Expand Down Expand Up @@ -46,13 +37,15 @@ public static void applyUpdatesLater(final Faction faction) {


if (updating.add(faction)) {
new BukkitRunnable() {
@Override
public void run() {
updating.remove(faction);
applyUpdates(faction);
}
}.runTask(FactionsPlugin.getInstance());
Runnable runnable = () -> {
updating.remove(faction);
applyUpdates(faction);
};//.runTask(FactionsPlugin.getInstance());
if (FactionsPlugin.isFolia()) {
FactionsPlugin.getInstance().getServer().getGlobalRegionScheduler().execute(FactionsPlugin.getInstance(), runnable);
} else {
Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), runnable);
}
}
}

Expand Down
Loading