Commit db5d8eaa authored by Spotlight Deveaux's avatar Spotlight Deveaux 🦊

Add permission support

parent a327c466
MIT License
Copyright (c) 2016 Spotlight Jones
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
......@@ -2,7 +2,7 @@ apply plugin: 'java'
apply plugin: 'maven'
group = 'io.github.packserver.CriEverytime'
version = '1.1'
version = '1.2'
description = """"""
......@@ -23,7 +23,7 @@ targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
maven {
name 'Spigot'
......@@ -35,23 +35,14 @@ repositories {
}
}
dependencies {
compile group: 'org.spigotmc', name: 'spigot-api', version:'1.10-R0.1-SNAPSHOT'
compile group: 'org.bukkit', name: 'bukkit', version:'1.10-R0.1-SNAPSHOT'
compile group: 'org.spigotmc', name: 'spigot-api', version:'1.11-R0.1-SNAPSHOT'
compile group: 'org.bukkit', name: 'bukkit', version:'1.11-R0.1-SNAPSHOT'
}
task copyJarToBin(type: Copy) {
from "${buildDir}/libs/CriEverytime-1.1.jar"
if(System.getenv().containsKey("IS_RELEASE"))
into "/Users/spotlight/Projects/RPi/toCopy"
// Deploy to either VPS or local
task deploy(type: Exec) {
if (System.getenv().containsKey("IS_RELEASE"))
commandLine "bash", "/Users/spotlight/bin/deploy-prod", libsDir.getCanonicalPath() + "/CriEverytime-1.2.jar"
else
into "/Users/spotlight/Projects/Minecraft/Testing/plugins"
}
task sendToPi(type: Exec,dependsOn:[copyJarToBin]) {
if(System.getenv().containsKey("IS_RELEASE"))
commandLine "bash", "/Users/spotlight/Projects/RPi/upload.sh", "CriEverytime-1.1.jar", "30632/plugins"
else
commandLine "/usr/bin/true"
}
sendToPi.mustRunAfter build
build.finalizedBy sendToPi
\ No newline at end of file
commandLine "bash", "/Users/spotlight/bin/deploy-dev", libsDir.getCanonicalPath() + "/CriEverytime-1.2.jar"
}
\ No newline at end of file
main: io.github.packserver.CriEverytime.Main
name: CriEverytime
version: 1.1
version: 1.2
commands:
cri:
description: "Making players cri since 1992. Or was it 2015?"
description: "Makes players cry."
rage:
description: "Making players rage since 1992. Or was it 2015?"
laugh:
description: "Making players laugh since 1992. Or was it 2015?"
description: "Makes players rage."
unrage:
description: "Making players stop rageing since 1992. Or was it 2015?"
\ No newline at end of file
description: "Stops players from raging."
laugh:
description: "Makes players laugh."
\ No newline at end of file
......@@ -6,24 +6,18 @@ import java.util.UUID;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author spotlight
* Handles anything regarding crying.
*
* @author Spotlight Jones
*/
class CriCommandExecutor implements CommandExecutor {
private final Main plugin;
public CriCommandExecutor(Main plugin) {
this.plugin = plugin; // Store the plugin in situations where you need
// it.
}
Map<UUID, Boolean> cryingMap = new HashMap<>();
private boolean isExist(UUID p) {
......@@ -47,6 +41,14 @@ class CriCommandExecutor implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("cri")) {
// Since OPs have all permissions, we can't check against them
// as they have the below permisison as well.
if (!sender.isOp()) {
if (sender.hasPermission("crieverytime.nocri")) {
sender.sendMessage(ChatColor.WHITE + "Unknown command. Type \"/help\" for help.");
return false;
}
}
switch (args.length) {
case 0:
if (!(sender instanceof Player)) {
......@@ -58,7 +60,7 @@ class CriCommandExecutor implements CommandExecutor {
break;
case 1:
try {
Player crier = plugin.getServer().getPlayer(args[0]);
Player crier = Main.plugin.getServer().getPlayer(args[0]);
if (crier.isOnline()) toCryOrNotToCry(sender, crier);
} catch (Exception e) {
sender.sendMessage("Player is not online!");
......@@ -79,30 +81,38 @@ class CriCommandExecutor implements CommandExecutor {
/***
* Decides on what to say upon crying.
* For this is the question.
*
* @param sender Player sending command
* @param crier Player crying
*/
public void toCryOrNotToCry(CommandSender sender, Player crier) {
private void toCryOrNotToCry(CommandSender sender, Player crier) {
// Check who's crying
Boolean isSelf;
if (sender.equals(crier)) isSelf = true;
else isSelf = false;
Boolean isSelf = sender.equals(crier);
// Get correct crying message
// If the player is not currently crying...
if (!isExist(crier.getUniqueId())) {
if (isSelf) {
Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "* " + crier.getName() + " is now crying.");
// say they made themselves cry.
Main.plugin.getServer().broadcastMessage(ChatColor.DARK_PURPLE + "* " + crier.getName() + " is now crying.");
} else {
Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "* " + sender.getName() + " forced " + crier.getName() + " to cry!");
// say whoever made them cry.
Main.plugin.getServer().broadcastMessage(ChatColor.DARK_PURPLE + "* " + sender.getName() + " forced " + crier.getName() + " to cry!");
}
// Set their crying state to false.
cryingMap.put(crier.getUniqueId(), true);
// If they're currently crying...
} else {
if (isSelf) {
Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "* " + crier.getName() + " is no longer crying.");
// say they made themselves stop crying.
Main.plugin.getServer().broadcastMessage(ChatColor.DARK_PURPLE + "* " + crier.getName() + " is no longer crying.");
} else {
Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "* " + sender.getName() + " forced " + crier.getName() + " to stop crying!");
// say whoever made them stop crying.
Main.plugin.getServer().broadcastMessage(ChatColor.DARK_PURPLE + "* " + sender.getName() + " forced " + crier.getName() + " to stop crying!");
}
// Set their crying state to true.
cryingMap.put(crier.getUniqueId(), false);
}
}
......
......@@ -11,14 +11,28 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* Handles anything related to laughing.
* This command has no state due to the fact
* that people cannot physically laugh as much
* as this command might be used for,
* and it would be pointless to implement a timer.
*
* @author spotlight
* @author Spotlight Jones
*/
class LaughCommandExecutor implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("laugh")) {
// Since OPs have all permissions, we can't check against them
// as they have the below permisison as well.
if (!sender.isOp()) {
if (sender.hasPermission("crieverytime.nolaugh")) {
sender.sendMessage(ChatColor.WHITE + "Unknown command. Type \"/help\" for help.");
return false;
}
}
if (!(sender instanceof Player)) {
sender.sendMessage("This command can only be run by a player.");
} else {
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package io.github.packserver.CriEverytime;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
/**
* @author spotlight
* Listens for the player join or quit event to reset raging.
* Both are listened to to make sure that the state of rage has reset.
*
* @author Spotlight Jones
*/
class ListenerClass implements Listener {
private final Main plugin;
public ListenerClass(Main plugin) {
this.plugin = plugin; // Store the plugin in situations where you need
// it.
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
// Get player object from quit event
Player p = event.getPlayer();
new CriCommandExecutor(plugin).stopCrying(p);
new CriCommandExecutor().stopCrying(p);
new RageCommandExecutor().stopRaging(p);
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
// Get player object from quit event
Player p = event.getPlayer();
new CriCommandExecutor().stopCrying(p);
new RageCommandExecutor().stopRaging(p);
}
}
......@@ -3,16 +3,24 @@ package io.github.packserver.CriEverytime;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
/**
* Create global reference to Main
*/
static Main plugin;
@Override
public void onEnable() {
// Set plugin
plugin = this;
// Bind commands
this.getCommand("cri").setExecutor(new CriCommandExecutor(this));
this.getCommand("cri").setExecutor(new CriCommandExecutor());
this.getCommand("rage").setExecutor(new RageCommandExecutor());
this.getCommand("laugh").setExecutor(new LaughCommandExecutor());
this.getCommand("unrage").setExecutor(new RageCommandExecutor());
// Create listener class to reset emotions upon logging off
getServer().getPluginManager().registerEvents(new ListenerClass(this), this);
getServer().getPluginManager().registerEvents(new ListenerClass(), this);
}
}
......@@ -14,8 +14,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* Handles anything related to raging.
*
* @author spotlight
* @author Spotlight Jones
*/
class RageCommandExecutor implements CommandExecutor {
......@@ -32,34 +33,62 @@ class RageCommandExecutor implements CommandExecutor {
}
}
public void stopRaging(Player p) {
void stopRaging(Player p) {
isUnraged.put(p.getUniqueId(), true);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
/* The reason that these are two different things is
* due to the fact that some people like spamming rage messages.
* If the command was spammed repeatedly, half of the messages
* would be about the player unraging and that's no fun!
*
* I, as the plugin developer find it acceptable to spam these.
* If for some reason you don't like this and want to implement
* your own permission, go for it.
*/
if (cmd.getName().equalsIgnoreCase("rage")) {
// Since OPs have all permissions, we can't check against them
// as they have the below permisison as well.
if (!sender.isOp()) {
if (sender.hasPermission("crieverytime.norage")) {
sender.sendMessage(ChatColor.WHITE + "Unknown command. Type \"/help\" for help.");
return false;
}
}
if (!(sender instanceof Player)) {
sender.sendMessage("This command can only be run by a player.");
sender.sendMessage("You can't rage, CONSOLE!");
} else {
Player p = (Player) sender;
String[] possibleStrings = {"U NUB", "OMG I H8 THIS STUPID GAME", "IM TELING ON YOU", "IM REPORTING YOU FOR HAXING U NUB", "1V1 ME YOU NOOB WITHOUT HAX", "I KNOW THE SERVER OWNER AND HES GOING 2 BAN U ALL!!!!!1!!!!!one!!!two1!11!!", "OMG I HATE ALL OF YOU HAXERS!", "STOP USING HAX GUYS!"};
String[] possibleStrings = {"U NUB", "OMG I H8 THIS STUPID GAME", "IM TELING ON YOU", "IM REPORTING YOU FOR HAXING U NUB", "1V1 ME YOU NOOB WITHOUT HAX", "I KNOW THE SERVER OWNER AND HES GOING 2 BAN U ALL!!!!!1!!!!!one!!!two1!11!!", "OMG I HATE ALL OF YOU HAXERS!", "STOP USING HAX GUYS! ITS NOT KIND!!!!!!!!!!!!!!1!!!"};
//Grab a random number
Random randomNumber = new Random();
// Randomly selects an index from the array
int number = randomNumber.nextInt(possibleStrings.length);
Bukkit.broadcastMessage(ChatColor.DARK_RED + "* " + p.getName() + ": " + possibleStrings[number]);
// If the player isn't already marked as raging, mark them.
if (isExist(p.getUniqueId())) {
isUnraged.put(p.getUniqueId(), false);
}
}
} else if (cmd.getName().equalsIgnoreCase("unrage")) {
// Since OPs have all permissions, we can't check against them
// as they have the below permisison as well.
if (!sender.isOp()) {
if (sender.hasPermission("crieverytime.norage")) {
sender.sendMessage(ChatColor.WHITE + "Unknown command. Type \"/help\" for help.");
return false;
}
}
if (!(sender instanceof Player)) {
sender.sendMessage("This command can only be run by a player.");
sender.sendMessage("You can't unrage, CONSOLE!");
} else {
Player p = (Player) sender;
// Check if the player is currently raging.
if (!isExist(p.getUniqueId())) {
Bukkit.broadcastMessage(ChatColor.DARK_RED + "* " + p.getName() + " has stopped being a noob!");
Bukkit.broadcastMessage(ChatColor.DARK_RED + "* " + p.getName() + " has stopped raging!");
isUnraged.put(p.getUniqueId(), true);
} else {
p.sendMessage(ChatColor.RED + "You can't unrage, you're already unragifieded!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment