-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a maybe-working legacy outpost converter.
- Loading branch information
Showing
5 changed files
with
142 additions
and
3 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
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
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
61 changes: 61 additions & 0 deletions
61
Towny/src/main/java/com/palmergames/bukkit/towny/tasks/LegacyOutpostConversionTask.java
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,61 @@ | ||
package com.palmergames.bukkit.towny.tasks; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import com.palmergames.bukkit.towny.Towny; | ||
import com.palmergames.bukkit.towny.TownyAPI; | ||
import com.palmergames.bukkit.towny.TownyMessaging; | ||
import com.palmergames.bukkit.towny.exceptions.TownyException; | ||
import com.palmergames.bukkit.towny.object.Outpost; | ||
import com.palmergames.bukkit.towny.object.Position; | ||
import com.palmergames.bukkit.towny.object.Town; | ||
import com.palmergames.bukkit.towny.object.TownBlock; | ||
import com.palmergames.bukkit.towny.object.WorldCoord; | ||
import com.palmergames.bukkit.towny.utils.BorderUtil; | ||
import com.palmergames.bukkit.towny.utils.BorderUtil.FloodfillResult; | ||
|
||
public class LegacyOutpostConversionTask extends TownyTimerTask { | ||
|
||
final Position pos; | ||
final Town town; | ||
|
||
public LegacyOutpostConversionTask(Towny plugin, Position pos, Town town) { | ||
super(plugin); | ||
this.pos = pos; | ||
this.town = town; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (plugin.isError()) | ||
return; | ||
|
||
TownBlock townBlock = TownyAPI.getInstance().getTownBlock(pos.asLocation()); | ||
if (!town.hasTownBlock(townBlock)) | ||
return; | ||
|
||
WorldCoord coord = townBlock.getWorldCoord(); | ||
FloodfillResult result = null; | ||
try { | ||
result = BorderUtil.getFloodFillableCoordsForOutpostConversion(town, coord); | ||
if (result.type() != BorderUtil.FloodfillResult.Type.SUCCESS) | ||
throw result.feedback() != null ? new TownyException(result.feedback()) : new TownyException(); | ||
else if (result.feedback() != null) | ||
TownyMessaging.sendMsg(result.feedback()); | ||
} catch (TownyException e) { | ||
TownyMessaging.sendMsg(e.getLocalizedMessage()); | ||
} | ||
|
||
List<WorldCoord> selection = new ArrayList<>(result.coords()); | ||
Outpost outpost = new Outpost(UUID.randomUUID(), townBlock.getName() != "" ? townBlock.getName() : String.valueOf(town.getMaxOutpostSpawn() + 1)); | ||
outpost.addTownblock(townBlock); | ||
for (WorldCoord wc : selection) { | ||
TownBlock tb = wc.getTownBlockOrNull(); | ||
if (tb != null) | ||
outpost.addTownblock(tb); | ||
} | ||
outpost.save(); | ||
} | ||
} |
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