Start
Plugin + Workspace uploded
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="Pvptoggle" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="sonatype" />
|
||||
<option name="name" value="sonatype" />
|
||||
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="spigotmc-repo" />
|
||||
<option name="name" value="spigotmc-repo" />
|
||||
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+19
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Pvptoggle.iml" filepath="$PROJECT_DIR$/Pvptoggle.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>benkralex</groupId>
|
||||
<artifactId>Pvptoggle</artifactId>
|
||||
<version>1.4-FINAL</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Pvptoggle</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.jorel</groupId>
|
||||
<artifactId>commandapi-bukkit-core</artifactId>
|
||||
<version>9.0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,20 @@
|
||||
package benkralex.pvptoggle;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.Instant;
|
||||
|
||||
public class Config {
|
||||
public static void createConfig() {
|
||||
FileConfiguration config = Pvptoggle.pvptoggle.getConfig();
|
||||
config.options().copyDefaults();
|
||||
config.addDefault("pvp-time-hit-back", 60);
|
||||
Pvptoggle.pvptoggle.saveConfig();
|
||||
}
|
||||
|
||||
public static int getpvptime() {
|
||||
FileConfiguration config = Pvptoggle.pvptoggle.getConfig();
|
||||
return config.getInt("pvp-time-hit-back");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package benkralex.pvptoggle;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class PvpCommand {
|
||||
public static void createPvpCommand() {
|
||||
//Create PVP-Command with Command-API
|
||||
new CommandAPICommand("pvp").
|
||||
withSubcommand(new CommandAPICommand("toggle").
|
||||
executesPlayer((sender, args)->{
|
||||
pvpToggle(sender, args);
|
||||
}).
|
||||
withPermission("pvp.toggle").
|
||||
withUsage("/pvp toggle").
|
||||
withHelp("PvP damage für sich an/auschalten.", "Du kannst damit an/ausschalten, ob du geschlagen werden kannst.")).
|
||||
register();
|
||||
}
|
||||
|
||||
public static void pvpToggle(Player sender, CommandArguments args) {
|
||||
PersistentDataContainer pdc = sender.getPersistentDataContainer();
|
||||
if (pdc.has(new NamespacedKey(Pvptoggle.pvptoggle, "pvptoggle"), PersistentDataType.BOOLEAN)) {
|
||||
pdc.set(new NamespacedKey(Pvptoggle.pvptoggle, "pvptoggle"), PersistentDataType.BOOLEAN,
|
||||
!pdc.get(new NamespacedKey(Pvptoggle.pvptoggle, "pvptoggle"), PersistentDataType.BOOLEAN));
|
||||
sender.sendMessage("Dein PvP-Schutz ist jetzt " + (pdc.get(new NamespacedKey(Pvptoggle.pvptoggle, "pvptoggle"), PersistentDataType.BOOLEAN)?"an":"aus"));
|
||||
} else {
|
||||
pdc.set(new NamespacedKey(Pvptoggle.pvptoggle, "pvptoggle"), PersistentDataType.BOOLEAN, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package benkralex.pvptoggle;
|
||||
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.persistence.PersistentDataAdapterContext;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import sun.reflect.generics.tree.ArrayTypeSignature;
|
||||
|
||||
import java.sql.Array;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class PvpEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public static void pvpListener(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
Entity victim = event.getEntity();
|
||||
|
||||
if (damager instanceof Player && victim instanceof Player) {
|
||||
List<PersistentDataContainer> pvpvictimsList;
|
||||
List<PersistentDataContainer> pvpvictimsListdamager;
|
||||
PersistentDataContainer pdc = victim.getPersistentDataContainer();
|
||||
PersistentDataContainer pdcdamager = damager.getPersistentDataContainer();
|
||||
PersistentDataContainer[] pvpvictims = pdc.get(new NamespacedKey(Pvptoggle.pvptoggle, "pvpvictims"), PersistentDataType.TAG_CONTAINER_ARRAY);
|
||||
PersistentDataContainer[] pvpvictimsdamager = pdcdamager.get(new NamespacedKey(Pvptoggle.pvptoggle, "pvpvictims"), PersistentDataType.TAG_CONTAINER_ARRAY);
|
||||
boolean canpvp = false;
|
||||
String victimuuid = victim.getUniqueId().toString();
|
||||
|
||||
if (pvpvictims != null) {
|
||||
pvpvictimsList = new ArrayList<PersistentDataContainer>(Arrays.asList(pvpvictims));
|
||||
} else {
|
||||
pvpvictimsList = new ArrayList<PersistentDataContainer>();
|
||||
}
|
||||
|
||||
if (pvpvictimsdamager != null) {
|
||||
pvpvictimsListdamager = new ArrayList<PersistentDataContainer>(Arrays.asList(pvpvictimsdamager));
|
||||
} else {
|
||||
pvpvictimsListdamager = new ArrayList<PersistentDataContainer>();
|
||||
}
|
||||
|
||||
for (int i = 0; i<pvpvictimsListdamager.size(); i++) {
|
||||
PersistentDataContainer pdcfor = pvpvictimsListdamager.get(i);
|
||||
if (pdcfor.get(new NamespacedKey(Pvptoggle.pvptoggle, "time"), PersistentDataType.LONG) >= Instant.now().getEpochSecond() - Config.getpvptime()) {
|
||||
if (pdcfor.get(new NamespacedKey(Pvptoggle.pvptoggle, "uuid"), PersistentDataType.STRING).equals(victimuuid)) {
|
||||
canpvp = true;
|
||||
}
|
||||
} else {
|
||||
pvpvictimsListdamager.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
if (pdc.has(new NamespacedKey(Pvptoggle.pvptoggle, "pvptoggle"), PersistentDataType.BOOLEAN) &&
|
||||
pdc.get(new NamespacedKey(Pvptoggle.pvptoggle, "pvptoggle"), PersistentDataType.BOOLEAN) &&
|
||||
!canpvp) {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
} else {
|
||||
PersistentDataContainer pdcupdated = pdc.getAdapterContext().newPersistentDataContainer();
|
||||
String uuid = damager.getUniqueId().toString();
|
||||
pdcupdated.set(new NamespacedKey(Pvptoggle.pvptoggle, "uuid"), PersistentDataType.STRING, uuid);
|
||||
pdcupdated.set(new NamespacedKey(Pvptoggle.pvptoggle, "time"), PersistentDataType.LONG, Instant.now().getEpochSecond());
|
||||
pvpvictimsList.add(pdcupdated);
|
||||
pvpvictims = pvpvictimsList.toArray(new PersistentDataContainer[pvpvictimsList.size()]);
|
||||
pdc.set(new NamespacedKey(Pvptoggle.pvptoggle, "pvpvictims"), PersistentDataType.TAG_CONTAINER_ARRAY, pvpvictims);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//pdc.getAdapterContext().newPersistentDataContainer()
|
||||
@@ -0,0 +1,26 @@
|
||||
package benkralex.pvptoggle;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class Pvptoggle extends JavaPlugin {
|
||||
|
||||
public static Pvptoggle pvptoggle;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin enable logic
|
||||
pvptoggle = this;
|
||||
Bukkit.getPluginManager().registerEvents(new PvpEvent(), this);
|
||||
PvpCommand.createPvpCommand();
|
||||
Config.createConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
name: Pvptoggle
|
||||
version: '${project.version}'
|
||||
main: benkralex.pvptoggle.Pvptoggle
|
||||
api-version: 1.20
|
||||
permissions:
|
||||
pvp.toggle:
|
||||
default: true
|
||||
Reference in New Issue
Block a user