Skip to content

Commit

Permalink
Initial commit of ShearMaster plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Mille12313 committed Sep 8, 2024
0 parents commit f6d676b
Show file tree
Hide file tree
Showing 9 changed files with 688 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# User-specific stuff
.idea/

*.iml
*.ipr
*.iws

# IntelliJ
out/

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

target/

pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next

release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml

# Common working directory
run/
72 changes: 72 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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>bloody.devmules</groupId>
<artifactId>ShearMaster</artifactId>
<version>0.01-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ShearMaster</name>

<properties>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</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.5.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</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.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
35 changes: 35 additions & 0 deletions src/main/java/bloody/devmules/shearMaster/ShearMaster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package bloody.devmules.shearMaster;

import bloody.devmules.shearMaster.config.ConfigManager;
import bloody.devmules.shearMaster.listeners.ShearListener;
import org.bukkit.plugin.java.JavaPlugin;

public class ShearMaster extends JavaPlugin {

private ConfigManager configManager;

@Override
public void onEnable() {
// Config laden en aanmaken als deze niet bestaat
saveDefaultConfig();
configManager = new ConfigManager(this);

// Event listener registreren
getServer().getPluginManager().registerEvents(new ShearListener(this), this);

// Command executor en tab-completer registreren
getCommand("shearmaster").setExecutor(new ShearMasterCommand(this));
getCommand("shearmaster").setTabCompleter(new ShearMasterTabCompleter(this));

getLogger().info("ShearMaster plugin enabled!");
}

@Override
public void onDisable() {
getLogger().info("ShearMaster plugin disabled.");
}

public ConfigManager getConfigManager() {
return configManager;
}
}
111 changes: 111 additions & 0 deletions src/main/java/bloody/devmules/shearMaster/ShearMasterCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package bloody.devmules.shearMaster;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class ShearMasterCommand implements CommandExecutor {

private ShearMaster plugin;

public ShearMasterCommand(ShearMaster plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("This command can only be used by players.");
return true;
}

Player player = (Player) sender;

if (command.getName().equalsIgnoreCase("shearmaster")) {
if (args.length == 0) {
player.sendMessage("Use /shearmaster reload, /shearmaster toggle <animal> <shear|slice>, or /shearmaster status.");
return true;
}

if (args[0].equalsIgnoreCase("reload")) {
if (!player.hasPermission("shearmaster.admin")) {
player.sendMessage("You do not have permission to use this command.");
return true;
}
// Config herladen en opnieuw initialiseren
plugin.reloadConfig();
plugin.getConfigManager().reloadConfig();
player.sendMessage("ShearMaster configuration reloaded!");
return true;
}

if (args[0].equalsIgnoreCase("toggle")) {
if (!player.hasPermission("shearmaster.toggle")) {
player.sendMessage("You do not have permission to use this command.");
return true;
}
if (args.length < 3) {
player.sendMessage("Usage: /shearmaster toggle <animal> <shear|slice>");
return true;
}
String animal = args[1].toLowerCase();
String type = args[2].toLowerCase();

// Check if the animal is in the config
if (!plugin.getConfigManager().isAnimalConfigured(animal)) {
player.sendMessage(ChatColor.RED + "Error: " + animal + " is not configured in the plugin.");
return true;
}

// Toggle shearable or sliceable
if (type.equals("shear")) {
if (!plugin.getConfigManager().canBeSheared(animal)) {
player.sendMessage(ChatColor.RED + animal + " cannot be sheared.");
} else if (!plugin.getConfigManager().hasShearableOption(animal)) {
player.sendMessage(ChatColor.RED + animal + " cannot be toggled as shearable.");
} else {
plugin.getConfigManager().toggleShearable(animal);
player.sendMessage("Toggled shearable status for " + animal + ".");
}
} else if (type.equals("slice")) {
if (!plugin.getConfigManager().hasSliceableOption(animal)) {
player.sendMessage(ChatColor.RED + animal + " cannot be toggled as sliceable.");
} else {
plugin.getConfigManager().toggleSliceable(animal);
player.sendMessage("Toggled sliceable status for " + animal + ".");
}
} else {
player.sendMessage(ChatColor.RED + "Error: Invalid type. Use shear or slice.");
}
return true;
}

if (args[0].equalsIgnoreCase("status")) {
if (!player.hasPermission("shearmaster.admin")) {
player.sendMessage("You do not have permission to use this command.");
return true;
}

// Stijl en kleur toevoegen aan de status-output
player.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "ShearMaster Status:");

for (String animal : plugin.getConfigManager().getAnimals()) {
boolean shearable = plugin.getConfigManager().isShearable(animal);
boolean sliceable = plugin.getConfigManager().isSliceable(animal);
ChatColor shearableColor = shearable ? ChatColor.GREEN : ChatColor.RED;
ChatColor sliceableColor = sliceable ? ChatColor.GREEN : ChatColor.RED;

// Bericht voor elk dier
player.sendMessage(ChatColor.GOLD + animal + ": "
+ ChatColor.WHITE + " Shearable: " + shearableColor + shearable
+ ChatColor.WHITE + ", Sliceable: " + sliceableColor + sliceable);
}
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package bloody.devmules.shearMaster;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;

import java.util.ArrayList;
import java.util.List;

public class ShearMasterTabCompleter implements TabCompleter {

private ShearMaster plugin;

public ShearMasterTabCompleter(ShearMaster plugin) {
this.plugin = plugin;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> completions = new ArrayList<>();

if (command.getName().equalsIgnoreCase("shearmaster")) {
if (args.length == 1) {
completions.add("reload");
completions.add("toggle");
completions.add("status");
} else if (args.length == 2 && args[0].equalsIgnoreCase("toggle")) {
completions.addAll(plugin.getConfigManager().getAnimals()); // Suggestie voor dieren
} else if (args.length == 3 && args[0].equalsIgnoreCase("toggle")) {
completions.add("shear");
completions.add("slice");
}
}

return completions;
}
}
Loading

0 comments on commit f6d676b

Please sign in to comment.