Skip to content

Commit

Permalink
feat(proj): Finished functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Dec 19, 2023
1 parent fdff934 commit 7e145ee
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 79 deletions.
41 changes: 12 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,28 @@
```

README LANGUAGES [ [**English**](README.md) | [中文](README_CN.md) ]
README LANGUAGES [ [**English**](README.md) ]

![CodeSize](https://img.shields.io/github/languages/code-size/ArtformGames/TemplateSinglePlugin)
[![Download](https://img.shields.io/github/downloads/ArtformGames/TemplateSinglePlugin/total)](https://github.com/ArtformGames/TemplateSinglePlugin/releases)
[![Java CI with Maven](https://github.com/ArtformGames/TemplateSinglePlugin/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/ArtformGames//actions/workflows/maven.yml)
![CodeSize](https://img.shields.io/github/languages/code-size/ArtformGames/TogglePVP)
[![Download](https://img.shields.io/github/downloads/ArtformGames/TogglePVP/total)](https://github.com/ArtformGames/TogglePVP/releases)
[![Java CI with Maven](https://github.com/ArtformGames/TogglePVP/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/ArtformGames//actions/workflows/maven.yml)
![Support](https://img.shields.io/badge/Minecraft-Java%201.16--Latest-green)

# **TemplateSinglePlugin**
# **TogglePVP**

> Slogan
Descriptions

## Features & Advantages

## Screenshots
SLet players decide whether to enable PVP!

## Dependencies

- **[Necessary]** Develop based on [ArtCore](https://github.com/ArtformGames/ArtCore) .
- **[Recommend]** Placeholders based on [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) .

For development dependencies, please
see [Dependencies](https://github.com/ArtformGames/TemplateSinglePlugin/network/dependencies) .
see [Dependencies](https://github.com/ArtformGames/TogglePVP/network/dependencies) .

## Commands

The main command is `/TemplateSinglePlugin` or `/tsp`.

```text
# subcommand <force-arg> <optional-arg>
@ Player command
- Description
```
Use `/pvp` or `/TogglePVP` to toggle pvp status.

## Configurations

Expand All @@ -51,14 +38,10 @@ Will be generated on the first boot up.
## Permissions

```text
# TemplateSinglePlugin.admin
- The permissions for all admin commands and functions.
# TogglePVP.use
- The permissions to use toggle command.
```

## Statistics

[![bStats](https://bstats.org/signatures/bukkit/TemplatePlugin.svg)](https://bstats.org/plugin/bukkit/TemplatePlugin/18946)

## Open Source Licence

The source code of this project adopts the [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0).
Expand All @@ -68,5 +51,5 @@ The source code of this project adopts the [GNU General Public License v3.0](htt
This project is mainly developed by the [Artfrom Games](https://github.com/ArtformGames/) .

Many thanks to Jetbrains for kindly providing a license for us to work on this and other open-source projects.
[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/ArtformGames/TemplateSinglePlugin)
[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/ArtformGames/TogglePVP)

25 changes: 11 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>

<project.package>${project.groupId}.plugin.template</project.package>
<project.package>${project.groupId}.plugin.${project.groupId}</project.package>
</properties>
<groupId>com.artformgames</groupId>
<artifactId>TemplateSinglePlugin</artifactId>
<artifactId>togglepvp</artifactId>
<version>1.0.0</version>

<name>TemplateSinglePlugin</name>
<name>TogglePVP</name>
<description>
An efficient and fair verification plugin for whitelisted servers,
which supports players to submit whitelist requests by themselves
and be reviewed by all players who have passed.
Let players decide whether to enable PVP!
</description>
<url>https://github.com/ArtformGames/TemplateSinglePlugin</url>
<url>https://github.com/ArtformGames/TogglePVP</url>

<developers>
<developer>
Expand Down Expand Up @@ -51,20 +49,20 @@

<ciManagement>
<system>GitHub Actions</system>
<url>https://github.com/ArtformGames/TemplateSinglePlugin/actions/workflows/maven.yml</url>
<url>https://github.com/ArtformGames/TogglePVP/actions/workflows/maven.yml</url>
</ciManagement>

<distributionManagement>
<downloadUrl>https://github.com/ArtformGames/TemplateSinglePlugin/releases</downloadUrl>
<downloadUrl>https://github.com/ArtformGames/TogglePVP/releases</downloadUrl>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/ArtformGames/TemplateSinglePlugin</url>
<url>https://maven.pkg.github.com/ArtformGames/TogglePVP</url>
</repository>
<snapshotRepository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/ArtformGames/TemplateSinglePlugin</url>
<url>https://maven.pkg.github.com/ArtformGames/TogglePVP</url>
</snapshotRepository>
</distributionManagement>

Expand Down Expand Up @@ -101,7 +99,7 @@
<dependency>
<groupId>com.artformgames</groupId>
<artifactId>artcore-api</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>

Expand All @@ -112,7 +110,6 @@
<scope>provided</scope>
</dependency>


<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
Expand Down Expand Up @@ -211,7 +208,7 @@
</execution>
</executions>
<configuration>
<finalName>${project.name}-${project.parent.version}</finalName>
<finalName>${project.name}-${project.version}</finalName>
<outputDirectory>${project.basedir}/.asset/</outputDirectory>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.artformgames.plugin.template;
package com.artformgames.plugin.togglepvp;

import cc.carm.lib.easyplugin.EasyPlugin;
import cc.carm.lib.mineconfiguration.bukkit.MineConfiguration;
import com.artformgames.core.utils.GHUpdateChecker;
import com.artformgames.plugin.template.conf.PluginConfig;
import com.artformgames.plugin.template.conf.PluginMessages;
import org.bstats.bukkit.Metrics;
import com.artformgames.plugin.togglepvp.command.TogglePVPCommand;
import com.artformgames.plugin.togglepvp.conf.PluginConfig;
import com.artformgames.plugin.togglepvp.conf.PluginMessages;
import com.artformgames.plugin.togglepvp.handler.PVPHandler;
import dev.rollczi.litecommands.bukkit.LiteCommandsBukkit;

public class Main extends EasyPlugin {

Expand All @@ -16,29 +18,23 @@ public Main() {
}

protected MineConfiguration configuration;
protected LiteCommandsBukkit commands;

@Override
protected void load() {
protected boolean initialize() {

log("Loading plugin configurations...");
configuration = new MineConfiguration(this);
configuration.initializeConfig(PluginConfig.class);
configuration.initializeMessage(PluginMessages.class);
}

@Override
protected boolean initialize() {

log("Register listeners...");
registerListener(new PVPHandler());

log("Register commands...");
registerCommand(getName(), new TogglePVPCommand());


if (PluginConfig.METRICS.getNotNull()) {
log("Initializing bStats...");
new Metrics(this, 0);
}

if (PluginConfig.CHECK_UPDATE.getNotNull()) {
log("Start to check the plugin versions...");
getScheduler().runAsync(GHUpdateChecker.runner(this));
Expand All @@ -49,13 +45,6 @@ protected boolean initialize() {
return true;
}

@Override
protected void shutdown() {

log("Shutting down...");

}

@Override
public boolean isDebugging() {
return PluginConfig.DEBUG.getNotNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.artformgames.plugin.togglepvp.command;

import com.artformgames.plugin.togglepvp.handler.PVPHandler;
import com.artformgames.plugin.togglepvp.conf.PluginMessages;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class TogglePVPCommand implements CommandExecutor {

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("You must be a player to use this command.");
return true;
}

boolean current = PVPHandler.isPVPEnabled(player);
PVPHandler.setPVPStatus(player, !current);
if (!current) {
PluginMessages.ENABLED.send(player);
} else {
PluginMessages.DISABLED.send(player);
}

return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package com.artformgames.plugin.template.conf;
package com.artformgames.plugin.togglepvp.conf;

import cc.carm.lib.configuration.core.ConfigurationRoot;
import cc.carm.lib.configuration.core.annotation.HeaderComment;
import cc.carm.lib.configuration.core.value.ConfigValue;
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;

public class PluginConfig extends ConfigurationRoot {

public static final ConfiguredValue<Boolean> DEBUG = ConfiguredValue.of(Boolean.class, false);

@HeaderComment({
"Statistics Settings",
"This option is used to help developers count plug-in versions and usage, and it will never affect performance and user experience.",
"Of course, you can also choose to turn it off here for this plugin,",
"or turn it off for all plugins in the configuration file under \"plugins/bStats\"."
})
public static final ConfiguredValue<Boolean> METRICS = ConfiguredValue.of(Boolean.class, true);

@HeaderComment({
"Check update settings",
"This option is used by the plug-in to determine whether to check for updates.",
Expand All @@ -24,4 +17,7 @@ public class PluginConfig extends ConfigurationRoot {
})
public static final ConfiguredValue<Boolean> CHECK_UPDATE = ConfiguredValue.of(Boolean.class, true);

@HeaderComment("Default status of player's pvp settings")
public static final ConfigValue<Boolean> DEFAULTS = ConfiguredValue.of(Boolean.class, false);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.artformgames.plugin.togglepvp.conf;

import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
import com.artformgames.core.conf.MessagesRoot;
import net.md_5.bungee.api.chat.BaseComponent;

public class PluginMessages extends MessagesRoot {

public static final ConfiguredMessageList<BaseComponent[]> SELF_DISABLED = list()
.defaults("&7 You have disabled PVP so you can't attack other players.")
.build();

public static final ConfiguredMessageList<BaseComponent[]> TARGET_DISABLED = list()
.defaults("&fPlayer &c%(player) &fPVP is disabled, so it can't be attacked.")
.params("player")
.build();

public static final ConfiguredMessageList<BaseComponent[]> ENABLED = list()
.defaults("&fYou have &a&lenabled &fPVP, now you can fight with other players.")
.build();

public static final ConfiguredMessageList<BaseComponent[]> DISABLED = list()
.defaults("&fYou have &c&ldisabled &fPVP, now you can't attack other players, and you can't be attacked by other players.")
.build();

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.artformgames.plugin.togglepvp.handler;

import com.artformgames.core.ArtCore;
import com.artformgames.core.function.settings.SettingsType;
import com.artformgames.core.function.settings.UserSettingsData;
import com.artformgames.core.function.settings.values.BooleanSettingsType;
import com.artformgames.plugin.togglepvp.conf.PluginConfig;
import com.artformgames.plugin.togglepvp.conf.PluginMessages;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

public class PVPHandler implements Listener {

public static final SettingsType<Boolean> PVP = new BooleanSettingsType(10, PluginConfig.DEFAULTS.getNotNull());


@EventHandler
public void onAttack(EntityDamageByEntityEvent e) {
Player attacker = null;

if (e.getDamager() instanceof Player player) {
attacker = player;
} else if (e.getDamager() instanceof Projectile proj && proj.getShooter() instanceof Player shooter) {
attacker = shooter;
}

if (attacker == null) return;
if (!(e.getEntity() instanceof Player player)) return;

if (!isPVPEnabled(attacker)) {
// 当玩家想要攻击别人时,先判断自己是否允许攻击
PluginMessages.SELF_DISABLED.send(attacker);
e.setCancelled(true);
} else if (!isPVPEnabled(player)) {
//再判断被攻击者是否允许被攻击
PluginMessages.TARGET_DISABLED.send(attacker, player.getName());
e.setCancelled(true);
}
}

public static boolean isPVPEnabled(Player player) {
return ArtCore.getUserManager().get(player).getHandler(UserSettingsData.class).get(PVP);
}

public static void setPVPStatus(Player player, boolean status) {
ArtCore.getUserManager().get(player).getHandler(UserSettingsData.class).set(PVP, status);
}


}
12 changes: 12 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ depend:

softdepend:
- PlaceholderAPI

permissions:
"togglepvp.use":
description: "Allows the player to toggle PVP status"
default: true

commands:
"TogglePVP":
description: "Toggle PVP status"
usage: "/togglepvp"
permission: "togglepvp.use"
aliases: [ "pvp" ]

0 comments on commit 7e145ee

Please sign in to comment.