Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ gradle.buildFinished {

allprojects {
group = "net.civmc.namelayer"
version = "3.0.0-SNAPSHOT"
version = "3.0.1-SNAPSHOT"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please revert this change before merge? We handle version number when releasing, not per pr

description = "NameLayer"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public void execute(CommandSender sender, String groupName, String adding, Strin
sender.sendMessage(ChatColor.RED + "You can't explicitly add players to this group. Per default any non blacklisted person will"
+ "be included in this permission group");
}
gPerm.addPermission(playerType, pType);
gPerm.addPermission(playerType, pType, true, p);
sender.sendMessage(ChatColor.GREEN + "The PermissionType: " + pType.getName() + " was successfully added to the PlayerType: " +
playerType.name());
}
}
else if (info.equalsIgnoreCase("remove")){
if (gPerm.hasPermission(playerType, pType)){
gPerm.removePermission(playerType, pType);
gPerm.removePermission(playerType, pType, true, p);
sender.sendMessage(ChatColor.GREEN + "The PermissionType: " + pType.getName() + " was successfully removed from" +
" the PlayerType: " + playerType.name());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,68 @@
package vg.civcraft.mc.namelayer.events;

import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import vg.civcraft.mc.namelayer.GroupManager.PlayerType;
import vg.civcraft.mc.namelayer.group.Group;
import vg.civcraft.mc.namelayer.permission.PermissionType;

public class GroupPermissionAdditionEvent extends Event implements Cancellable{
public class GroupPermissionChangeEvent extends Event implements Cancellable {

private static final HandlerList handlers = new HandlerList();

private boolean isCancelled = false;

private Group group;
private PlayerType playerType;
private PermissionType permission;

public GroupPermissionAdditionEvent(Group group, PlayerType playerType, PermissionType permission){
private ChangeType changeType;
private Player player;

public GroupPermissionChangeEvent(Group group, PlayerType playerType, PermissionType permission, ChangeType changeType, Player player){
this.group = group;
this.playerType = playerType;
this.permission = permission;
this.changeType = changeType;
this.player = player;
}

/**
* @return Group for which permission was removed
*/
public Group getGroup(){
return group;
}

/**
* @return Player type from which the permission was taken
*/
public PlayerType getPlayerType() {
return playerType;
}

/**
* @return Permission taken
* @return Permission changed
*/
public PermissionType getPermission() {
return permission;
}


/**
* @return Type of change that occurred
*/
public ChangeType getChange(){
return changeType;
}

/**
* @return The player, if any, responsible for the change
*/
public Player getPlayer(){
return player;
}

@Override
public boolean isCancelled() {
return isCancelled;
Expand All @@ -57,10 +77,14 @@ public void setCancelled(boolean value) {
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
return handlers;
}

}
public enum ChangeType {
ADD,
REMOVE
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ public void clicked(Player p) {
p.sendMessage(ChatColor.GREEN + "Group is now disciplined."
+ " Check back later to see if group is deleted.");
}

p.closeInventory();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a random 1 line fix?

}
}, 11);
confirmInv.setSlot(new Clickable(no) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ public void clicked(Player arg0) {
+ "for player type " + pType.toString()
+ " for " + g.getName() + " via the gui");
if (hasPerm) {
gp.removePermission(pType, perm);
gp.removePermission(pType, perm, true, arg0);
} else {
gp.addPermission(pType, perm);
gp.addPermission(pType, perm, true, arg0);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.bukkit.entity.Player;
import vg.civcraft.mc.namelayer.GroupManager.PlayerType;
import vg.civcraft.mc.namelayer.NameLayerPlugin;
import vg.civcraft.mc.namelayer.database.GroupManagerDao;
import vg.civcraft.mc.namelayer.events.GroupPermissionChangeEvent;
import vg.civcraft.mc.namelayer.group.Group;

public class GroupPermission {
Expand Down Expand Up @@ -73,15 +76,28 @@ public boolean addPermission(PlayerType pType, PermissionType permType) {
}

public boolean addPermission(PlayerType pType, PermissionType permType, boolean savetodb) {
return addPermission(pType, permType, savetodb, null);
}

public boolean addPermission(PlayerType pType, PermissionType permType, boolean savetodb, Player changer){
List<PermissionType> playerPerms = perms.get(pType);
if (playerPerms == null || playerPerms.contains(permType)) {
return false;
}
playerPerms.add(permType);
if (savetodb) {
db.addPermission(group.getName(), pType.name(), Collections.singletonList(permType));
GroupPermissionChangeEvent gpce = new GroupPermissionChangeEvent(
this.group,
pType,
permType,
GroupPermissionChangeEvent.ChangeType.ADD,
changer);
if(gpce.callEvent()) {
playerPerms.add(permType);
if (savetodb) {
db.addPermission(group.getName(), pType.name(), Collections.singletonList(permType));
}
return true;
}
return true;
return false;
}

/**
Expand All @@ -95,15 +111,30 @@ public boolean removePermission(PlayerType pType, PermissionType permType){
}

public boolean removePermission(PlayerType pType, PermissionType permType, boolean savetodb) {
return removePermission(pType, permType, savetodb, null);
}

public boolean removePermission(PlayerType pType, PermissionType permType, boolean savetodb, Player changer) {
List<PermissionType> playerPerms = perms.get(pType);
if (playerPerms == null || !playerPerms.contains(permType)) {
return false;
}
playerPerms.remove(permType);
if (savetodb) {
db.removePermissionAsync(group.getName(), pType, permType);

GroupPermissionChangeEvent gpce = new GroupPermissionChangeEvent(
this.group,
pType,
permType,
GroupPermissionChangeEvent.ChangeType.REMOVE,
changer);

if(gpce.callEvent()) {
playerPerms.remove(permType);
if (savetodb) {
db.removePermissionAsync(group.getName(), pType, permType);
}
return true;
}
return true;
return false;
}

/**
Expand Down