Skip to content

Commit

Permalink
Finish off initial version.
Browse files Browse the repository at this point in the history
Added in pictures, added bStats, and fixed a bug with Nether Portals I found while getting pictures.
Replay mod seems broken, so no animated pictures for now.
  • Loading branch information
minus1over12 committed Jun 11, 2024
1 parent 7617cb0 commit 3215d9b
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 25 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ on the [Paper](https://papermc.io/software/paper) server.
CTF Buddy doesn't have a prescribed flag item you have to use. CTF Buddy keeps track of items by
adding a piece of metadata to the item, then listens for events involving that item. This means
anything that you can hold in your hand can be a flag.

![A custom flag item on the ground.](images/Flag-on-Ice.png)
Want an entity instead? CTF Buddy can do that too! The plugin uses the same metadata system to
allow keeping track of marked entities, so you can use your favorite Villager or Creeper as a flag.
![A Villager marked as a flag](images/Jeff.png)

### Flag Visibility

Flags, and any entity carrying a flag, are given a glowing effect to make them easier to spot.
Additionally, entities holding a flag item will have their helmet slot replaced with the flag to
make them easy to spot (if a player had a helmet before, it will be safely placed in their
inventory).
![A player carrying a flag](images/Player-with-Flag-on-Ice.png)

By default, the plugin will shoot off firework particles every minute to help players find the
flags. This can be disabled if needed.
Expand All @@ -30,6 +32,7 @@ CTF Buddy takes measures when an item is marked as a flag to make sure it is not
to be destroyed. Flag entities can only be harmed by creative mode players and will not despawn.
The plugin also prevents bringing flags to the end by default, where they could easily be lost to
the void.
![A flag sitting in a lava ocean, unharmed](images/Flag-in-Lava.png)

### Logout Protection

Expand All @@ -41,9 +44,9 @@ vehicle if the player tries to log out with them.

### Logging

Need to figure out what happened to a flag? CTF Buddy logs flag events to the server console.
You can use this to track down who won at the end of an event, or use to give players hints if
needed.
Need to figure out what happened to a flag? CTF Buddy logs to the server console whenever a player
picks up or drops a flag item. You can use this to track down who won at the end of an event,
or use to give players hints if needed.

## Usage

Expand Down Expand Up @@ -80,6 +83,7 @@ please let me know how it goes!). Upstreams of Paper (Bukkit & Spigot) will *not
plugin utilizes the expanded API provided by Paper.

