Skip to content

Commit

Permalink
Update to 1.20.6 and java 21, refactoring (#109)
Browse files Browse the repository at this point in the history
* update to 1.20.6 and java 21

* use jdk21 in appveyor
  • Loading branch information
MajdT51 authored Jul 11, 2024
1 parent 2c7aa25 commit c2ab7e6
Show file tree
Hide file tree
Showing 15 changed files with 477 additions and 399 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clone_depth: 10
environment:
matrix:
- appveyor_build_worker_image: Visual Studio 2022
JAVA_HOME: C:\Program Files\Java\jdk17
JAVA_HOME: C:\Program Files\Java\jdk21
branches:
only:
- master
Expand Down
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: PopulationDensity
main: me.ryanhamshire.PopulationDensity.PopulationDensity
softdepend: [Multiverse-Core, My Worlds, Transporter, MystCraft]
version: '${project.version}-${git.commit.id.abbrev}'
api-version: '1.16'
api-version: '1.20.6'
commands:
visit:
description: Teleports the player to a specified region.
Expand All @@ -25,7 +25,7 @@ commands:
usage: /renameregion <name>
permission: populationdensity.renameregion
whichregion:
description: Tells the player which region he's in.
description: Tells the player which region he's in, and the coordinates of the region post.
usage: /WhichRegion
newestregion:
description: Teleports the player to the newest region.
Expand Down
24 changes: 12 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<groupId>me.ryanhamshire</groupId>
<artifactId>PopulationDensity</artifactId>
<version>5.13</version>
<version>6.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<repositories>
<repository>
Expand Down Expand Up @@ -52,7 +52,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<version>3.6.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
Expand Down Expand Up @@ -99,11 +99,17 @@
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Google stuff-->
Expand All @@ -112,12 +118,6 @@
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<!--json stuff-->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
Expand All @@ -127,7 +127,7 @@
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.3</version>
<version>1.0.8</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
10 changes: 9 additions & 1 deletion src/me/ryanhamshire/PopulationDensity/BlockEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class BlockEventHandler implements Listener
Material.LILAC,
Material.LARGE_FERN,
Material.PEONY,
Material.GRASS,
Material.SHORT_GRASS,
Material.FERN,
Material.DEAD_BUSH,
Material.OAK_LOG,
Expand All @@ -60,12 +60,16 @@ public class BlockEventHandler implements Listener
Material.JUNGLE_LOG,
Material.ACACIA_LOG,
Material.DARK_OAK_LOG,
Material.CHERRY_LOG,
Material.MANGROVE_LOG,
Material.OAK_LEAVES,
Material.SPRUCE_LEAVES,
Material.BIRCH_LEAVES,
Material.JUNGLE_LEAVES,
Material.ACACIA_LEAVES,
Material.DARK_OAK_LEAVES,
Material.CHERRY_LEAVES,
Material.MANGROVE_LEAVES,
Material.POPPY,
Material.DANDELION,
Material.BLUE_ORCHID,
Expand All @@ -76,8 +80,12 @@ public class BlockEventHandler implements Listener
Material.WHITE_TULIP,
Material.PINK_TULIP,
Material.OXEYE_DAISY,
Material.SPORE_BLOSSOM,
Material.BROWN_MUSHROOM,
Material.RED_MUSHROOM,
Material.PINK_PETALS,
Material.PITCHER_PLANT,
Material.TORCHFLOWER,
Material.SNOW_BLOCK
));

Expand Down
98 changes: 56 additions & 42 deletions src/me/ryanhamshire/PopulationDensity/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.io.Files;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang3.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -29,6 +29,8 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.block.sign.Side;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
Expand All @@ -47,6 +49,7 @@
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -78,8 +81,8 @@ public class DataStore implements TabCompleter
private RegionCoordinates nextRegionCoordinates;

//region data cache
private ConcurrentHashMap<String, RegionCoordinates> nameToCoordsMap = new ConcurrentHashMap<String, RegionCoordinates>();
private ConcurrentHashMap<RegionCoordinates, String> coordsToNameMap = new ConcurrentHashMap<RegionCoordinates, String>();
private ConcurrentHashMap<String, RegionCoordinates> nameToCoordsMap = new ConcurrentHashMap<>();
private ConcurrentHashMap<RegionCoordinates, String> coordsToNameMap = new ConcurrentHashMap<>();

//initialization!
public DataStore(List<String> regionNames)
Expand Down Expand Up @@ -199,7 +202,7 @@ public RegionCoordinates getRandomRegion(RegionCoordinates regionToAvoid)
//initialize random number generator with a seed based the current time
Random randomGenerator = new Random();

ArrayList<RegionCoordinates> possibleDestinations = new ArrayList<RegionCoordinates>();
ArrayList<RegionCoordinates> possibleDestinations = new ArrayList<>();
for (RegionCoordinates coords : this.coordsToNameMap.keySet())
{
if (!coords.equals(regionToAvoid))
Expand Down Expand Up @@ -514,14 +517,18 @@ public void AddRegionPost(RegionCoordinates region) throws ChunkLoadException
blockType == Material.JUNGLE_LEAVES ||
blockType == Material.ACACIA_LEAVES ||
blockType == Material.DARK_OAK_LEAVES ||
blockType == Material.GRASS ||
blockType == Material.CHERRY_LEAVES ||
blockType == Material.MANGROVE_LEAVES ||
blockType == Material.SHORT_GRASS ||
blockType == Material.TALL_GRASS ||
blockType == Material.OAK_LOG ||
blockType == Material.SPRUCE_LOG ||
blockType == Material.BIRCH_LOG ||
blockType == Material.JUNGLE_LOG ||
blockType == Material.ACACIA_LOG ||
blockType == Material.DARK_OAK_LOG ||
blockType == Material.CHERRY_LOG ||
blockType == Material.MANGROVE_LOG ||
blockType == Material.SNOW ||
blockType == Material.VINE
));
Expand Down Expand Up @@ -687,40 +694,41 @@ else if (blockType == PopulationDensity.instance.postMaterialMidTop)

