Skip to content

Commit

Permalink
MostlyNoRefunds
Browse files Browse the repository at this point in the history
  • Loading branch information
nullptr committed Apr 13, 2019
0 parents commit 3115b98
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.class
*.iml
.classpath
.project
.DS_Store
bin*/
build/
server/
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
language: java
script: gradle build
jdk:
- oraclejdk8
install:
- echo Do Nothing Here!
branches:
except:
- untagged*
before_deploy:
- gem install octokit -v 4.3.0
deploy:
provider: releases
api_key:
secure: s2AAlmw8wtMkepUrCsy3MFOxyY+A1s+f+fvvBU02DT4Ig++xftJkjOdhmI5kyMyjIsAh+OcUXQUUpwyE53HwEw/VwwlJZXhpTExU+HkEb0dWvtNgke/tpN1vAqPhnTYE3OlkEkpVvRQvo5V5LbnwF+UXjl1KapTEEBfRsTBF8xfbwV8B787hqR+vwGndyb+dYZ/H4MZ2oBP+dWF4S/HAwOKLfWyp1kUn6I5BNmP7jJxRpfdSYBSxcI1UpRfATeEfR/jSIZyLQQQrMj3nKBtIz4VnyjG7GIq7NqYy2BAoSXN4M8X5DGj19u/I13h+QY3mrx/oJcJzVhyd9NTut8bcxAa/NZFk4W+CevUPX7cjbK+Qz61S97EMpcFlLwTJYCeVrmY6r+VE+DfrHpVi1xLk6YwP951iV+kEVNCrUAZIxFP2Xlbti4zJmZaQ4mX76GV5bfYwU304acDIBzsCRaIA3a7/7XQkJ8C8Yf7tANBvYcHUUx+CAI0/qyFXhnH7/xUoHNT7qoYUMwtUnSKZulUXcpHTBS8OIy23+2eh5WAAoJK1Cq1euq2rFP4xX5Txei1V+siJeUJZYhil7wI6mfPHeQlwcu0UflTzjsZtLerUCDbu3yi3UDJ/gkQc0HIK+WQ13uXLO9jilUnYTGzUvYde19GiNiADvcOs23bE4BwjEdg=
file: build/libs/*
on:
repo: HelloWorldMinecraft/MostlyNoRefunds
file_glob: true
skip_cleanup: true
notifications:
email: false
after_success:
- wget https://raw.githubusercontent.com/k3rn31p4nic/travis-ci-discord-webhook/master/send.sh
- chmod +x send.sh
- "./send.sh success $WEBHOOK_URL"
after_failure:
- wget https://raw.githubusercontent.com/k3rn31p4nic/travis-ci-discord-webhook/master/send.sh
- chmod +x send.sh
- "./send.sh failure $WEBHOOK_URL"

52 changes: 52 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter

buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.github.jengelman.gradle.plugins:shadow:4.0.1"
}
}

apply plugin: "com.github.johnrengelman.shadow"
apply plugin: "java"
apply plugin: "idea"

configurations {
compile.extendsFrom(bundle, server)
}

version = "1.0.0"
if (!project.hasProperty("Release")) version += '-' + LocalDateTime.now(ZoneId.of("America/Chicago")).format(DateTimeFormatter.ofPattern("yyMMddHHmm"))


repositories {
mavenCentral()
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
maven { url 'http://maven.elmakers.com/repository/' } //Spigot
}

processResources {
filesMatching("**/*.yml") {
expand(project.properties)
}
}

dependencies {
compile "org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT"
}

jar {
baseName = "Generated-${project.name}"
version = rootProject?.version ?: project.version
destinationDir = rootProject?.libsDir ?: libsDir
}

build.dependsOn = ['jar']
37 changes: 37 additions & 0 deletions src/main/java/ws/mcserver/in/DeathListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ws.mcserver.in;

import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class DeathListener implements Listener {
private JavaPlugin plugin;

public DeathListener(JavaPlugin plugin) {
this.plugin = plugin;
}

@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
UUID deathUUID = UUID.randomUUID();

plugin.getLogger().info(event.getEntity().getName() + " has died at " + event.getEntity().getLocation() + " with " + event.getEntity().getExp() + " EXP.");
plugin.getLogger().info("To restore items, run /refund " + event.getEntity().getName() + " " + deathUUID + "");

YamlConfiguration configuration = new YamlConfiguration();
configuration.set("data", event.getDrops());

try {
configuration.save(new File(plugin.getDataFolder(), deathUUID + ".yml"));
} catch (IOException exception) {
plugin.getLogger().info("Error: Death was not saved.");
exception.printStackTrace();
}
}
}
14 changes: 14 additions & 0 deletions src/main/java/ws/mcserver/in/MostlyNoRefunds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ws.mcserver.in;

import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class MostlyNoRefunds extends JavaPlugin {

@Override
public void onEnable() {
getCommand("refund").setExecutor(new RefundExecutor(this));
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
}
}
55 changes: 55 additions & 0 deletions src/main/java/ws/mcserver/in/RefundExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ws.mcserver.in;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.UUID;

public class RefundExecutor implements CommandExecutor {
private JavaPlugin plugin;

public RefundExecutor(JavaPlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender commandSender, Command command, String name, String[] args) {
if (!commandSender.hasPermission("mostlynorefunds.refund") || args.length != 2) return false;

Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
commandSender.sendMessage("Invalid Player: " + args[0]);
return true;
}

File file = new File(plugin.getDataFolder(), UUID.fromString(args[1]) + ".yml");
if (!file.exists()) {
commandSender.sendMessage("Invalid Death: " + args[1]);
}

YamlConfiguration config = new YamlConfiguration();

try {
config.load(file);
} catch (IOException | InvalidConfigurationException exception) {
commandSender.sendMessage("Invalid Configuration Data. Check console for details.");
exception.printStackTrace();
}

Collection<ItemStack> leftover = player.getInventory().addItem(((List<ItemStack>) config.get("data")).toArray(new ItemStack[0])).values();
leftover.forEach(item -> player.getWorld().dropItem(player.getLocation(), item));

return true;
}
}
13 changes: 13 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: MostlyNoRefunds
main: ws.mcserver.in.MostlyNoRefunds
version: ${project.version}
api-version: 1.13
commands:
refund:
description: Refund an inventory to a player
usage: /refund <Player> <Death ID>

permissions:
maybenorefunds.refund:
description: Refund a user's items
default: op

0 comments on commit 3115b98

Please sign in to comment.