Skip to content

Commit

Permalink
Added arena outline particles
Browse files Browse the repository at this point in the history
  • Loading branch information
Despical committed Aug 18, 2023
1 parent 45485b9 commit 6be69a1
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 20 deletions.
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.despical</groupId>
<artifactId>king-of-the-ladder</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<name>King of the Ladder</name>
<url>https://www.spigotmc.org/resources/80686/</url>

<properties>
<java.version>17</java.version>
Expand Down Expand Up @@ -107,6 +108,7 @@
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<outputDirectory>C:\Users\berke\OneDrive\Masaüstü\Server\plugins</outputDirectory>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/me/despical/kotl/api/StatsStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import me.despical.commons.configuration.ConfigUtils;
import me.despical.commons.sorter.SortUtils;
import me.despical.kotl.ConfigPreferences;
import me.despical.kotl.Main;
import me.despical.kotl.user.data.MysqlManager;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -59,7 +58,7 @@ public static Map<UUID, Integer> getStats(StatisticType stat) {
}

return column;
} catch(SQLException e) {
} catch (SQLException e) {
plugin.getLogger().warning("SQLException occurred during getting statistics from database!");
return new LinkedHashMap<>();
}
Expand Down
56 changes: 54 additions & 2 deletions src/main/java/me/despical/kotl/arena/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
import org.apache.commons.lang.math.IntRange;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -51,7 +55,8 @@ public class Arena {
private static final Main plugin = JavaPlugin.getPlugin(Main.class);

private final String id;
private boolean ready = true;
private boolean ready = true, showOutlines;
private BukkitTask particleScheduler;

private final Set<Player> players;
private final Map<GameLocation, Location> gameLocations;
Expand Down Expand Up @@ -83,7 +88,54 @@ public boolean isReady() {
public void setReady(boolean ready) {
this.ready = ready;
}


public void setShowOutlines(boolean showOutlines) {
this.showOutlines = showOutlines;

if (showOutlines) {
if (this.particleScheduler != null || getMinCorner() == null || getMaxCorner() == null) return;

this.particleScheduler = new BukkitRunnable() {
final Location min = getMinCorner();
final Location max = getMaxCorner();
final World world = min.getWorld();
final Particle particle = Particle.valueOf(plugin.getConfig().getString("Arena-Outlines.Particle", "flame").toUpperCase());
final double step = plugin.getConfig().getDouble("Arena-Outlines.Step", .4);

final double[]
xArr = {Math.min(min.getX(), max.getX()), Math.max(min.getX(), max.getX())},
yArr = {Math.min(min.getY(), max.getY()), Math.max(min.getY(), max.getY())},
zArr = {Math.min(min.getZ(), max.getZ()), Math.max(min.getZ(), max.getZ())};

@Override
public void run() {
for (double x = xArr[0]; x < xArr[1]; x += step) for (double y : yArr) for (double z : zArr) {
world.spawnParticle(particle, new Location(world, x, y, z), 1, 0, 0, 0, 0);
}

for (double y = yArr[0]; y < yArr[1]; y += step) for (double x : xArr) for (double z : zArr) {
world.spawnParticle(particle, new Location(world, x, y, z), 1, 0, 0, 0, 0);
}

for (double z = zArr[0]; z < zArr[1]; z += step) for (double y : yArr) for (double x : xArr) {
world.spawnParticle(particle, new Location(world, x, y, z), 1, 0, 0, 0, 0);
}
}
}.runTaskTimer(plugin, 20, 1);
} else if (this.particleScheduler != null) {
this.particleScheduler.cancel();
this.particleScheduler = null;
}
}

public void handleOutlines() {
this.setShowOutlines(showOutlines);
}

public boolean isShowOutlines() {
return showOutlines;
}

/**
* Get arena identifier used to get arenas by string.
*
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/me/despical/kotl/arena/ArenaRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import me.despical.commons.configuration.ConfigUtils;
import me.despical.commons.serializer.LocationSerializer;
import me.despical.kotl.Main;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

import java.util.HashSet;
Expand Down Expand Up @@ -82,19 +80,19 @@ public boolean isInArena(final Player player) {
public void registerArenas() {
this.arenas.clear();

final FileConfiguration config = ConfigUtils.getConfig(plugin, "arenas");
final ConfigurationSection section = config.getConfigurationSection("instances");
final var config = ConfigUtils.getConfig(plugin, "arenas");
final var section = config.getConfigurationSection("instances");

if (section == null) {
plugin.getLogger().warning("Couldn't find 'instances' section in arena.yml, delete the file to regenerate it!");
return;
}

for (String id : section.getKeys(false)) {
for (final var id : section.getKeys(false)) {
if (id.equals("default")) continue;

final String path = "instances." + id + ".";
final Arena arena = new Arena(id);
final var path = "instances." + id + ".";
final var arena = new Arena(id);

this.registerArena(arena);

Expand All @@ -104,6 +102,7 @@ public void registerArenas() {
arena.setMinCorner(LocationSerializer.fromString(config.getString(path + "areaMin")));
arena.setMaxCorner(LocationSerializer.fromString(config.getString(path + "areaMax")));
arena.setArenaPlate(XMaterial.valueOf(config.getString(path + "arenaPlate")));
arena.setShowOutlines(config.getBoolean(path + "showOutlines"));

if (arena.isReady() && LocationSerializer.fromString(config.getString(path + "plateLocation")).getBlock().getType() != arena.getArenaPlate().parseMaterial()) {
plugin.getLogger().warning("Founded plate block material is not the same type as you set on setup!");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/despical/kotl/command/AdminCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private void setupDefaultConfiguration(String id) {
arenaConfig.set(path + "areaMin", def);
arenaConfig.set(path + "areaMax", def);
arenaConfig.set(path + "isdone", false);
arenaConfig.set(path + "showOutlines", true);
arenaConfig.set(path + "plateLocation", def);
arenaConfig.set(path + "arenaPlate", "OAK_PRESSURE_PLATE");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import me.despical.kotl.handler.ChatManager;
import me.despical.kotl.handler.setup.components.ArenaRegisterComponents;
import me.despical.kotl.handler.setup.components.PressurePlateComponents;
import me.despical.kotl.handler.setup.components.SpawnComponents;
import me.despical.kotl.handler.setup.components.MainMenuComponents;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -75,7 +75,7 @@ private void prepareGui() {
}

private void prepareComponents(StaticPane pane) {
final var spawnComponents = new SpawnComponents();
final var spawnComponents = new MainMenuComponents();
spawnComponents.injectComponents(this, pane);

final var arenaRegistryComponents = new ArenaRegisterComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void injectComponents(SetupInventory setupInventory, StaticPane pane) {

if (!arena.isReady()) {
registeredItem = new ItemBuilder(XMaterial.FIREWORK_ROCKET)
.name("&e&lRegister Arena - Finish Setup")
.name("&e&l Register Arena - Finish Setup")
.lore("&7Click this when you're done with configuration.")
.lore("&7It will validate and register arena.");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@
* <p>
* Created at 22.06.2020
*/
public class SpawnComponents implements SetupInventory.SetupComponent {
public class MainMenuComponents implements SetupInventory.SetupComponent {

private static boolean supportsParticle;;

static {
try {
Class.forName("org.bukkit.Particle");

supportsParticle = true;
} catch (ClassNotFoundException exception) {
supportsParticle = false;
}
}

@Override
public void injectComponents(SetupInventory setupInventory, StaticPane pane) {
Expand All @@ -41,7 +53,7 @@ public void injectComponents(SetupInventory setupInventory, StaticPane pane) {
final var path = "instances.%s.".formatted(arena.getId());

pane.addItem(new GuiItem(new ItemBuilder(XMaterial.REDSTONE_BLOCK)
.name("&e&lSet Ending Location")
.name("&e&l Set Ending Location ")
.lore("&7Click to set ending location on")
.lore("&7the place where you are standing.")
.lore("&8(location where players will be")
Expand All @@ -61,7 +73,7 @@ public void injectComponents(SetupInventory setupInventory, StaticPane pane) {
}), 1, 1);

pane.addItem(GuiItem.of(new ItemBuilder(arena.getArenaPlate())
.name("&e&lSet Plate Location")
.name("&e&l Set Plate Location ")
.lore("&7Click to set plate location on")
.lore("&7the place where you are standing.")
.lore("&8(location where players will try to")
Expand All @@ -82,7 +94,7 @@ public void injectComponents(SetupInventory setupInventory, StaticPane pane) {
}), 5, 1);

pane.addItem(GuiItem.of(new ItemBuilder(XMaterial.BLAZE_ROD.parseItem())
.name("&e&lSet Arena Region")
.name("&e&l Set Arena Region ")
.lore("&7Click to set arena's region")
.lore("&7with the cuboid selector.")
.lore("&8(area where game will be playing)")
Expand Down Expand Up @@ -110,11 +122,13 @@ public void injectComponents(SetupInventory setupInventory, StaticPane pane) {
player.sendMessage(chatManager.coloredRawMessage("&e✔ Completed | &aGame area of arena &e" + arena.getId() + " &aset as you selection!"));
selector.removeSelection(player);

arena.handleOutlines();

saveConfig();
}), 3, 1);

pane.addItem(GuiItem.of(new ItemBuilder(XMaterial.ENCHANTED_BOOK)
.name(chatManager.coloredRawMessage("&e&lChange Arena Plate"))
.name("&e&l Change Arena Plate ")
.lore("&7Click here to change arena plate.")
.lore("&8(opens arena plate changer menu)")
.build(), e -> {
Expand All @@ -126,5 +140,19 @@ public void injectComponents(SetupInventory setupInventory, StaticPane pane) {
gui.setTitle(" Arena Plate Editor");
gui.update();
}), 7, 1);

final var outlineItem = supportsParticle ? new ItemBuilder(arena.isShowOutlines() ? XMaterial.ENDER_EYE : XMaterial.ENDER_PEARL)
.name(" " + (arena.isShowOutlines() ? "&c&lDisable" : "&e&lEnable") + " Outline Particles ")
.lore("&7You can create particles around the game arena.") :
new ItemBuilder(XMaterial.BARREL).name("&c&lYour server does not support Particles!");

pane.addItem(GuiItem.of(outlineItem.build(), e -> {
arena.setShowOutlines(!arena.isShowOutlines());

config.set(path + "showOutlines", arena.isShowOutlines());
saveConfig();

new SetupInventory(arena, player).openInventory();
}), 8, 3);
}
}
1 change: 1 addition & 0 deletions src/main/resources/arenas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ instances:
areaMin: world, -994.000, 4.000, 853.000, 0.000, 0.000
areaMax: world, -994.000, 4.000, 853.000, 0.000, 0.000
isdone: false
showOutlines: true
plateLocation: world, -994.000, 4.000, 853.000, 0.000, 0.000
arenaPlate: OAK_PRESSURE_PLATE
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ Disable-Fall-Damage: true
# Should we let players become king in a row?
Become-King-In-A-Row: false

# Your server must support particles to use that feature.
Arena-Outlines:
Step: .4
Particle: FLAME

# The delay between hitting players. ONLY EFFECTED in Minecraft 1.9+
Hit-Cooldown-Delay: 16

Expand Down

0 comments on commit 6be69a1

Please sign in to comment.