private boolean isEmptyArray(String[] lines)
{
for (String line : lines)
{
if (!line.isEmpty())
return false;
}

return true;
return Arrays.stream(lines).allMatch(String::isEmpty);
}

private void setSign(int x, int y, int z, BlockFace blockFace, String[] lines, String... replacements)
{
if (isEmptyArray(lines))
return;

Block block = PopulationDensity.ManagedWorld.getBlockAt(x, y, z);
block.setType(Material.OAK_SIGN);

org.bukkit.block.data.type.Sign wall = (org.bukkit.block.data.type.Sign)block.getBlockData();
wall.setRotation(blockFace);
block.setBlockData(wall);

Sign s = (Sign)block.getState();
for (int i = 0; i < 4; i++)
if (block.getState() instanceof Sign)
{
String line = lines[i];
for (int r = 0; r < replacements.length; r++, r++)
org.bukkit.block.data.type.Sign wall = (org.bukkit.block.data.type.Sign)block.getBlockData();
wall.setRotation(blockFace);
block.setBlockData(wall);

Sign s = (Sign)block.getState();
for (int i = 0; i < 4; i++)
{
String key = replacements[r];
String value = replacements[r + 1];
line = line.replace(key, value);
String line = lines[i];
for (int r = 0; r < replacements.length; r++, r++)
{
String key = replacements[r];
String value = replacements[r + 1];
line = line.replace(key, value);
}
s.getSide(Side.FRONT).setLine(i, color(line));
s.setWaxed(true);
}
s.setLine(i, color(line));
s.setEditable(false);
s.update();
} else
{
PopulationDensity.AddLogEntry("Failed to set sign at " + x + ", " + y + ", " + z + " facing " + blockFace);
}
s.update();
}

private void setWallSign(int x, int y, int z, BlockFace blockFace, String[] lines, String... replacements)
Expand All @@ -730,24 +738,30 @@ private void setWallSign(int x, int y, int z, BlockFace blockFace, String[] line
Block block = PopulationDensity.ManagedWorld.getBlockAt(x, y, z);
block.setType(Material.OAK_WALL_SIGN);

org.bukkit.block.data.type.WallSign wall = (org.bukkit.block.data.type.WallSign)block.getBlockData();
wall.setFacing(blockFace);
block.setBlockData(wall);

Sign s = (Sign)block.getState();
for (int i = 0; i < 4; i++)
if (block.getState().getBlockData() instanceof WallSign)
{
String line = lines[i];
for (int r = 0; r < replacements.length; r++, r++)
WallSign wall = (WallSign) block.getBlockData();
wall.setFacing(blockFace);
block.setBlockData(wall);

Sign s = (Sign)block.getState();
for (int i = 0; i < 4; i++)
{
String key = replacements[r];
String value = replacements[r + 1];
line = line.replace(key, value);
String line = lines[i];
for (int r = 0; r < replacements.length; r++, r++)
{
String key = replacements[r];
String value = replacements[r + 1];
line = line.replace(key, value);
}
s.getSide(Side.FRONT).setLine(i, line);
s.setWaxed(true);
}
s.setLine(i, color(line));
s.setEditable(false);
s.update();
} else
{
PopulationDensity.AddLogEntry("Failed to set wall sign at " + x + ", " + y + ", " + z + " facing " + blockFace);
}
s.update();
}

private String color(String string)
Expand All @@ -765,7 +779,7 @@ private void loadMessages()
Messages[] messageIDs = Messages.values();
this.messages = new String[Messages.values().length];

HashMap<String, CustomizableMessage> defaults = new HashMap<String, CustomizableMessage>();
HashMap<String, CustomizableMessage> defaults = new HashMap<>();

//initialize defaults
this.addDefault(defaults, Messages.NoManagedWorld, "The PopulationDensity plugin has not been properly configured. Please update your config.yml to specify a world to manage.", null);
Expand Down Expand Up @@ -908,7 +922,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
}

String arg = builder.toString().trim();
ArrayList<String> matches = new ArrayList<String>();
ArrayList<String> matches = new ArrayList<>();
for (String name : this.coordsToNameMap.values())
{
if (StringUtil.startsWithIgnoreCase(name, arg))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;

import java.util.HashSet;
import java.util.UUID;
Expand Down Expand Up @@ -81,7 +80,7 @@ public void onEntityDamage(EntityDamageEvent event)
}
}

HashSet<UUID> fallImmunityList = new HashSet<UUID>();
HashSet<UUID> fallImmunityList = new HashSet<>();

void makeEntityFallDamageImmune(LivingEntity entity)
{
Expand Down
Loading

0 comments on commit c2ab7e6

Please sign in to comment.