Geyser is a bit problematic, due to a lack of important features in Bedrock Edition.
[Bedrock does not support glowing](https://wiki.geysermc.org/geyser/current-limitations/#:~:text=links%20in%20chat-,Glowing%20effect,-Crafting%20in%20the)
, which may make locating the flag harder for those players. Additionally,
[Bedrock also does not support blocks on entity heads](https://wiki.geysermc.org/geyser/current-limitations/#:~:text=Blocks%20(excluding%20jack%2Do%2Dlantern)%20on%20entity%20heads%20(E.G.%20armor%20stands%2C%20players)), meaning the flag may not be visible on entities carrying them.
[Bedrock does not support glowing](https://wiki.geysermc.org/geyser/current-limitations/#:~:text=links%20in%20chat-,Glowing%20effect,-Crafting%20in%20the),
which may make locating the flag harder for those players. Additionally,
[Bedrock also does not support blocks on entity heads](https://wiki.geysermc.org/geyser/current-limitations/#:~:text=Blocks%20(excluding%20jack%2Do%2Dlantern)%20on%20entity%20heads%20(E.G.%20armor%20stands%2C%20players)),
meaning the flag may not be visible on entities carrying them.
15 changes: 11 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import xyz.jpenilla.runtask.task.AbstractRun
plugins {
id 'java'
id("xyz.jpenilla.run-paper") version "2.3.0"
id("io.github.goooler.shadow") version "8.1.7"
}

group = 'io.github.minus1over12'
Expand All @@ -26,8 +27,8 @@ repositories {

dependencies {
compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT"
compileOnly 'com.mojang:brigadier:1.0.18'
implementation('org.jetbrains:annotations:24.1.0')
compileOnly 'org.jetbrains:annotations:24.1.0'
implementation "org.bstats:bstats-bukkit:3.0.2"
}

def targetJavaVersion = 21
Expand Down Expand Up @@ -69,8 +70,12 @@ tasks {
modrinth("FastAsyncWorldEdit", "2.10.0")
hangar("ViaBackwards", "4.10.2")
hangar("ViaVersion", "4.10.2")
github("PaperMC", "Debuggery", "v1.5.1", "debuggery-bukkit-1.5.1.jar")
}
}
shadowJar {
relocate 'org.bstats', 'io.github.minus1over12.ctfbuddy.bstats'
}
}

tasks.jar {
Expand All @@ -80,13 +85,15 @@ tasks.jar {
}

tasks.withType(AbstractRun).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
jvmArgs("-Xmx6G", "-XX:+UseG1GC", "-XX:+ParallelRefProcEnabled", "-XX:MaxGCPauseMillis=200",
"-XX:+UnlockExperimentalVMOptions", "-XX:+DisableExplicitGC", "-XX:+AlwaysPreTouch",
"-XX:G1NewSizePercent=30", "-XX:G1MaxNewSizePercent=40", "-XX:G1HeapRegionSize=8M",
"-XX:G1ReservePercent=20", "-XX:G1HeapWastePercent=5", "-XX:G1MixedGCCountTarget=4",
"-XX:InitiatingHeapOccupancyPercent=15", "-XX:G1MixedGCLiveThresholdPercent=90",
"-XX:G1RSetUpdatingPauseTimePercent=5", "-XX:SurvivorRatio=32",
"-XX:+PerfDisableSharedMem", "-XX:MaxTenuringThreshold=1",
"-Dusing.aikars.flags=https://mcflags.emc.gs", "-Daikars.new.flags=true",
"-XX:+AllowRedefinitionToAddDeleteMethods")
"-Dusing.aikars.flags=https://mcflags.emc.gs", "-Daikars.new.flags=true")
}
Binary file added images/Flag-in-Lava.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Flag-on-Ice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Jeff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Player-with-Flag-on-Ice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

rootProject.name = 'CTFBuddy'
12 changes: 12 additions & 0 deletions src/main/java/io/github/minus1over12/ctfbuddy/CTFBuddy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bstats.bukkit.Metrics;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Animals;
Expand Down Expand Up @@ -70,6 +71,7 @@ public void onEnable() {
// Plugin startup logic
flagTracker = new FlagTracker(this);
getServer().getPluginManager().registerEvents(flagTracker, this);
metrics();
}

@Override
Expand Down Expand Up @@ -197,4 +199,14 @@ private void checkTrackingConfig(@NotNull Audience sender, String entityTypeName
}
return super.onTabComplete(sender, command, alias, args);
}

/**
* Sends plugin metrics to bStats.
*/
private void metrics() {
// All you have to do is adding the following two lines in your onEnable method.
// You can find the plugin ids of your plugins on the page https://bstats.org/what-is-my-plugin-id
int pluginId = 22225; // <-- Replace with the id of your plugin!
Metrics metrics = new Metrics(this, pluginId);
}
}
11 changes: 8 additions & 3 deletions src/main/java/io/github/minus1over12/ctfbuddy/FlagTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@

import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Logger;
Expand Down Expand Up @@ -101,7 +103,7 @@ public class FlagTracker implements Listener {
/**
* A set of entities that are known to be flags.
*/
private final HashSet<Entity> knownFlagEntities = new HashSet<>();
private final Set<Entity> knownFlagEntities = Collections.synchronizedSet(new HashSet<>());

/**
* Create a new FlagTracker.
Expand Down Expand Up @@ -316,8 +318,11 @@ public void onEntityPortal(EntityPortalEvent event) {
*/
@EventHandler
public void onPlayerPortal(PlayerPortalEvent event) {
if (Arrays.stream(event.getPlayer().getInventory().getContents()).filter(Objects::nonNull)
.anyMatch(itemStack -> isFlag(itemStack.getItemMeta()))) {
if (!allowEnd &&
event.getTo().getWorld().getEnvironment().equals(World.Environment.THE_END) &&
Arrays.stream(event.getPlayer().getInventory().getContents())
.filter(Objects::nonNull)
.anyMatch(itemStack -> isFlag(itemStack.getItemMeta()))) {
event.setCancelled(true);
}
}
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/module-info.java

This file was deleted.

0 comments on commit 3215d9b

Please sign in to comment.